Skip to content

Commit f96d5cd

Browse files
fredlegerneilime
authored andcommitted
feat(argocd-cmp-hk-deployment): add a single entrypoint
1 parent c95e6d4 commit f96d5cd

File tree

10 files changed

+215
-82
lines changed

10 files changed

+215
-82
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
container-structure-test 1.22.0

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help
1+
.PHONY: help test test-all
22

33
help: ## Display help
44
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@@ -37,8 +37,13 @@ define run_linter
3737
DEFAULT_WORKSPACE="$(CURDIR)"; \
3838
LINTER_IMAGE="linter:latest"; \
3939
VOLUME="$$DEFAULT_WORKSPACE:$$DEFAULT_WORKSPACE"; \
40-
docker build --target linter --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $$LINTER_IMAGE .; \
40+
docker build --platform linux/amd64 \
41+
--target linter \
42+
--build-arg UID=$(shell id -u) \
43+
--build-arg GID=$(shell id -g) \
44+
--tag $$LINTER_IMAGE .; \
4145
docker run \
46+
--platform linux/amd64 \
4247
-e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \
4348
-e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \
4449
-e IGNORE_GITIGNORED_FILES=true \
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
.dockerignore
22
Dockerfile
3-
Taskfile.yml
4-
tests

images/argocd-cmp-hk-deployment/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM quay.io/argoproj/argocd:v3.2.0
22

33
USER root
4-
COPY * /hk-tools/
4+
COPY . /hk-tools/
55
RUN chown -R argocd:argocd /hk-tools
66

77
USER argocd

