Skip to content

Add delete runtime hook, possibility to add arbitrary config values to app-proxy and HELM_RELEASE_NAME environment variable #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/gitops-runtime/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
appVersion: 0.1.27-helm-alpha
description: A Helm chart for Codefresh gitops runtime
name: gitops-runtime
version: 0.2.0-16-alpha
version: 0.2.1-alpha.1
home: https://github.com/codefresh-io/gitops-runtime-helm
keywords:
- codefresh
Expand Down
2 changes: 1 addition & 1 deletion charts/gitops-runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gitops-runtime

![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)
![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)

A Helm chart for Codefresh gitops runtime

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
{{- define "cap-app-proxy.resources.configmap-documented-configs"}}
argoCdUrl: {{ .Values.config.argoCdUrl }}
argoCdUsername: {{ .Values.config.argoCdUsername }}
argoWorkflowsInsecure: {{ .Values.config.argoWorkflowsInsecure | quote }}
env: {{ .Values.config.env | quote}}
argoWorkflowsUrl: {{ default "" .Values.config.argoWorkflowsUrl }}
runtimeName: {{ .Values.global.runtime.name | quote}}
skipGitPermissionValidation: {{ .Values.config.skipGitPermissionValidation | quote }}
logLevel: {{ .Values.config.logLevel | quote }}
{{- $enrichmentValues := get .Values "image-enrichment" }}
{{- if $enrichmentValues.enabled }}
enrichmentConcurrencyCmName: {{ $enrichmentValues.config.concurrencyCmName | quote}}
enrichmentConcurrencyCmKey: {{ $enrichmentValues.config.concurrencyCmKey | quote}}
enrichmentServiceAccountName: {{ $enrichmentValues.serviceAccount.name | quote}}
enrichmentPodGcStrategy: {{ $enrichmentValues.config.podGcStrategy | quote}}
enrichmentTtlAfterCompletionInSeconds: {{ $enrichmentValues.config.ttlAfterCompletionInSeconds | quote }}
enrichmentTtlActiveInSeconds: {{ $enrichmentValues.config.ttlActiveInSeconds | quote }}
enrichmentClientHeartbeatIntervalInSeconds: {{ $enrichmentValues.config.clientHeartbeatIntervalInSeconds | quote }}
{{- end }}
{{- end }}

