diff --git a/charts/capsule/Chart.yaml b/charts/capsule/Chart.yaml index eb88e2a1..50af629e 100644 --- a/charts/capsule/Chart.yaml +++ b/charts/capsule/Chart.yaml @@ -21,7 +21,7 @@ sources: # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. -version: 0.0.6 +version: 0.0.7 # This is the version number of the application being deployed. # This version number should be incremented each time you make changes to the application. diff --git a/charts/capsule/templates/_helpers.tpl b/charts/capsule/templates/_helpers.tpl index 16e019e7..0faa5694 100644 --- a/charts/capsule/templates/_helpers.tpl +++ b/charts/capsule/templates/_helpers.tpl @@ -67,3 +67,24 @@ Create the fully-qualified Docker image to use {{- define "capsule.fullyQualifiedDockerImage" -}} {{- printf "%s:%s" .Values.manager.image.repository ( .Values.manager.image.tag | default (printf "v%s" .Chart.AppVersion) ) -}} {{- end }} + +{{/* +Create the Capsule Deployment name to use +*/}} +{{- define "capsule.deploymentName" -}} +{{- printf "%s-controller-manager" (include "capsule.fullname" .) -}} +{{- end }} + +{{/* +Create the Capsule CA Secret name to use +*/}} +{{- define "capsule.secretCaName" -}} +{{- printf "%s-ca" (include "capsule.fullname" .) -}} +{{- end }} + +{{/* +Create the Capsule TLS Secret name to use +*/}} +{{- define "capsule.secretTlsName" -}} +{{- printf "%s-tls" (include "capsule.fullname" .) -}} +{{- end }} diff --git a/charts/capsule/templates/ca.yaml b/charts/capsule/templates/ca.yaml index 581a576f..aec0f58c 100644 --- a/charts/capsule/templates/ca.yaml +++ b/charts/capsule/templates/ca.yaml @@ -1,7 +1,10 @@ apiVersion: v1 kind: Secret metadata: + annotations: + "helm.sh/hook": "pre-install" + "helm.sh/hook-delete-policy": "before-hook-creation" labels: {{- include "capsule.labels" . | nindent 4 }} - name: {{ include "capsule.fullname" . }}-ca + name: {{ include "capsule.secretCaName" . }} data: diff --git a/charts/capsule/templates/certs.yaml b/charts/capsule/templates/certs.yaml index bf5b4fe9..715ccdf1 100644 --- a/charts/capsule/templates/certs.yaml +++ b/charts/capsule/templates/certs.yaml @@ -1,7 +1,10 @@ apiVersion: v1 kind: Secret metadata: + annotations: + "helm.sh/hook": "pre-install" + "helm.sh/hook-delete-policy": "before-hook-creation" labels: {{- include "capsule.labels" . | nindent 4 }} - name: {{ include "capsule.fullname" . }}-tls + name: {{ include "capsule.secretTlsName" . }} data: diff --git a/charts/capsule/templates/deployment.yaml b/charts/capsule/templates/deployment.yaml index aec15b1c..bfc1bebe 100644 --- a/charts/capsule/templates/deployment.yaml +++ b/charts/capsule/templates/deployment.yaml @@ -1,7 +1,7 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "capsule.fullname" . }}-controller-manager + name: {{ include "capsule.deploymentName" . }} labels: {{- include "capsule.labels" . | nindent 4 }} spec: diff --git a/charts/capsule/templates/post-install-job.yaml b/charts/capsule/templates/post-install-job.yaml index 4f278d2d..3027b23f 100644 --- a/charts/capsule/templates/post-install-job.yaml +++ b/charts/capsule/templates/post-install-job.yaml @@ -1,3 +1,6 @@ +{{- $cmd := "while [ -z $$(kubectl -n $NAMESPACE get secret capsule-tls -o jsonpath='{.data.tls\\\\.crt}') ];" -}} +{{- $cmd = printf "%s do echo 'waiting Capsule to be up and running...' && sleep 5;" $cmd -}} +{{- $cmd = printf "%s done" $cmd -}} apiVersion: batch/v1 kind: Job metadata: @@ -26,7 +29,7 @@ spec: containers: - name: post-install-job image: "bitnami/kubectl:1.18" - command: ["sh", "-c", "while [ -z $$(kubectl -n $NAMESPACE get secret capsule-tls -o jsonpath='{.data.tls\\.crt}') ]; do echo 'waiting Capsule to be up and running...' && sleep 5; done"] + command: ["sh", "-c", "{{ $cmd }}"] env: - name: NAMESPACE valueFrom: diff --git a/charts/capsule/templates/pre-delete-job.yaml b/charts/capsule/templates/pre-delete-job.yaml index 57efca99..fd50639d 100644 --- a/charts/capsule/templates/pre-delete-job.yaml +++ b/charts/capsule/templates/pre-delete-job.yaml @@ -1,5 +1,7 @@ -{{- $deploymentName := printf "%s-controller-manager" (include "capsule.fullname" .) -}} -{{- $cmd := printf "kubectl scale deployment -n $NAMESPACE %s --replicas 0 && kubectl delete clusterroles.rbac.authorization.k8s.io capsule-namespace-deleter capsule-namespace-provisioner --ignore-not-found && kubectl delete clusterrolebindings.rbac.authorization.k8s.io capsule-namespace-provisioner --ignore-not-found" $deploymentName -}} +{{- $cmd := printf "kubectl scale deployment -n $NAMESPACE %s --replicas 0 &&" (include "capsule.deploymentName" .) -}} +{{- $cmd = printf "%s kubectl delete secret -n $NAMESPACE %s %s --ignore-not-found &&" $cmd (include "capsule.secretTlsName" .) (include "capsule.secretCaName" .) -}} +{{- $cmd = printf "%s kubectl delete clusterroles.rbac.authorization.k8s.io capsule-namespace-deleter capsule-namespace-provisioner --ignore-not-found &&" $cmd -}} +{{- $cmd = printf "%s kubectl delete clusterrolebindings.rbac.authorization.k8s.io capsule-namespace-provisioner --ignore-not-found" $cmd -}} apiVersion: batch/v1 kind: Job metadata: @@ -26,12 +28,12 @@ spec: spec: restartPolicy: Never containers: - - name: pre-delete-job - image: "bitnami/kubectl:1.18" - command: ["sh", "-c", {{ $cmd | quote }}] - env: - - name: NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace + - name: pre-delete-job + image: "bitnami/kubectl:1.18" + command: [ "sh", "-c", "{{ $cmd }}"] + env: + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace serviceAccountName: {{ include "capsule.serviceAccountName" . }}