Skip to content

Commit 8aee756

Browse files
committed
implement sync
executor doesn't go in the pkg dir, fix test delete old file typos pedantry small stuff remove unnecessary step all the. small things. options and timeout parallel syncs simplify nest sync action under app parallel action groups comment as documented docstrings break things up for readability instantiate API client once per plugin run update readme simplify go 1.19 distroless, smaller binary
1 parent 6964955 commit 8aee756

28 files changed

+1492
-410
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nohup.out
1+
.idea

CONTRIBUTING.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Get started
2+
3+
Here you will have everything you need to get started developing and testing the plugin.
4+
5+
## Prerequisites
6+
7+
Have these tools installed:
8+
9+
- make
10+
- docker
11+
- kind
12+
- kubectl
13+
- The `argo` ad `argocd` CLIs
14+
15+
## Set up the test environment
16+
17+
This command will install a kind cluster and Argo components.
18+
19+
```shell
20+
make setup
21+
```
22+
23+
## Build the plugin as a container image
24+
25+
```shell
26+
make build
27+
```
28+
29+
## Install the plugin
30+
31+
Run `make apply` to install the plugin.
32+
33+
## Run a test workflow
34+
35+
Run `make submit` to apply a workflow that runs the plugin.
36+
37+
To see that the workflow has synced the app, connect to the Argo CD server by going to https://localhost:8080 in your browser.
38+
39+
## Cleanup
40+
41+
To delete the test cluster, run the following:
42+
43+
```shell
44+
make clean
45+
```

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.19-alpine AS build
4+
WORKDIR /app
5+
COPY go.mod ./
6+
COPY go.sum ./
7+
RUN go mod download
8+
RUN apk add build-base
9+
COPY cmd ./cmd
10+
COPY internal ./internal
11+
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags "-w" -o plugin cmd/argocd-plugin/main.go
12+
13+
FROM gcr.io/distroless/static
14+
USER 1000
15+
COPY --from=build /app/plugin /
16+
17+
CMD [ "/plugin" ]

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
.DEFAULT_GOAL := apply
22

3+
.PHONY: setup
4+
setup:
5+
bash ./scripts/setup_cluster.sh
6+
37
.PHONY: build
48
build:
5-
@scripts/build_plugin.sh
9+
go mod tidy
10+
docker build --load -t urielc12/argocd-plugin:local -f ./Dockerfile .
11+
kind load docker-image urielc12/argocd-plugin:local --name argo-workflows-plugin-argocd
612

7-
apply:
8-
@kubectl apply -n argo -f deployments/argocd-executor-plugin-configmap.yaml
9-
@kubectl apply -n argo -f examples/rbac.yaml
13+
.PHONY: manifests
14+
manifests:
15+
argo executor-plugin build ./manifests
1016

11-
submit:
12-
@argo submit -n argo examples/argocd-example-wf.yaml
17+
.PHONY: apply
18+
apply: manifests
19+
kubectl apply -n argo -f deployments/argocd-executor-plugin-configmap.yaml
20+
kubectl apply -n argo -f examples/rbac.yaml
1321

14-
setup:
15-
@scripts/create_cluster.sh
22+
.PHONY: submit
23+
submit:
24+
argo submit -n argo examples/argocd-example-wf.yaml --serviceaccount workflow
1625

26+
.PHONY: clean
1727
clean:
18-
@scripts/delete_cluster.sh
28+
bash scripts/delete_cluster.sh

README.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22
<h1 align="center">Argocd Executor Plugin</h1>
3-
<p align="center">An <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/executor_plugins.md">Executor Plugin</a> for <a href="https://argoproj.github.io/argo-workflows/">Argo Workflows</a> that lets you interact with ArgoCD servers </br>
3+
<p align="center">An <a href="https://github.com/argoproj/argo-workflows/blob/master/docs/executor_plugins.md">Executor Plugin</a> for <a href="https://argoproj.github.io/argo-workflows/">Argo Workflows</a> that lets you interact with Argo CD servers <br>
44
<b>In Active Development</b></p>
55
</div>
66