{{- define "cap-app-proxy.resources.configmap" }}
{{- $documentedConfigs := (include "cap-app-proxy.resources.configmap-documented-configs" . | fromYaml ) }}
{{- $overrides := .Values.config }}
{{- $mergedConfig := mergeOverwrite $documentedConfigs $overrides }}
apiVersion: v1
kind: ConfigMap
metadata:
name: cap-app-proxy-cm
labels:
{{- include "cap-app-proxy.labels" . | nindent 4 }}
data:
argoCdUrl: {{ .Values.config.argoCdUrl }}
argoCdUsername: {{ .Values.config.argoCdUsername }}
argoWorkflowsInsecure: {{ .Values.config.argoWorkflowsInsecure | quote }}
env: {{ .Values.config.env | quote}}
argoWorkflowsUrl: {{ default "" .Values.config.argoWorkflowsUrl }}
runtimeName: {{ .Values.global.runtime.name | quote}}
skipGitPermissionValidation: {{ .Values.config.skipGitPermissionValidation | quote }}
logLevel: {{ .Values.config.logLevel | quote }}
{{- $enrichmentValues := get .Values "image-enrichment" }}
{{- if $enrichmentValues.enabled }}
enrichmentConcurrencyCmName: {{ $enrichmentValues.config.concurrencyCmName | quote}}
enrichmentConcurrencyCmKey: {{ $enrichmentValues.config.concurrencyCmKey | quote}}
enrichmentServiceAccountName: {{ $enrichmentValues.serviceAccount.name | quote}}
enrichmentPodGcStrategy: {{ $enrichmentValues.config.podGcStrategy | quote}}
enrichmentTtlAfterCompletionInSeconds: {{ $enrichmentValues.config.ttlAfterCompletionInSeconds | quote }}
enrichmentTtlActiveInSeconds: {{ $enrichmentValues.config.ttlActiveInSeconds | quote }}
enrichmentClientHeartbeatIntervalInSeconds: {{ $enrichmentValues.config.clientHeartbeatIntervalInSeconds | quote }}
{{- end }}
{{- $mergedConfig | toYaml | nindent 2}}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ to keep the separation of components as pseudo library charts, they are defined
app-proxy components are generated.
*/}}
{{- define "codefresh-gitops-runtime.app-proxy.calculated-env-vars"}}
HELM_RELEASE_NAME: {{ .Release.Name }}
USER_TOKEN:
{{- include "codefresh-gitops-runtime.installation-token-env-var-value" . | nindent 2 }}
GIT_INTEGRATION_PROVIDER: {{ include "codefresh-gitops-runtime.git-integration.provider" .}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: cleanup-runtime-resources
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation
spec:
backoffLimit: 3
template:
Expand All @@ -14,14 +14,10 @@ spec:
containers:
- name: cleanup-runtime-resources
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
env:
- name: ISC_REPO_APPLICATION
value: {{ .Values.global.runtime.name}}-isc
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
command: ["sh", "-c"]
args:
- |
kubectl delete application $ISC_REPO_APPLICATION --cascade=foreground;
kubectl patch EventBus $(kubectl get eventbus -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge && \
kubectl patch Eventsource $(kubectl get EventSource -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge && \
kubectl patch Sensor $(kubectl get Sensor -l codefresh.io/internal=true | awk 'NR>1{print $1}' | xargs) -p '{"metadata":{"finalizers":null}}' --type=merge ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: batch/v1
kind: Job
metadata:
name: delete-runtime-from-platform
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
spec:
backoffLimit: 3
template:
spec:
restartPolicy: Never
containers:
- name: delete-runtime-from-platform
image: "{{ .Values.installer.image.repository }}:{{ .Values.installer.image.tag | default .Chart.Version }}"
env:
- name: RUNTIME_NAME
value: {{ .Values.global.runtime.name }}
- name: PLATFORM_URL
value: {{ .Values.global.codefresh.url }}
- name: USER_TOKEN
{{ include "codefresh-gitops-runtime.installation-token-env-var-value" . | nindent 10 }}
imagePullPolicy: {{ .Values.installer.image.pullPolicy }}
command: ["sh", "-c"]
args:
- |
if [ ! -z "$USER_TOKEN" ]; then
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}\"}}"
else
echo "User token unavailable, unable to remove runtime ${RUNTIME_NAME} from platform, please remove it from UI"
exit 1
fi
37 changes: 37 additions & 0 deletions charts/gitops-runtime/templates/hooks/pre-uninstall/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: runtime-cleanup
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
rules:
- apiGroups:
- "*"
resources:
- "*"
verbs:
- "*"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: runtime-cleanup
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
roleRef:
apiGroup: ""
kind: Role
name: runtime-cleanup
subjects:
- kind: ServiceAccount
name: runtime-cleanup
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: runtime-cleanup
annotations:
"helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
36 changes: 36 additions & 0 deletions charts/gitops-runtime/tests/app-proxy-misc_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ tests:
content:
name: PORT
value: 8787
- it: adding environment variables on main container
template: 'app-proxy/deployment.yaml'
values:
- ./values/mandatory-values.yaml
set:
app-proxy.env.SOME_ENV: 'test'
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: SOME_ENV
value: test
- it: overriding of argoCD and workflows Url through values
template: 'app-proxy/config.yaml'
values:
Expand Down Expand Up @@ -146,3 +158,27 @@ tests:
values:
- antarctica-east1
- antarctica-west1

- it: add some other config option to app-proxy
template: 'app-proxy/config.yaml'
values:
- ./values/mandatory-values.yaml
set:
app-proxy.config.myconf: 'test'
asserts:
- equal:
path: data.myconf
value: test

- it: Release name exists in app-proxy env
template: 'app-proxy/deployment.yaml'
values:
- ./values/mandatory-values.yaml
release:
name: my-release
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: HELM_RELEASE_NAME
value: my-release