diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 4b98b21c..ec7e052a 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -191,6 +191,23 @@ Reduce duplication of the st2.*.conf volume details {{- end }} {{- end -}} +{{- define "stackstorm-ha.init-containers-wait-for-auth" -}} +- name: wait-for-auth + image: "alpine/curl:8.4.0" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - 'sh' + - '-c' + - > + until curl -skSL --fail -w '\n' -X POST -u {{ .Values.st2.username }}:{{ .Values.st2.password }} "https://{{ required ".Values.ingress.fqdn is required if .Values.ingress.class is non-empty" .Values.ingress.fqdn | printf (ternary "canary-%s" "%s" .Values.phaseCanary)}}/auth/tokens"; do + echo 'Waiting for StackStorm API' + sleep 2; + done + {{- with .Values.securityContext }} + securityContext: {{- toYaml . | nindent 8 }} + {{- end }} +{{- end -}} + {{- define "stackstorm-ha.init-containers-wait-for-db" -}} {{- if index .Values "mongodb" "enabled" }} {{- $mongodb_port := (int (index .Values "mongodb" "service" "port")) }} diff --git a/templates/tests/st2tests-configmap.yaml b/templates/tests/st2tests-configmap.yaml index 13703a61..2299ca94 100644 --- a/templates/tests/st2tests-configmap.yaml +++ b/templates/tests/st2tests-configmap.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Release.Name }}-st2tests + name: {{ .Release.Name }}-job-st2-tests labels: {{- include "stackstorm-ha.labels" (list $ "st2tests") | nindent 4 }} data: st2tests.sh: | diff --git a/templates/tests/st2tests-job.yaml b/templates/tests/st2tests-job.yaml new file mode 100644 index 00000000..c5ef6752 --- /dev/null +++ b/templates/tests/st2tests-job.yaml @@ -0,0 +1,89 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: "{{ .Release.Name }}-job-st2-tests" + labels: {{- include "stackstorm-ha.labels" (list $ "st2tests") | nindent 4 }} + annotations: + "helm.sh/hook": test-success + "helm.sh/hook-delete-policy": hook-succeeded +spec: + template: + metadata: + name: "{{ .Release.Name }}-job-st2-tests" + labels: {{- include "stackstorm-ha.labels" (list $ "st2tests") | nindent 8 }} + annotations: + "helm.sh/hook": test-success + "helm.sh/hook-delete-policy": hook-succeeded + spec: + initContainers: + {{- include "stackstorm-ha.init-containers-wait-for-auth" . | nindent 6 }} + # Sidecar container to copy BATS framework to the main container + - name: bats-core + image: "bats/bats:1.8.2" + imagePullPolicy: {{ $.Values.image.pullPolicy }} + {{- with .Values.securityContext }} + securityContext: {{- toYaml . | nindent 12 }} + {{- end }} + command: + - bash + - -ec + - | + cp -R /opt/bats /tools/ + volumeMounts: + - name: tools + mountPath: /tools + - name: bats-addons + image: "alpine/git:2.36.3" + imagePullPolicy: {{ $.Values.image.pullPolicy }} + {{- with .Values.securityContext }} + securityContext: {{- toYaml . | nindent 12 }} + {{- end }} + command: + - ash + - -ec + - | + git clone --config advice.detachedHead=false --depth 1 --branch v0.3.0 \ + https://github.com/ztombol/bats-assert /tools/bats-assert + git clone --config advice.detachedHead=false --depth 1 --branch v0.2.0 \ + https://github.com/ztombol/bats-file /tools/bats-file + git clone --config advice.detachedHead=false --depth 1 --branch v0.3.0 \ + https://github.com/ztombol/bats-support /tools/bats-support + volumeMounts: + - name: tools + mountPath: /tools + # Run the actual BATS tests + containers: + - name: st2tests + image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) $ }}' + imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- with .Values.securityContext }} + securityContext: {{- toYaml . | nindent 12 }} + {{- end }} + envFrom: + - configMapRef: + name: {{ .Release.Name }}-st2-urls + - secretRef: + name: {{ include "stackstorm-ha.secrets.st2Auth" . }} + env: + - name: BATS_HELPERS_DIR + value: /tools + - name: ST2_VERSION + value: "{{ .Values.image.tag }}" + - name: ST2_RBAC_ENABLED + value: "{{ .Values.st2.rbac.enabled }}" + volumeMounts: + - name: tools + mountPath: /tools + - name: tests + mountPath: /tests + command: + - /tools/bats/bin/bats + - /tests/st2tests.sh + volumes: + - name: tools + emptyDir: {} + - name: tests + configMap: + name: {{ .Release.Name }}-job-st2-tests + restartPolicy: Never + backoffLimit: 0 diff --git a/templates/tests/st2tests-pod.yaml b/templates/tests/st2tests-pod.yaml deleted file mode 100644 index 5c7ed8c9..00000000 --- a/templates/tests/st2tests-pod.yaml +++ /dev/null @@ -1,68 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: "{{ .Release.Name }}-st2tests" - labels: {{- include "stackstorm-ha.labels" (list $ "st2tests") | nindent 4 }} - annotations: - "helm.sh/hook": test-success - "helm.sh/hook-delete-policy": hook-succeeded -spec: - initContainers: - # Sidecar container to copy BATS framework to the main container - - name: bats-core - image: bats/bats:1.8.2 - command: - - bash - - -ec - - | - cp -R /opt/bats /tools/ - volumeMounts: - - name: tools - mountPath: /tools - - name: bats-addons - image: alpine/git:2.36.3 - command: - - ash - - -ec - - | - git clone --config advice.detachedHead=false --depth 1 --branch v0.3.0 \ - https://github.com/ztombol/bats-assert /tools/bats-assert - git clone --config advice.detachedHead=false --depth 1 --branch v0.2.0 \ - https://github.com/ztombol/bats-file /tools/bats-file - git clone --config advice.detachedHead=false --depth 1 --branch v0.3.0 \ - https://github.com/ztombol/bats-support /tools/bats-support - volumeMounts: - - name: tools - mountPath: /tools - # Run the actual BATS tests - containers: - - name: st2tests - image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ .Chart.AppVersion }}' - imagePullPolicy: {{ .Values.image.pullPolicy }} - envFrom: - - configMapRef: - name: {{ .Release.Name }}-st2-urls - - secretRef: - name: {{ include "stackstorm-ha.secrets.st2Auth" . }} - env: - - name: BATS_HELPERS_DIR - value: /tools - - name: ST2_VERSION - value: "{{ .Chart.AppVersion }}" - - name: ST2_RBAC_ENABLED - value: "{{ .Values.st2.rbac.enabled }}" - volumeMounts: - - name: tools - mountPath: /tools - - name: tests - mountPath: /tests - command: - - /tools/bats/bin/bats - - /tests/st2tests.sh - volumes: - - name: tools - emptyDir: {} - - name: tests - configMap: - name: {{ .Release.Name }}-st2tests - restartPolicy: Never