Skip to content

Commit

Permalink
Argocd v2.6 plugin (#6)
Browse files Browse the repository at this point in the history
* remove generated files

* convert to new sidecar plugin format for argocd >= v2.6

* generate client for goreleaser

* fix goreleaser docker build

* update deps

* update deps
  • Loading branch information
wr0ngway authored May 22, 2023
1 parent 8a60259 commit 3d31e9b
Show file tree
Hide file tree
Showing 440 changed files with 331 additions and 182,216 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
local
dist/
pkg/
.git*
5 changes: 4 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
with:
go-version: 1.17.2
id: go

- name: Set environment from cloudtruth
uses: cloudtruth/configure-action@v2
with:
Expand All @@ -37,6 +37,9 @@ jobs:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}

- name: Make client stubs
run: make client

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
local/
dist/
pkg/
.git*
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dockers:
- image_templates:
- "cloudtruth/{{.ProjectName}}:{{ .Tag }}"
- "cloudtruth/{{.ProjectName}}:latest"
extra_files:
- plugin.yaml
archives:
- replacements:
darwin: Darwin
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.0 (05/22/2023)
------------------

convert to new sidecar plugin format for argocd >= v2.6

0.6.0 (03/23/2023)
------------------

Expand Down
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM alpine
ENTRYPOINT ["/argocd-cloudtruth-plugin"]
COPY argocd-cloudtruth-plugin /
ARG CMP_ROOT=/home/argocd/cmp-server

COPY argocd-cloudtruth-plugin /usr/bin/
COPY plugin.yaml ${CMP_ROOT}/config/
32 changes: 32 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use this for local development to get the image, compiled for the right platform, into a local cluster without having to push to an image repo.
FROM openapitools/openapi-generator-cli:v6.2.0 AS client-builder

COPY . /build/

RUN mkdir -p /build/pkg
RUN curl -s https://api.cloudtruth.io/api/schema/ > /build/pkg/openapi.yml

RUN /usr/local/bin/docker-entrypoint.sh generate \
-i /build/pkg/openapi.yml \
-g go \
-o /build/pkg/cloudtruth \
--additional-properties packageName=cloudtruth \
--additional-properties isGoSubmodule=true \
--additional-properties packageVersion=1.0.0 \
--additional-properties enumClassPrefix=true \
--type-mappings=object=interface{}

FROM golang:1.20-alpine AS go-builder

COPY . /build/
COPY --from=client-builder /build/pkg /build/pkg

WORKDIR /build
RUN ls -lart /build/
RUN go build -o dist/argocd-cloudtruth-plugin

FROM alpine
ARG CMP_ROOT=/home/argocd/cmp-server

COPY --from=go-builder /build/dist/argocd-cloudtruth-plugin /usr/bin/
COPY plugin.yaml ${CMP_ROOT}/config/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pkg/cloudtruth/client.go: pkg/openapi.yml
--type-mappings=object=interface{}

pkg/openapi.yml: pkg
curl -s https://api.cloudtruth.io/api/schema/ > pkg/openapi.yml
curl -s https://api.cloudtruth.io/api/schema/ > pkg/openapi.yml

pkg:
mkdir -p pkg
Expand Down
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ git clone https://github.com/cloudtruth/argocd-cloudtruth-plugin

## Usage

The default installation process adds the following settings to the Secret named argocd-cloudtruth-plugin, and applies them as environment variables to the argocd-repo-server Deployment. Theses act as defaults for the plugin, and can be overriden in the plugin setup page for each argocd project.
Current versions of this plugin (>= 0.7.0) only support ArgoCD v2.6 and newer due to the changes in the configuration management plugin. It gets installed as a sidecar container against the `argocd-repo-server`.

