Skip to content

Commit

Permalink
test: connection from scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Nov 10, 2024
1 parent fc83b0e commit 32702ba
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fixtures/playbooks/connection-from-scraper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- exec:
script: "kubectl get deployments"
connections:
fromConfigItem: "$(.config.id)"
fromConfigItem: "{{.config.id}}"
name: list
category: Echoer
description: Lists all deployments
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.25.0 // indirect
github.com/flanksource/commons v1.31.2
github.com/flanksource/duty v1.0.746
github.com/flanksource/duty v1.0.747
github.com/flanksource/gomplate/v3 v3.24.39
github.com/flanksource/kopper v1.0.10
github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2
Expand Down Expand Up @@ -361,7 +361,7 @@ require (
sigs.k8s.io/yaml v1.4.0
)

// replace github.com/flanksource/duty => ../duty
replace github.com/flanksource/duty => ../duty

// replace github.com/flanksource/gomplate/v3 => ../gomplate

Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,6 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z
github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70=
github.com/flanksource/commons v1.31.2 h1:VBhmhmvk6PjhJYuaK8LL+7700E3zPCY03VV/K1BxH64=
github.com/flanksource/commons v1.31.2/go.mod h1:X2txnbNGY6fKQuKLmc7x92FMYjB2MuaqNJOR6vEWDMs=
github.com/flanksource/duty v1.0.746 h1:5kenx08MeC99IDP/XdPiCpX2a8os1jn3Z41oDxHS1zw=
github.com/flanksource/duty v1.0.746/go.mod h1:sZY2NytdenrkqXoMD6Gn2C8xH6dm5HsqOeE0p74Z2VE=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.39 h1:O763lnNIcTELSMYeIO0dNDfcb3LoZvzU1fr62I4Yxqg=
github.com/flanksource/gomplate/v3 v3.24.39/go.mod h1:0wY/+UPvd7CxmiTBNmzZdWIEOUZAsRkpGY1j5R711O8=
Expand Down
13 changes: 13 additions & 0 deletions playbook/playbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ var _ = Describe("Playbook", func() {
Expect(actions[0].JSON()["item"]).To(Equal(*dummy.KubernetesNodeA.Name))
Expect(actions[1].JSON()["item"]).To(Equal(fmt.Sprintf("name=%s", *dummy.KubernetesNodeA.Name)))
})

It("exec | connection | kubernetes", func() {
run := createAndRun(DefaultContext.WithUser(&dummy.JohnDoe), "exec-connection-kubernetes", RunParams{
ConfigID: lo.ToPtr(dummy.KubernetesCluster.ID),
})

Expect(run.Status).To(Equal(models.PlaybookRunStatusCompleted), run.String(DefaultContext.DB()))
actions, err := run.GetActions(DefaultContext.DB())
Expect(err).To(BeNil())
Expect(len(actions)).To(Equal(1))
Expect(actions[0].Result["stdout"]).To(HavePrefix(".creds/cred-"))
})
})

var _ = Describe("spec runner", func() {
Expand Down Expand Up @@ -634,6 +646,7 @@ func waitFor(run *models.PlaybookRun, statuses ...models.PlaybookRunStatus) *mod
if savedRun != nil {
return savedRun.Status
}

return models.PlaybookRunStatus("Unknown")

}).WithTimeout(15 * time.Second).WithPolling(time.Second).Should(BeElementOf(s))
Expand Down
18 changes: 18 additions & 0 deletions playbook/testdata/exec-connection-kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: kubernetes-connection-from-scraper
namespace: mc
spec:
category: Echoer
description: list kubeconfig env var
configs:
- types:
- Kubernetes::Deployment
actions:
- name: echo
exec:
connections:
fromConfigItem: "{{.config.id}}"
script: "echo $KUBECONFIG"

0 comments on commit 32702ba

Please sign in to comment.