images/argocd-cmp-hk-deployment/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ Docker base image for the Hoverkraft ArgoCD custom CMP (Config Management Plugin
66

77
- **Image purpose:** Provides a containerized environment for ArgoCD to render and manage Hoverkraft deployments using Helm and Kustomize, with support for multi-source and single-source workflows.
88
- **Key scripts:**
9+
- `entrypoint.sh`: call correct script depending of the argocd context
910
- `single-source.sh`: Renders a Helm chart and applies Kustomize overlays, outputting the final Kubernetes manifests. Supports injection of deployment ID and ArgoCD environment variables.
1011
- `multi-sources.sh`: Generates a ConfigMap manifest for multi-source deployments, propagating the deployment ID.
1112
- **Kustomize template:** `kustomize-template.yaml` is used by the scripts to inject deployment-specific configuration.
1213

1314
## Scripts
1415

15-
- `single-source.sh`: Entrypoint for single-source ArgoCD CMP integration. Expects a Helm chart in the working directory and outputs manifests to stdout. Honors the following environment variables:
16+
- `entrypoint.sh`: Honors the following environment variables:
17+
- `ARGOCD_APP_NAME`: name of the argocd application
18+
- `ARGOCD_ENV_ARGOCD_MULTI_SOURCES`: is the argocd app multi-sources or not (0 or 1)
19+
- `ARGOCD_ENV_DEBUG`: enable debug env output (0 or 1)
20+
- `single-source.sh`: Expects a Helm chart in the working directory and outputs manifests to stdout. Honors the following environment variables:
1621
- `ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID`
17-
- `ARGOCD_APP_NAME`
18-
- `ARGOCD_APP_NAMESPACE`
19-
- `KUBE_VERSION`
20-
- `multi-sources.sh`: Outputs a ConfigMap manifest with the deployment ID, suitable for multi-source workflows.
22+
- `multi-sources.sh`: Outputs a ConfigMap manifest with the deployment ID, suitable for multi-source workflows. Honors the following environment variables:

images/argocd-cmp-hk-deployment/container-structure-test.yaml

Lines changed: 156 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,106 +3,185 @@ schemaVersion: "2.0.0"
33

44
commandTests:
55
- name: "single-source renders helm output with provided deployment id"
6+
envVars:
7+
- key: ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID
8+
value: "4242"
69
command: "bash"
710
args:
811
- -c
912
- |
1013
set -euo pipefail
11-
WORKDIR="$(mktemp -d)"
12-
cd "$WORKDIR"
13-
cat <<'EOF' > Chart.yaml
14-
apiVersion: v2
15-
name: hk-deployment-fixture
16-
description: Fixture chart for container tests
17-
type: application
18-
version: 0.1.0
19-
appVersion: "1.0.0"
20-
EOF
21-
cat <<'EOF' > values.yaml
22-
replicaCount: 1
23-
EOF
24-
mkdir -p templates
25-
cat <<'EOF' > templates/configmap.yaml
26-
apiVersion: v1
27-
kind: ConfigMap
28-
metadata:
29-
name: sample-config
30-
labels:
31-
app.kubernetes.io/name: sample-config
32-
data:
33-
foo: bar
34-
EOF
14+
cd /hk-tools/tests
3515
/hk-tools/single-source.sh
36-
envVars:
37-
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
38-
value: "4242"
39-
- key: "ARGOCD_APP_NAME"
40-
value: "hk-app"
41-
- key: "ARGOCD_APP_NAMESPACE"
42-
value: "hk-namespace"
43-
- key: "KUBE_VERSION"
44-
value: "1.31.0"
16+
exitCode: 0
4517
expectedOutput:
18+
- "name: hoverkraft-deployment"
4619
- 'deploymentId: "4242"'
47-
- "name: sample-config"
48-
- "foo: bar"
4920

5021
- name: "single-source falls back to unknown deployment id"
5122
command: "bash"
5223
args:
5324
- -c
5425
- |
5526
set -euo pipefail
56-
WORKDIR="$(mktemp -d)"
57-
cd "$WORKDIR"
58-
cat <<'EOF' > Chart.yaml
59-
apiVersion: v2
60-
name: hk-deployment-fixture
61-
description: Fixture chart for container tests
62-
type: application
63-
version: 0.1.0
64-
appVersion: "1.0.0"
65-
EOF
66-
cat <<'EOF' > values.yaml
67-
replicaCount: 1
68-
EOF
69-
mkdir -p templates
70-
cat <<'EOF' > templates/configmap.yaml
71-
apiVersion: v1
72-
kind: ConfigMap
73-
metadata:
74-
name: sample-config
75-
data:
76-
foo: bar
77-
EOF
27+
cd /hk-tools/tests
7828
/hk-tools/single-source.sh
79-
envVars:
80-
- key: "ARGOCD_APP_NAME"
81-
value: "hk-app"
82-
- key: "ARGOCD_APP_NAMESPACE"
83-
value: "hk-namespace"
84-
- key: "KUBE_VERSION"
85-
value: "1.31.0"
29+
exitCode: 0
8630
expectedOutput:
31+
- "name: hoverkraft-deployment"
8732
- "deploymentId: unknown"
88-
- "name: sample-config"
8933

9034
- name: "multi-sources propagates deployment id"
91-
command: "/hk-tools/multi-sources.sh"
9235
envVars:
9336
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
9437
value: "7777"
38+
command: "bash"
39+
args:
40+
- -c
41+
- |
42+
set -euo pipefail
43+
cd /hk-tools/tests
44+
/hk-tools/multi-sources.sh
45+
exitCode: 0
9546
expectedOutput:
96-
- 'deploymentId: "7777"'
9747
- "name: hoverkraft-deployment"
48+
- 'deploymentId: "7777"'
9849

9950
- name: "multi-sources defaults deployment id"
100-
command: "/hk-tools/multi-sources.sh"
51+
command: "bash"
52+
args:
53+
- -c
54+
- |
55+
set -euo pipefail
56+
cd /hk-tools/tests
57+
/hk-tools/multi-sources.sh
10158
expectedOutput:
59+
- "name: hoverkraft-deployment"
10260
- 'deploymentId: "unknown"'
61+
62+
- name: "entrypoint executes single-source when ARGOCD_MULTI_SOURCES is 0"
63+
command: "bash"
64+
args:
65+
- -c
66+
- |
67+
set -euo pipefail
68+
cd /hk-tools/tests
69+
/hk-tools/entrypoint.sh
70+
envVars:
71+
- key: "ARGOCD_ENV_ARGOCD_MULTI_SOURCES"
72+
value: "0"
73+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
74+
value: "1234"
75+
expectedOutput:
10376
- "name: hoverkraft-deployment"
77+
- 'deploymentId: "1234"'
78+
expectedError:
79+
- "hoverkraft-deployment CMP plugin"
80+
- "single-source application"
81+
82+
- name: "entrypoint executes multi-sources when ARGOCD_MULTI_SOURCES is 1"
83+
envVars:
84+
- key: "ARGOCD_ENV_ARGOCD_MULTI_SOURCES"
85+
value: "1"
86+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
87+
value: "5678"
88+
command: "bash"
89+
args:
90+
- -c
91+
- |
92+
set -euo pipefail
93+
cd /hk-tools/tests
94+
/hk-tools/entrypoint.sh
95+
expectedOutput:
96+
- "name: hoverkraft-deployment"
97+
- 'deploymentId: "5678"'
98+
expectedError:
99+
- "hoverkraft-deployment CMP plugin"
100+
- "multi-sources application"
101+
102+
- name: "entrypoint defaults to single-source when ARGOCD_MULTI_SOURCES is unset"
103+
envVars:
104+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
105+
value: "9999"
106+
- key: "ARGOCD_APP_NAME"
107+
value: "test-app"
108+
command: "bash"
109+
args:
110+
- -c
111+
- |
112+
set -euo pipefail
113+
cd /hk-tools/tests
114+
/hk-tools/entrypoint.sh
115+
expectedOutput:
116+
- "name: hoverkraft-deployment"
117+
- 'deploymentId: "9999"'
118+
expectedError:
119+
- "WARN: ARGOCD_MULTI_SOURCES is not set"
120+
- "single-source application"
121+
122+
- name: "entrypoint handles invalid ARGOCD_MULTI_SOURCES value"
123+
command: "bash"
124+
envVars:
125+
- key: "ARGOCD_ENV_ARGOCD_MULTI_SOURCES"
126+
value: "invalid"
127+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
128+
value: "8888"
129+
args:
130+
- -c
131+
- |
132+
set -euo pipefail
133+
cd /hk-tools/tests
134+
/hk-tools/entrypoint.sh
135+
exitCode: 0
136+
expectedError:
137+
- "WARN: ARGOCD_MULTI_SOURCES is invalid"
138+
- "WARN: defaulting to single source mode"
139+
140+
- name: "entrypoint with DEBUG enabled shows environment"
141+
envVars:
142+
- key: "ARGOCD_ENV_DEBUG"
143+
value: "true"
144+
- key: "ARGOCD_ENV_ARGOCD_MULTI_SOURCES"
145+
value: "0"
146+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
147+
value: "1111"
148+
command: "bash"
149+
args:
150+
- -c
151+
- |
152+
set -euo pipefail
153+
cd /hk-tools/tests
154+
/hk-tools/entrypoint.sh
155+
exitCode: 0
156+
expectedError:
157+
- '\+ DEBUG: current environment:'
158+
- "ARGOCD_ENV_DEBUG=true"
159+
- "ARGOCD_ENV_ARGOCD_MULTI_SOURCES=0"
160+
- "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID=1111"
161+
162+
- name: "entrypoint display argocd app name"
163+
command: "bash"
164+
envVars:
165+
- key: "ARGOCD_ENV_ARGOCD_MULTI_SOURCES"
166+
value: "1"
167+
- key: "ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID"
168+
value: "9999"
169+
args:
170+
- -c
171+
- |
172+
set -euo pipefail
173+
cd /hk-tools/tests
174+
/hk-tools/entrypoint.sh
175+
exitCode: 0
176+
expectedError:
177+
- '\+ application: hk-app'
104178

105179
fileExistenceTests:
180+
- name: "entrypoint script is present"
181+
path: "/hk-tools/entrypoint.sh"
182+
shouldExist: true
183+
isExecutableBy: "any"
184+
106185
- name: "single-source script is present"
107186
path: "/hk-tools/single-source.sh"
108187
shouldExist: true
@@ -119,3 +198,12 @@ fileExistenceTests:
119198

120199
metadataTest:
121200
user: "argocd"
201+
202+
# global configuration
203+
globalEnvVars:
204+
- key: "ARGOCD_APP_NAME"
205+
value: "hk-app"
206+
- key: "ARGOCD_APP_NAMESPACE"
207+
value: "hk-ns"
208+
- key: "KUBE_VERSION"
209+
value: "1.33.0"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# save stdout descriptor
4+
exec 3>&1
5+
# redirect all output to stderr
6+
exec 1>&2
7+
8+
echo "+ hoverkraft-deployment CMP plugin"
9+
echo "+ application: ${ARGOCD_APP_NAME}"
10+
11+
echo "+ init"
12+
13+
if [ -n "${ARGOCD_ENV_DEBUG}" ]; then
14+
echo "+ DEBUG: current environment:"
15+
printenv | grep "ARGOCD_ENV_"
16+
echo "+++"
17+
fi
18+
19+
# ARGOCD_ENV_ARGOCD_MULTI_SOURCES is a boolean that can be either 0 or 1
20+
if [ -z "${ARGOCD_ENV_ARGOCD_MULTI_SOURCES}" ]; then
21+
echo "WARN: ARGOCD_MULTI_SOURCES is not set (expected 0 or 1, got empty string)"
22+
echo "WARN: defaulting to single source mode"
23+
elif [ "${ARGOCD_ENV_ARGOCD_MULTI_SOURCES}" != "0" ] && [ "${ARGOCD_ENV_ARGOCD_MULTI_SOURCES}" != "1" ]; then
24+
echo "WARN: ARGOCD_MULTI_SOURCES is invalid (expected 0 or 1, got '${ARGOCD_ENV_ARGOCD_MULTI_SOURCES}')"
25+
echo "WARN: defaulting to single source mode"
26+
fi
27+
28+
case "${ARGOCD_ENV_ARGOCD_MULTI_SOURCES}" in
29+
1)
30+
echo "+ multi-sources application"
31+
/hk-tools/multi-sources.sh >&3
32+
;;
33+
*)
34+
echo "+ single-source application"
35+
/hk-tools/single-source.sh >&3
36+
;;
37+
esac

