From bba407232df8a9584a72c221e5b378475ff0c167 Mon Sep 17 00:00:00 2001 From: Ievgenii Shepeliuk Date: Wed, 3 Mar 2021 14:55:45 +0200 Subject: [PATCH] feat: e2e tests with helm and k3d --- .github/workflows/master.yaml | 25 +++++++++----- Dockerfile | 6 ++-- e2e.sh | 16 --------- skaffold.yaml | 21 ++++++++---- .../{cronjob.yaml => cronjob-reconcile.yaml} | 2 +- templates/job-setup.yaml | 33 +++++++++++++++++++ templates/tests/values-clusters.yaml | 23 +++++++++++++ test/e2e/values-e2e.yaml | 9 +++++ .../linter}/subchart/.gitignore | 0 .../linter}/subchart/.helmignore | 0 .../linter}/subchart/Chart.yaml | 2 +- .../linter}/subchart/templates/test.yaml | 0 .../linter}/subchart/values.schema.json | 0 .../linter}/subchart/values.yaml | 4 +++ {test-linter => test/linter}/values-lint.yaml | 0 values.schema.json | 2 +- values.yaml | 2 +- 17 files changed, 108 insertions(+), 37 deletions(-) delete mode 100755 e2e.sh rename templates/{cronjob.yaml => cronjob-reconcile.yaml} (98%) create mode 100644 templates/job-setup.yaml create mode 100644 templates/tests/values-clusters.yaml create mode 100644 test/e2e/values-e2e.yaml rename {test-linter => test/linter}/subchart/.gitignore (100%) rename {test-linter => test/linter}/subchart/.helmignore (100%) rename {test-linter => test/linter}/subchart/Chart.yaml (81%) rename {test-linter => test/linter}/subchart/templates/test.yaml (100%) rename {test-linter => test/linter}/subchart/values.schema.json (100%) rename {test-linter => test/linter}/subchart/values.yaml (70%) rename {test-linter => test/linter}/values-lint.yaml (100%) diff --git a/.github/workflows/master.yaml b/.github/workflows/master.yaml index 4aea378..0a664e9 100644 --- a/.github/workflows/master.yaml +++ b/.github/workflows/master.yaml @@ -21,21 +21,30 @@ jobs: - name: helm lint run: | helm lint . --strict - helm lint . --strict -f test-linter/values-lint.yaml - helm dep up test-linter/subchart && helm lint test-linter/subchart --strict + helm lint . --strict -f test/linter/values-lint.yaml + helm dep up test/linter/subchart && helm lint test/linter/subchart --strict - uses: volesen/setup-skaffold@v1.1 with: version: 'v1.20.0' - - run: | - skaffold version - - uses: AbsaOSS/k3d-action@v1.2.0 - name: create cluster + - name: start k8s with k3d + uses: AbsaOSS/k3d-action@v1.3.1 with: cluster-name: "cmak" use-default-registry: true args: >- --config ./k3d.yaml + - name: build cmak-operator + run: | + skaffold config set default-repo "registry.localhost:5000" + skaffold build + - name: deploy cmak-operator + run: | + set -x + set -e + skaffold config set default-repo "registry.localhost:5000" + skaffold run -p e2e - name: e2e test run: | - sleep 20 - ./e2e.sh + set -x + set -e + helm test cmak-operator --logs diff --git a/Dockerfile b/Dockerfile index ac0bd2e..48890ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ -FROM python:3.8-alpine3.11 +FROM python:3.8-alpine3.12 COPY *.py /opt/ -RUN pip install click~=7.0 kazoo~=2.8 +RUN set -x && \ + apk add --update --no-cache jq curl && \ + pip install click~=7.0 kazoo~=2.8 WORKDIR /opt diff --git a/e2e.sh b/e2e.sh deleted file mode 100755 index e344b21..0000000 --- a/e2e.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -set -x -set -e - -REGISTRY='registry.localhost' -if [ -z $CI ];then - REGISTRY='192.168.99.103' -fi - -skaffold config set default-repo "${REGISTRY}:5000" -touch values-dev.yaml -skaffold run - -[ "$(helm ls --deployed -q | wc -l)" -eq 1 ] - -kubectl get all diff --git a/skaffold.yaml b/skaffold.yaml index 23e126d..eca546f 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -12,6 +12,7 @@ profiles: activation: - command: run - command: dev + - command: delete deploy: helm: releases: @@ -24,10 +25,16 @@ profiles: image: eshepelyuk/json2zk imageStrategy: helm: {} - portForward: - - resourceType: Service - resourceName: cmak - port: 2181 - - resourceType: Service - resourceName: cmak - port: 9000 +- name: e2e + deploy: + helm: + releases: + - name: cmak-operator + chartPath: . + wait: true + valuesFiles: + - test/e2e/values-e2e.yaml + artifactOverrides: + image: eshepelyuk/json2zk + imageStrategy: + helm: {} diff --git a/templates/cronjob.yaml b/templates/cronjob-reconcile.yaml similarity index 98% rename from templates/cronjob.yaml rename to templates/cronjob-reconcile.yaml index 89e6906..eba434b 100644 --- a/templates/cronjob.yaml +++ b/templates/cronjob-reconcile.yaml @@ -4,7 +4,7 @@ apiVersion: batch/v1beta1 kind: CronJob metadata: - name: {{ $nm }}-clusters + name: {{ $nm }}-reconcile labels: {{- include "cmak.labels" . | nindent 4 }} spec: diff --git a/templates/job-setup.yaml b/templates/job-setup.yaml new file mode 100644 index 0000000..9348cae --- /dev/null +++ b/templates/job-setup.yaml @@ -0,0 +1,33 @@ +{{- $nm := include "cmak.name" . -}} +{{- $dict := .Values.image | default (dict "tag" .Chart.Version "repository" (printf "%s/eshepelyuk/json2zk" .Values.imageRegistry)) -}} +{{- $image := printf "%s:%s" $dict.repository $dict.tag -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ $nm }}-setup + labels: + {{- include "cmak.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-delete-policy": hook-succeeded +spec: + backoffLimit: 3 + template: + spec: + restartPolicy: Never + volumes: + - name: {{ $nm }}-clusters + configMap: + name: {{ $nm }}-clusters + containers: + - name: setup + image: {{ $image | quote }} + command: ['python3', './json2zk.py'] + args: + - '{{ .Values.reconcile.overwriteZk | ternary "--" "--no-" }}overwrite-zk' + - '{{ $nm }}.{{ $.Release.Namespace }}:2181' + - '/kafka-manager/configs' + - '/opt/clusters' + volumeMounts: + - name: {{ $nm }}-clusters + mountPath: /opt/clusters diff --git a/templates/tests/values-clusters.yaml b/templates/tests/values-clusters.yaml new file mode 100644 index 0000000..aeb9f9b --- /dev/null +++ b/templates/tests/values-clusters.yaml @@ -0,0 +1,23 @@ +{{- $nm := include "cmak.name" . -}} +{{- $uiUrl := printf "http://%v.%v:%v/api/status/clusters" $nm .Release.Namespace .Values.ui.port -}} +{{- $dict := .Values.image | default (dict "tag" .Chart.Version "repository" (printf "%s/eshepelyuk/json2zk" .Values.imageRegistry)) -}} +{{- $image := printf "%s:%s" $dict.repository $dict.tag -}} +apiVersion: v1 +kind: Pod +metadata: + name: {{ $nm }}-values-clusters + annotations: + "helm.sh/hook": test +spec: + restartPolicy: Never + containers: + - name: values-clusters + image: {{ $image | quote }} + command: + - '/bin/sh' + - '-c' + - | + set -x + set -e + [ "$(curl -s {{ $uiUrl }} | jq '.clusters.active | length')" -eq 2 ] + curl -s {{ $uiUrl }} | jq '.clusters.active[].name' diff --git a/test/e2e/values-e2e.yaml b/test/e2e/values-e2e.yaml new file mode 100644 index 0000000..2e73337 --- /dev/null +++ b/test/e2e/values-e2e.yaml @@ -0,0 +1,9 @@ +cmak: + clusters: + - name: cluster + curatorConfig: + zkConnect: kafka1.local + - name: cluster-disabled + enabled: false + curatorConfig: + zkConnect: kafka2.local diff --git a/test-linter/subchart/.gitignore b/test/linter/subchart/.gitignore similarity index 100% rename from test-linter/subchart/.gitignore rename to test/linter/subchart/.gitignore diff --git a/test-linter/subchart/.helmignore b/test/linter/subchart/.helmignore similarity index 100% rename from test-linter/subchart/.helmignore rename to test/linter/subchart/.helmignore diff --git a/test-linter/subchart/Chart.yaml b/test/linter/subchart/Chart.yaml similarity index 81% rename from test-linter/subchart/Chart.yaml rename to test/linter/subchart/Chart.yaml index 111b8cc..1ff9694 100644 --- a/test-linter/subchart/Chart.yaml +++ b/test/linter/subchart/Chart.yaml @@ -7,4 +7,4 @@ appVersion: 0.0.0 dependencies: - name: cmak-operator version: 0.0.0 - repository: file://../.. + repository: file://../../.. diff --git a/test-linter/subchart/templates/test.yaml b/test/linter/subchart/templates/test.yaml similarity index 100% rename from test-linter/subchart/templates/test.yaml rename to test/linter/subchart/templates/test.yaml diff --git a/test-linter/subchart/values.schema.json b/test/linter/subchart/values.schema.json similarity index 100% rename from test-linter/subchart/values.schema.json rename to test/linter/subchart/values.schema.json diff --git a/test-linter/subchart/values.yaml b/test/linter/subchart/values.yaml similarity index 70% rename from test-linter/subchart/values.yaml rename to test/linter/subchart/values.yaml index bb4c336..af44e20 100644 --- a/test-linter/subchart/values.yaml +++ b/test/linter/subchart/values.yaml @@ -6,3 +6,7 @@ propStr: "true" global: globalStr: "false" + +image: + tag: xxx + repository: yyy diff --git a/test-linter/values-lint.yaml b/test/linter/values-lint.yaml similarity index 100% rename from test-linter/values-lint.yaml rename to test/linter/values-lint.yaml diff --git a/values.schema.json b/values.schema.json index 1331260..1ac9f44 100644 --- a/values.schema.json +++ b/values.schema.json @@ -90,7 +90,7 @@ "required": ["schedule"], "title": "reconciliation job config", "properties": { "schedule": { - "type": "string", "default": "*/2 * * * *", "title": "cron expression for periodic reconciliation" + "type": "string", "default": "*/3 * * * *", "title": "cron expression for periodic reconciliation" }, "overwriteZk": { "type": "boolean", "default": true, "title": "allow overwrite Zookeeper settings of CMAK" diff --git a/values.yaml b/values.yaml index e859353..45b0851 100644 --- a/values.yaml +++ b/values.yaml @@ -44,7 +44,7 @@ cmak: clusters: [] reconcile: - schedule: "*/2 * * * *" + schedule: "*/3 * * * *" overwriteZk: true successfulJobsHistoryLimit: null failedJobsHistoryLimit: null