Skip to content

Commit f5c4bff

Browse files
committed
added some simple test, need to break ArgocdPlugin to smaller units that try to actually do stuff. ArgocdPlugin should only test if it can get values and pass it to interfaces and stuff.
1 parent b79a1e1 commit f5c4bff

File tree

14 files changed

+272
-56
lines changed

14 files changed

+272
-56
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.DEFAULT_GOAL := apply
22

3-
# Local build
3+
.PHONY: build
44
build:
55
@scripts/build_plugin.sh
66

7-
apply: build
7+
apply:
88
@kubectl apply -n argo -f deployments/argocd-executor-plugin-configmap.yaml
99
@kubectl apply -n argo -f examples/rbac.yaml
1010

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ spec:
2020
actions:
2121
- sync:
2222
project: guestbook
23-
app: guestbook
23+
apps:
24+
- guestbook
2425
```
2526
2627
## Getting Started

cmd/argocd-plugin/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
package main
22

33
import (
4-
"context"
54
"net/http"
65

6+
"k8s.io/client-go/kubernetes"
7+
"k8s.io/client-go/rest"
8+
79
"github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/common"
810
argocd "github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/internal/argocd-plugin"
911
)
1012

1113
func main() {
12-
ctx := context.WithValue(context.Background(), "namespace", common.Namespace());
13-
http.HandleFunc("/api/v1/template.execute", argocd.ArgocdPlugin(ctx))
14+
config, err := rest.InClusterConfig()
15+
if err != nil {
16+
panic(err.Error())
17+
}
18+
19+
client, err := kubernetes.NewForConfig(config)
20+
if err != nil {
21+
panic(err.Error())
22+
}
23+
24+
http.HandleFunc("/api/v1/template.execute", argocd.ArgocdPlugin(client, common.Namespace()))
1425
http.ListenAndServe(":4355", nil)
1526
}

common/common.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io/ioutil"
55
"os"
66
"strings"
7+
"testing"
78
)
89

910
// Returns the namespace the pod runs in.
@@ -22,3 +23,17 @@ func Namespace() string {
2223

2324
return "default"
2425
}
26+
27+
func AssertResponseBody(t testing.TB, got, want string) {
28+
t.Helper()
29+
if got != want {
30+
t.Errorf("response body is wrong, got %q want %q", got, want)
31+
}
32+
}
33+
34+
func AssertStatus(t testing.TB, got, want int) {
35+
t.Helper()
36+
if got != want {
37+
t.Errorf("did not get correct status, got %d, want %d", got, want)
38+
}
39+
}

deployments/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# argocd
33

44
* Needs: >= v3.3
5-
* Image: urielc12/argocd-plugin:v0.1.0
5+
* Image: urielc12/argocd-plugin
66

77
This is an ArgoCD plugin that allows you to interact with an argocd instance of your choice.
88
For examples visit https://github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/examples

deployments/argocd-executor-plugin-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
apiVersion: v1
33
data:
44
sidecar.container: |
5-
image: urielc12/argocd-plugin:v0.1.0
5+
image: urielc12/argocd-plugin
66
name: argocd-executor-plugin
77
ports:
88
- containerPort: 4355

deployments/plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ spec:
1111
sidecar:
1212
container:
1313
name: argocd-executor-plugin
14-
image: urielc12/argocd-plugin:v0.1.0
14+
image: urielc12/argocd-plugin
1515
ports:
1616
- containerPort: 4355
1717
resources:

examples/argocd-example-wf.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ metadata:
44
generateName: argocd-example-
55
spec:
66
ttlStrategy:
7-
secondsAfterCompletion: 60
7+
secondsAfterCompletion: 300
8+
secondsAfterFailure: 300
9+
secondsAfterSuccess: 300
810
serviceAccountName: workflow
911
entrypoint: main
1012
templates:
1113
- name: main
1214
plugin:
1315
argocd:
14-
serverUrl: https://my-argocd-instance.com/
16+
serverUrl: argocd-server.argocd.svc.cluster.local
1517
actions:
1618
- sync:
1719
project: default
18-
app: guestbook
19-
- refresh:
20-
project: default
21-
app: guestbook
20+
apps:
21+
- guestbook

go.mod

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,47 @@ require (
99
)
1010

1111
require (
12+
github.com/PuerkitoBio/purell v1.1.1 // indirect
13+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
14+
github.com/argoproj/argo-workflows/v3 v3.3.1 // indirect
1215
github.com/davecgh/go-spew v1.1.1 // indirect
13-
github.com/go-logr/logr v1.2.0 // indirect
16+
github.com/emicklei/go-restful v2.15.0+incompatible // indirect
17+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
18+
github.com/go-logr/logr v1.2.2 // indirect
19+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
20+
github.com/go-openapi/jsonreference v0.19.6 // indirect
21+
github.com/go-openapi/swag v0.19.15 // indirect
1422
github.com/gogo/protobuf v1.3.2 // indirect
1523
github.com/golang/protobuf v1.5.2 // indirect
16-
github.com/google/go-cmp v0.5.5 // indirect
17-
github.com/google/gofuzz v1.1.0 // indirect
24+
github.com/google/go-cmp v0.5.7 // indirect
25+
github.com/google/gofuzz v1.2.0 // indirect
1826
github.com/googleapis/gnostic v0.5.5 // indirect
27+
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
28+
github.com/josharian/intern v1.0.0 // indirect
1929
github.com/json-iterator/go v1.1.12 // indirect
30+
github.com/mailru/easyjson v0.7.7 // indirect
2031
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2132
github.com/modern-go/reflect2 v1.0.2 // indirect
33+
github.com/pkg/errors v0.9.1 // indirect
2234
github.com/pmezard/go-difflib v1.0.0 // indirect
23-
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
24-
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
25-
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
26-
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
35+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
36+
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
37+
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
38+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
2739
golang.org/x/text v0.3.7 // indirect
28-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
40+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
2941
google.golang.org/appengine v1.6.7 // indirect
42+
google.golang.org/genproto v0.0.0-20220218161850-94dd64e39d7c // indirect
43+
google.golang.org/grpc v1.44.0 // indirect
3044
google.golang.org/protobuf v1.27.1 // indirect
3145
gopkg.in/inf.v0 v0.9.1 // indirect
3246
gopkg.in/yaml.v2 v2.4.0 // indirect
3347
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
3448
k8s.io/api v0.23.5 // indirect
35-
k8s.io/klog/v2 v2.30.0 // indirect
36-
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
37-
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
38-
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
49+
k8s.io/klog/v2 v2.40.1 // indirect
50+
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf // indirect
51+
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
52+
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
3953
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
40-
sigs.k8s.io/yaml v1.2.0 // indirect
54+
sigs.k8s.io/yaml v1.3.0 // indirect
4155
)

0 commit comments

Comments
 (0)