@@ -17,34 +17,32 @@ spec:
1717
- name: main
1818
plugin:
1919
argocd:
20-
serverUrl: https://my-argocd-instance.com/
2120
actions:
22-
- sync:
23-
project: guestbook
24-
apps:
25-
- guestbook
26-
- guestbook-backend
21+
- - sync:
22+
apps:
23+
- name: guestbook
24+
- name: guestbook-backend
2725
```
2826
29-
</br>
30-
3127
## Getting Started
3228
33-
Head to the [scripts](scripts/README.md) directory to find out how to get the project up and running on your local machine for development and testing purposes.
29+
Head to the [scripts](CONTRIBUTING.md) directory to find out how to get the project up and running on your local machine for development and testing purposes.
3430
3531
### Prerequisites
3632
37-
You will need to have a working [Argo Workflows](https://argoproj.github.io/argo-workflows/) and [ArgoCD](https://argo-cd.readthedocs.io/en/stable/) instances to be able to deploy the plugin and use it.
33+
You will need to have a working [Argo Workflows](https://argoproj.github.io/argo-workflows/) and [Argo CD](https://argo-cd.readthedocs.io/en/stable/) instances to be able to deploy the plugin and use it.
3834
3935
### Installing
4036
41-
Read how to install the plugin in your Argo Workflows instance [here](out/README.md).
37+
```shell
38+
kubectl apply -n argo -f https://raw.githubusercontent.com/UrielCohen456/argocd-executor-plugin/main/deployments/argocd-executor-plugin-configmap.yaml
39+
```
4240

43-
</br>
41+
You will have to run the workflow using a service account with appropriate permissions. See [examples/rbac.yaml](examples/rbac.yaml) for an example.
4442

4543
## Contributing
4644

47-
Currently I am developing this on my own as my interest in workflow plugins is growing. <br>
45+
Currently, I am developing this on my own as my interest in workflow plugins is growing. <br>
4846
However, you are free to send me a message or create pull request or an issue if you have anything to suggest. <br>
4947
To get started check the scripts directory for setting up the dev environment.
5048

@@ -60,11 +58,11 @@ The goals of this plugin is to enable native usage of argocd actions inside work
6058
- [x] Figure out how to get access to kubernetes resources from inside the pod
6159
- [x] Figure out how to get access to argocd binary (Build image that has it)
6260
- [x] Figure out how to get current namespace (not supported in client library in python)
63-
- [x] Add argocd installation to the create_cluster.sh script
64-
- [x] Add a few different applications to argocd in the create_cluster.sh script (More complexity over time)
61+
- [x] Add argocd installation to the setup_cluster.sh script
62+
- [x] Add a few different applications to argocd in the setup_cluster.sh script (More complexity over time)
6563
- [x] Translate python server that works so far to go
66-
- [ ] Github actions pipeline to automatically build and test
67-
- [ ] Find way to get arguments from template
64+
- [ ] GitHub actions pipeline to automatically build and test
65+
- [x] Find way to get arguments from template
6866
- [ ] Build a simple json schema to validate inside the plugin
69-
- [ ] Build classes to be able to seperate concerns and test
67+
- [ ] Build classes to be able to separate concerns and test
7068
- [ ] Build unit tests and integration tests

build/.dockerignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

cmd/argocd-plugin/main.go

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

33
import (
4+
"fmt"
45
"net/http"
56

6-
"k8s.io/client-go/kubernetes"
7-
"k8s.io/client-go/rest"
7+
"github.com/argoproj/argo-cd/v2/pkg/apiclient"
88

9-
"github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/common"
10-
"github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/pkg/plugin"
9+
"github.com/UrielCohen456/argo-workflows-argocd-executor-plugin/internal"
1110
)
1211

1312
func main() {
14-
config, err := rest.InClusterConfig()
13+
client, err := apiclient.NewClient(&apiclient.ClientOptions{
14+
// TODO: make this configurable by passing a root CA.
15+
Insecure: true,
16+
})
1517
if err != nil {
16-
panic(err.Error())
18+
panic(fmt.Sprintf("failed to initialize Argo CD API client: %s", err))
1719
}
18-
19-
client, err := kubernetes.NewForConfig(config)
20+
http.HandleFunc("/api/v1/template.execute", argocd.ArgocdPlugin(argocd.NewApiExecutor(client)))
21+
err = http.ListenAndServe(":3000", nil)
2022
if err != nil {
2123
panic(err.Error())
2224
}
23-
24-
http.HandleFunc("/api/v1/template.execute", plugin.ArgocdPlugin(nil, client, common.Namespace()))
25-
http.ListenAndServe(":3000", nil)
2625
}

common/common.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

examples/argocd-example-wf.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ spec:
1313
- name: main
1414
plugin:
1515
argocd:
16-
serverUrl: argocd-server.argocd.svc.cluster.local
16+
# `actions` is a nested list. Items of inner arrays run in parallel. Top-level arrays run in sequence.
17+
# In this example, each inner array has only one item. The syncs run in sequence.
1718
actions:
18-
- sync:
19-
project: default
20-
apps:
21-
- guestbook
19+
# TODO: support other action types, e.g. `cluster` and `repository`.
20+
- - app:
21+
sync:
22+
apps:
23+
- name: guestbook
24+
options:
25+
- ServerSideApply=true
26+
timeout: 10s
27+
# Uncomment this to test a failed sync.
28+
# - - app:
29+
# sync:
30+
# apps:
31+
# - name: not-real

0 commit comments

Comments
 (0)