After installing the plugin, create the file `.argocd-cloudtruth-plugin` in your Application's repo(+path) to allow this plugin to be used for that Application. The file can be empty or contain a yaml dictionary to override the plugin's configuration for that repo. Since this CMP is defined as a sidecar, without creating this file, the plugin can only be enabled for a project by [manually editing the Application manifest](https://argo-cd.readthedocs.io/en/stable/operator-manual/config-management-plugins/#using-a-config-management-plugin-with-an-application).

The configuration for using the plugin can be set and read in one of 4 ways (in order of priority - last wins):
* During install, the `CLOUDTRUTH_*` settings are added to `Secret[argocd-cloudtruth-plugin]` and are made available as system environment variables with an envFrom mount to `argocd-repo-server`. You can edit the Secret or re-run the installer to change them.
* Application specific settings can be added to the plugin activation file (as yaml) checked into the repo. The keys in the file get transformed to look like environment variables in order to determine matches for priority, so a key in the file of `cloudtruth-project` will get compared to and override the environment variable `CLOUDTRUTH_PROJECT`
* Plugin specific environment variables can be set as part of its attachment to the argocd Application
* Plugin specific params can be set as part of its attachment to the argocd Application

The settings that control the plugin's behavior area as follows:

| Parameter | Description | Type | Default | Required |
|-----------|-------------|------|---------|:--------:|
Expand All @@ -28,32 +38,24 @@ The default installation process adds the following settings to the Secret named
| CLOUDTRUTH_REFERENCE_PATTERN | the pattern that indicates parameter references in the input files | string | `<%s>` | no |
| CLOUDTRUTH_FILE_PATTERN | the file pattern (glob) of the input files | array(string) delim=, | `*.y*ml` | no |

Once the plugin has been installed, you can enable it when creating a new Argo project:

![Enable for a new plugin](docs/plugin-select.png)

and override the variables needed for that project:

![Set plugin parameter](docs/plugin-config.png)

To edit an existing project, visit the plugin settings from the PARAMETERS tab:
Once the plugin has been enabled for an Application, you can change settings by visiting the plugin settings from the PARAMETERS tab in the App Details section of the Application:

![Edit plugin on a project](docs/plugin-add.png)

Once enabled, the plugin will act upon the yaml files produced by the Argo project, performing substitutions of text like `<PARAMETER_OR_SECRET_NAME>` with the lookup of the value of `PARAMETER_OR_SECRET_NAME` in CloudTruth for the given `CLOUDTRUTH_PROJECT`, `CLOUDTRUTH_ENVIRONMENT` and `CLOUDTRUTH_TAG`

## Argo CD CLI Usage
## Argo CD CLI Usage
### Adding the plugin to existing projects

The [Argo CD cli](https://argo-cd.readthedocs.io/en/stable/getting_started/#2-download-argo-cd-cli) will allow you to add The CLoudTruth plugin to your existing apps.
```shell
argocd app set YOUR_APP --config-management-plugin argocd-cloudtruth-plugin
```
To add The CLoudTruth plugin to your existing Application, create the `.argocd-cloudtruth-plugin` trigger file in your Application's repo and Sync.

### Override plugin parameters
You can set the plugin environment parameters on [create](https://argo-cd.readthedocs.io/en/stable/user-guide/commands/argocd_app_create/) or [set](https://argo-cd.readthedocs.io/en/stable/user-guide/commands/argocd_app_set/) them after the app is deployed with the ```--plugin-env``` option. This allows you to change app config settings on the next sync.

**create**

Note that one SHOULD NOT provide the `--config-management-plugin` argument, as that only works for the [deprecated ConfigMap structure for plugins](https://argo-cd.readthedocs.io/en/stable/operator-manual/config-management-plugins/#using-a-config-management-plugin-with-an-application)

```shell
argocd app create YOUR_APP --repo https://github.com/YOUR_REPO --path YOUR_PATH_IN_REPO --dest-server YOUR_K8S_SERVER --dest-namespace default --config-management-plugin argocd-cloudtruth-plugin --plugin-env CLOUDTRUTH_PROJECT=YOUR_CLOUDTRUTH_PROJECT
```
Expand All @@ -63,10 +65,28 @@ argocd app create YOUR_APP --repo https://github.com/YOUR_REPO --path YOUR_PATH_
argocd app set YOUR_APP --plugin-env CLOUDTRUTH_PROJECT=YOUR_CLOUDTRUTH_PROJECT
```


## Development

After checking out the repo, run `make`. To generate new client stubs (vs what is checked in), run `make clean` before running `make`
After checking out the repo, run `make`. To generate new client stubs, run `make clean` before running `make`

### Developing against a local minikube cluster

In order to build and test the plugin against a local cluster, it needs to be compiled for the correct platform and the sidecar image pushed into the cluster to avoid having to push it to an external image repo.

* Add to argocd-repo-server cloudtruth plugin sidecar manifest: imagePullPolicy: Never
* Run installer (`install/seup.sh`) to add plugin to cluster
* Set minikube docker env:
```
eval $(minikube docker-env)
```
* Run docker build against `Dockerfile.dev` within the same terminal as docker env:
```
docker build -t cloudtruth/argocd-cloudtruth-plugin -f Dockerfile.dev .
```
* Restart argocd-server:
```
kubectl rollout restart -n argocd deployment/argocd-repo-server
```

## Contributing

Expand Down
Binary file modified docs/plugin-add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 8 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ go 1.17
require (
github.com/argocd-cloudtruth-plugin/pkg/cloudtruth v1.0.0
github.com/jessevdk/go-flags v1.5.0
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.2
github.com/yargevad/filepathx v1.0.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/golang/protobuf v1.4.2 // indirect
golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

replace github.com/argocd-cloudtruth-plugin/pkg/cloudtruth v1.0.0 => ./pkg/cloudtruth
Loading

0 comments on commit 3d31e9b

Please sign in to comment.