images/argocd-cmp-hk-deployment/kustomize-template.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resources:
66
- all.yaml
77

88
configMapGenerator:
9-
- name: hk-deployment
9+
- name: hoverkraft-deployment
1010
options:
1111
disableNameSuffixHash: true
1212
literals:

images/argocd-cmp-hk-deployment/multi-sources.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ exec 1>&2
77

88
echo "hoverkraft-deployment-multi"
99

10-
echo "+ init"
10+
echo "+ pre-checks"
1111
if [ -z "${ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID}" ]; then
12+
echo "WARN: HOVERKRAFT_DEPLOYMENT_ID is empty"
1213
ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID="unknown"
1314
fi
1415

images/argocd-cmp-hk-deployment/single-source.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ exec 1>&2
77

88
SOURCE_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
99

10-
echo "hk-deployment"
10+
echo "hk-deployment-single"
1111

12-
echo "+ init"
12+
echo "+ pre-checks"
1313
cp "$SOURCE_DIR/kustomize-template.yaml" ./kustomization.yaml
1414
if [ -z "${ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID}" ]; then
15+
echo "WARN: HOVERKRAFT_DEPLOYMENT_ID is empty"
1516
ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID="unknown"
1617
fi
1718
sed -i'' -e "s/<HK_DEPLOYMENT_ID>/${ARGOCD_ENV_HOVERKRAFT_DEPLOYMENT_ID}/" kustomization.yaml

0 commit comments

Comments
 (0)