Skip to content

Commit 9133d6f

Browse files
Add delete runtime hook, possibility to add arbitrary config values to app-proxy and HELM_RELEASE_NAME environment variable (#25)
* add delete runtime hook, possibility to add arbitrary config values to app-proxy and HELM_RELEASE_NAME environment variable
1 parent 21cda20 commit 9133d6f

File tree

8 files changed

+134
-25
lines changed

8 files changed

+134
-25
lines changed

charts/gitops-runtime/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
appVersion: 0.1.27-helm-alpha
33
description: A Helm chart for Codefresh gitops runtime
44
name: gitops-runtime
5-
version: 0.2.0-16-alpha
5+
version: 0.2.1-alpha.1
66
home: https://github.com/codefresh-io/gitops-runtime-helm
77
keywords:
88
- codefresh

charts/gitops-runtime/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# gitops-runtime
22

3-
![Version: 0.2.0-16-alpha](https://img.shields.io/badge/Version-0.2.0--16--alpha-informational?style=flat-square) ![AppVersion: 0.1.27-helm-alpha](https://img.shields.io/badge/AppVersion-0.1.27--helm--alpha-informational?style=flat-square)
3+
![Version: 0.2.1-alpha.1](https://img.shields.io/badge/Version-0.2.1--alpha.1-informational?style=flat-square) ![AppVersion: 0.1.27-helm-alpha](https://img.shields.io/badge/AppVersion-0.1.27--helm--alpha-informational?style=flat-square)
44

55
A Helm chart for Codefresh gitops runtime
66

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1+
{{- define "cap-app-proxy.resources.configmap-documented-configs"}}
2+
argoCdUrl: {{ .Values.config.argoCdUrl }}
3+
argoCdUsername: {{ .Values.config.argoCdUsername }}
4+
argoWorkflowsInsecure: {{ .Values.config.argoWorkflowsInsecure | quote }}
5+
env: {{ .Values.config.env | quote}}
6+
argoWorkflowsUrl: {{ default "" .Values.config.argoWorkflowsUrl }}
7+
runtimeName: {{ .Values.global.runtime.name | quote}}
8+
skipGitPermissionValidation: {{ .Values.config.skipGitPermissionValidation | quote }}
9+
logLevel: {{ .Values.config.logLevel | quote }}
10+
{{- $enrichmentValues := get .Values "image-enrichment" }}
11+
{{- if $enrichmentValues.enabled }}
12+
enrichmentConcurrencyCmName: {{ $enrichmentValues.config.concurrencyCmName | quote}}
13+
enrichmentConcurrencyCmKey: {{ $enrichmentValues.config.concurrencyCmKey | quote}}
14+
enrichmentServiceAccountName: {{ $enrichmentValues.serviceAccount.name | quote}}
15+
enrichmentPodGcStrategy: {{ $enrichmentValues.config.podGcStrategy | quote}}
16+
enrichmentTtlAfterCompletionInSeconds: {{ $enrichmentValues.config.ttlAfterCompletionInSeconds | quote }}
17+
enrichmentTtlActiveInSeconds: {{ $enrichmentValues.config.ttlActiveInSeconds | quote }}
18+
enrichmentClientHeartbeatIntervalInSeconds: {{ $enrichmentValues.config.clientHeartbeatIntervalInSeconds | quote }}
19+
{{- end }}
20+
{{- end }}
21+
122
{{- define "cap-app-proxy.resources.configmap" }}
23+
{{- $documentedConfigs := (include "cap-app-proxy.resources.configmap-documented-configs" . | fromYaml ) }}
24+
{{- $overrides := .Values.config }}
25+
{{- $mergedConfig := mergeOverwrite $documentedConfigs $overrides }}
226
apiVersion: v1
327
kind: ConfigMap
428
metadata:
529
name: cap-app-proxy-cm
630
labels:
731
{{- include "cap-app-proxy.labels" . | nindent 4 }}
832
data:
9-
argoCdUrl: {{ .Values.config.argoCdUrl }}
10-
argoCdUsername: {{ .Values.config.argoCdUsername }}
11-
argoWorkflowsInsecure: {{ .Values.config.argoWorkflowsInsecure | quote }}
12-
env: {{ .Values.config.env | quote}}
13-
argoWorkflowsUrl: {{ default "" .Values.config.argoWorkflowsUrl }}
14-
runtimeName: {{ .Values.global.runtime.name | quote}}
15-
skipGitPermissionValidation: {{ .Values.config.skipGitPermissionValidation | quote }}
16-
logLevel: {{ .Values.config.logLevel | quote }}
17-
{{- $enrichmentValues := get .Values "image-enrichment" }}
18-
{{- if $enrichmentValues.enabled }}
19-
enrichmentConcurrencyCmName: {{ $enrichmentValues.config.concurrencyCmName | quote}}
20-
enrichmentConcurrencyCmKey: {{ $enrichmentValues.config.concurrencyCmKey | quote}}
21-
enrichmentServiceAccountName: {{ $enrichmentValues.serviceAccount.name | quote}}
22-
enrichmentPodGcStrategy: {{ $enrichmentValues.config.podGcStrategy | quote}}
23-
enrichmentTtlAfterCompletionInSeconds: {{ $enrichmentValues.config.ttlAfterCompletionInSeconds | quote }}
24-
enrichmentTtlActiveInSeconds: {{ $enrichmentValues.config.ttlActiveInSeconds | quote }}
25-
enrichmentClientHeartbeatIntervalInSeconds: {{ $enrichmentValues.config.clientHeartbeatIntervalInSeconds | quote }}
26-
{{- end }}
33+
{{- $mergedConfig | toYaml | nindent 2}}
2734
{{- end }}

charts/gitops-runtime/templates/app-proxy/_app-proxy-env.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ to keep the separation of components as pseudo library charts, they are defined
44
app-proxy components are generated.
55
*/}}
66
{{- define "codefresh-gitops-runtime.app-proxy.calculated-env-vars"}}
7+
HELM_RELEASE_NAME: {{ .Release.Name }}
78
USER_TOKEN:
89
{{- include "codefresh-gitops-runtime.installation-token-env-var-value" . | nindent 2 }}
910
GIT_INTEGRATION_PROVIDER: {{ include "codefresh-gitops-runtime.git-integration.provider" .}}

charts/gitops-runtime/templates/hooks/pre-uninstall/cleanup-resources.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: cleanup-runtime-resources
55
annotations:
66
"helm.sh/hook": pre-delete
7-
"helm.sh/hook-delete-policy": hook-succeeded
7+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
88
spec:
99
backoffLimit: 3
1010
template:
@@ -14,14 +14,10 @@ spec:
1414
containers:
1515
- name: cleanup-runtime-resources
1616
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
17-
env:
18-
- name: ISC_REPO_APPLICATION
19-
value: {{ .Values.global.runtime.name}}-isc
2017
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
2118
command: ["sh", "-c"]
2219
args:
2320
- |
24-
kubectl delete application $ISC_REPO_APPLICATION --cascade=foreground;
2521
kubectl patch EventBus $(kubectl get eventbus -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge && \
2622
kubectl patch Eventsource $(kubectl get EventSource -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge && \
2723
kubectl patch Sensor $(kubectl get Sensor -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge ;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: delete-runtime-from-platform
5+
annotations:
6+
"helm.sh/hook": pre-delete
7+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
8+
spec:
9+
backoffLimit: 3
10+
template:
11+
spec:
12+
restartPolicy: Never
13+
containers:
14+
- name: delete-runtime-from-platform
15+
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
16+
env:
17+
- name: RUNTIME_NAME
18+
value: {{ .Values.global.runtime.name }}
19+
- name: PLATFORM_URL
20+
value: {{ .Values.global.codefresh.url }}
21+
- name: USER_TOKEN
22+
{{ include "codefresh-gitops-runtime.installation-token-env-var-value" . | nindent 10 }}
23+
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
24+
command: ["sh", "-c"]
25+
args:
26+
- |
27+
if [ ! -z "$USER_TOKEN" ]; then
28+
curl ${PLATFORM_URL}/2.0/api/graphql -H "Authorization: ${USER_TOKEN}" -H "Content-Type: application/json" -d "{\"query\": \"mutation deleteRuntime(\$name: String"'!'") {\n deleteRuntime(name: \$name) }\",\"variables\": {\"name\": \"${RUNTIME_NAME}\"}}"
29+
else
30+
echo "User token unavailable, unable to remove runtime ${RUNTIME_NAME} from platform, please remove it from UI"
31+
exit 1
32+
fi
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: runtime-cleanup
5+
annotations:
6+
"helm.sh/hook": pre-delete
7+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
8+
rules:
9+
- apiGroups:
10+
- "*"
11+
resources:
12+
- "*"
13+
verbs:
14+
- "*"
15+
---
16+
apiVersion: rbac.authorization.k8s.io/v1
17+
kind: RoleBinding
18+
metadata:
19+
name: runtime-cleanup
20+
annotations:
21+
"helm.sh/hook": pre-delete
22+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
23+
roleRef:
24+
apiGroup: ""
25+
kind: Role
26+
name: runtime-cleanup
27+
subjects:
28+
- kind: ServiceAccount
29+
name: runtime-cleanup
30+
---
31+
apiVersion: v1
32+
kind: ServiceAccount
33+
metadata:
34+
name: runtime-cleanup
35+
annotations:
36+
"helm.sh/hook": pre-delete
37+
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed

charts/gitops-runtime/tests/app-proxy-misc_test.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ tests:
1515
content:
1616
name: PORT
1717
value: 8787
18+
- it: adding environment variables on main container
19+
template: 'app-proxy/deployment.yaml'
20+
values:
21+
- ./values/mandatory-values.yaml
22+
set:
23+
app-proxy.env.SOME_ENV: 'test'
24+
asserts:
25+
- contains:
26+
path: spec.template.spec.containers[0].env
27+
content:
28+
name: SOME_ENV
29+
value: test
1830
- it: overriding of argoCD and workflows Url through values
1931
template: 'app-proxy/config.yaml'
2032
values:
@@ -146,3 +158,27 @@ tests:
146158
values:
147159
- antarctica-east1
148160
- antarctica-west1
161+
162+
- it: add some other config option to app-proxy
163+
template: 'app-proxy/config.yaml'
164+
values:
165+
- ./values/mandatory-values.yaml
166+
set:
167+
app-proxy.config.myconf: 'test'
168+
asserts:
169+
- equal:
170+
path: data.myconf
171+
value: test
172+
173+
- it: Release name exists in app-proxy env
174+
template: 'app-proxy/deployment.yaml'
175+
values:
176+
- ./values/mandatory-values.yaml
177+
release:
178+
name: my-release
179+
asserts:
180+
- contains:
181+
path: spec.template.spec.containers[0].env
182+
content:
183+
name: HELM_RELEASE_NAME
184+
value: my-release

0 commit comments

Comments
 (0)