From b96c9fe8975c6f7a1a8af66a4f23c379e0ff37b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Tue, 5 Apr 2022 11:40:06 +0200 Subject: [PATCH] Rebase on top of upstream/main and squash Red Hat/Openshift downstream commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -update pip to pip3 -run openshift tests -Fix test data deployment version -Install PV before test setup and fix deamon set tests -Add helm dir in .acceptance -Change to use current helm bin -Disable test for version greater than 3.1 -Create blank.yml -Enable tests related to Helm 3.2 bin. (#2) -Add openshift cluster provider (#6) * Run acceptance tests against provided k8s cluster * Add openshift cluster provider -Fix kubeVersion to support kube pre-releases (https://github.com/helm/helm/issues/6190) (#9) -Remove obsolete and redundand test cases from kubernetes_versions.robot (#12) -Adjust completion test according to helm 3.4 flags (#11) -Fixes the completion tests failure by adjusting tests according to new changes flags changes in helm 3.4. Co-authored-by: Akash Shinde Signed-off-by: Pavel MacĂ­k --- .github/workflows/blank.yml | 22 +++ Makefile | 2 +- lib/Helm.py | 14 +- lib/Kubectl.py | 7 +- scripts/acceptance.sh | 4 +- .../openshift_cleanup_all_test_clusters | 3 + .../openshift_create_cluster | 23 +++ .../openshift_delete_cluster | 5 + .../openshift_get_cluster_auth | 3 + .../openshift_wait_for_cluster | 3 + scripts/completion-tests/test-completion.sh | 2 +- scripts/ensure-cluster-setup.sh | 36 ++++ testdata/charts/nginx/Chart.yaml | 2 +- .../charts/nginx/templates/deployment.yaml | 6 +- testdata/charts/openshift-nginx/.helmignore | 5 + testdata/charts/openshift-nginx/Chart.yaml | 14 ++ .../openshift-nginx/templates/NOTES.txt | 1 + .../openshift-nginx/templates/_helpers.tpl | 16 ++ .../openshift-nginx/templates/deployment.yaml | 154 ++++++++++++++++++ .../charts/openshift-nginx/templates/ds.yaml | 35 ++++ .../charts/openshift-nginx/templates/pvc.yaml | 13 ++ .../openshift-nginx/templates/service.yaml | 39 +++++ .../templates/statefulset.yaml | 32 ++++ testdata/charts/openshift-nginx/values.yaml | 18 ++ testsuites/kubernetes_versions.robot | 8 +- 25 files changed, 450 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/blank.yml create mode 100755 scripts/cluster_providers/openshift_cleanup_all_test_clusters create mode 100755 scripts/cluster_providers/openshift_create_cluster create mode 100755 scripts/cluster_providers/openshift_delete_cluster create mode 100755 scripts/cluster_providers/openshift_get_cluster_auth create mode 100755 scripts/cluster_providers/openshift_wait_for_cluster create mode 100755 scripts/ensure-cluster-setup.sh create mode 100755 testdata/charts/openshift-nginx/.helmignore create mode 100755 testdata/charts/openshift-nginx/Chart.yaml create mode 100755 testdata/charts/openshift-nginx/templates/NOTES.txt create mode 100755 testdata/charts/openshift-nginx/templates/_helpers.tpl create mode 100755 testdata/charts/openshift-nginx/templates/deployment.yaml create mode 100755 testdata/charts/openshift-nginx/templates/ds.yaml create mode 100755 testdata/charts/openshift-nginx/templates/pvc.yaml create mode 100755 testdata/charts/openshift-nginx/templates/service.yaml create mode 100755 testdata/charts/openshift-nginx/templates/statefulset.yaml create mode 100755 testdata/charts/openshift-nginx/values.yaml diff --git a/.github/workflows/blank.yml b/.github/workflows/blank.yml new file mode 100644 index 0000000..44e7530 --- /dev/null +++ b/.github/workflows/blank.yml @@ -0,0 +1,22 @@ +name: acceptance-tests + +on: + push: + branches: + - master +jobs: + run: + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v1 + + - name: Run acceptance tests + run: make github-actions-ci + + - uses: actions/upload-artifact@master + name: Upload test report + with: + name: helm-acceptance-testing-report-${{ github.sha }} + path: acceptance-testing-reports/${{ github.sha }}/ + if: always() diff --git a/Makefile b/Makefile index e175d6b..8284ce6 100644 --- a/Makefile +++ b/Makefile @@ -15,4 +15,4 @@ github-actions-ci-local: -w /tmp/acceptance-testing \ --privileged -v /var/run/docker.sock:/var/run/docker.sock \ --entrypoint=/bin/bash ubuntu:latest \ - -c 'set +e; scripts/github-actions-ci.sh; echo "Exited $?. (Ctrl+D to exit shell)"; bash' \ No newline at end of file + -c 'set +e; scripts/github-actions-ci.sh; echo "Exited $?. (Ctrl+D to exit shell)"; bash' diff --git a/lib/Helm.py b/lib/Helm.py index ddc98f2..64e2355 100644 --- a/lib/Helm.py +++ b/lib/Helm.py @@ -2,10 +2,18 @@ import common from ClusterProvider import auth_wrap -TEST_CHARTS_ROOT_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) +'/../testdata/charts') +TEST_CHARTS_ROOT_DIR = os.path.abspath(os.path.dirname( + os.path.realpath(__file__)) + '/../testdata/charts') + class Helm(common.CommandRunner): + def get_chart_path(self, test_chart): + provider = os.getenv("CLUSTER_PROVIDER", default='') + if provider == '': + return test_chart + return f'{TEST_CHARTS_ROOT_DIR}/{provider}-{test_chart}' + def install_test_chart(self, release_name, test_chart, extra_args): - chart_path = TEST_CHARTS_ROOT_DIR+'/'+test_chart - cmd = 'helm install '+release_name+' '+chart_path+' '+extra_args + cmd = 'helm install '+release_name+' ' + \ + self.get_chart_path(test_chart) + ' '+extra_args self.run_command(auth_wrap(cmd)) diff --git a/lib/Kubectl.py b/lib/Kubectl.py index d777c9d..9997bcf 100644 --- a/lib/Kubectl.py +++ b/lib/Kubectl.py @@ -18,7 +18,10 @@ def persistent_volume_claim_is_bound(self, namespace, pvc_name): def pods_with_prefix_are_running(self, namespace, pod_prefix, num_expected): cmd = '[ `kubectl get pods --namespace='+namespace cmd += ' | grep ^'+pod_prefix+' | awk \'{print $2 "--" $3}\'' - cmd += ' | grep -E "^([1-9][0-9]*)/\\1--Running" | wc -l` == ' + \ - num_expected+' ]' + cmd += ' | grep -E "^([1-9][0-9]*)/\\1--Running" | wc -l` == '+num_expected+' ]' self.run_command(auth_wrap(cmd)) + def deamon_set_pods_with_prefix(self, namespace, pod_prefix): + cmd = 'kubectl get nodes | grep Ready | wc -l' + self.run_command(auth_wrap(cmd)) + self.pods_with_prefix_are_running(namespace, pod_prefix, self.stdout) diff --git a/scripts/acceptance.sh b/scripts/acceptance.sh index 02cfbae..b8a5d7e 100755 --- a/scripts/acceptance.sh +++ b/scripts/acceptance.sh @@ -36,7 +36,7 @@ set_shell_debug_level 2 REQUIRED_SYSTEM_COMMANDS=( "kubectl" "python3" - "pip" + "pip3" "virtualenv" ) @@ -133,7 +133,7 @@ fi set_shell_debug_level 2 if [[ ! -d ${ROBOT_VENV_DIR} ]]; then virtualenv -p $(which python3) ${ROBOT_VENV_DIR} - pip install ${ROBOT_PY_REQUIRES} + pip3 install ${ROBOT_PY_REQUIRES} fi # Run Robot Framework, output diff --git a/scripts/cluster_providers/openshift_cleanup_all_test_clusters b/scripts/cluster_providers/openshift_cleanup_all_test_clusters new file mode 100755 index 0000000..ade4cb6 --- /dev/null +++ b/scripts/cluster_providers/openshift_cleanup_all_test_clusters @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "No need to cleanup cluster" diff --git a/scripts/cluster_providers/openshift_create_cluster b/scripts/cluster_providers/openshift_create_cluster new file mode 100755 index 0000000..bd46912 --- /dev/null +++ b/scripts/cluster_providers/openshift_create_cluster @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "No need to create cluster" +export KUBECONFIG=$2 +cat <=1.2.0' +kubeVersion: '>=1.2.0-0' maintainers: [] name: nginx sources: diff --git a/testdata/charts/nginx/templates/deployment.yaml b/testdata/charts/nginx/templates/deployment.yaml index 1992310..276d494 100755 --- a/testdata/charts/nginx/templates/deployment.yaml +++ b/testdata/charts/nginx/templates/deployment.yaml @@ -1,4 +1,4 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "nginx.fullname" . }}-ext @@ -37,7 +37,7 @@ spec: - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "nginx.fullname" . }}-v1beta1 @@ -76,7 +76,7 @@ spec: - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" --- -apiVersion: apps/v1beta2 +apiVersion: apps/v1 kind: Deployment metadata: name: {{ template "nginx.fullname" . }}-v1beta2 diff --git a/testdata/charts/openshift-nginx/.helmignore b/testdata/charts/openshift-nginx/.helmignore new file mode 100755 index 0000000..435b756 --- /dev/null +++ b/testdata/charts/openshift-nginx/.helmignore @@ -0,0 +1,5 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +.git diff --git a/testdata/charts/openshift-nginx/Chart.yaml b/testdata/charts/openshift-nginx/Chart.yaml new file mode 100755 index 0000000..34fcb5e --- /dev/null +++ b/testdata/charts/openshift-nginx/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +description: A basic NGINX HTTP server +home: https://github.com/helm/helm +keywords: +- http +- nginx +- www +- web +kubeVersion: '>=1.2.0-0' +maintainers: [] +name: nginx +sources: +- https://hub.docker.com/_/nginx/ +version: 0.1.0 diff --git a/testdata/charts/openshift-nginx/templates/NOTES.txt b/testdata/charts/openshift-nginx/templates/NOTES.txt new file mode 100755 index 0000000..4bdf443 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/NOTES.txt @@ -0,0 +1 @@ +Sample notes for {{ .Chart.Name }} \ No newline at end of file diff --git a/testdata/charts/openshift-nginx/templates/_helpers.tpl b/testdata/charts/openshift-nginx/templates/_helpers.tpl new file mode 100755 index 0000000..2ec6ba7 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "nginx.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "nginx.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/testdata/charts/openshift-nginx/templates/deployment.yaml b/testdata/charts/openshift-nginx/templates/deployment.yaml new file mode 100755 index 0000000..276d494 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/deployment.yaml @@ -0,0 +1,154 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "nginx.fullname" . }}-ext + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/name: {{ template "nginx.name" . }}-ext +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-ext + template: + metadata: + labels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-ext + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "nginx.fullname" . }}-v1beta1 + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta1 +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta1 + template: + metadata: + labels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta1 + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "nginx.fullname" . }}-v1beta2 + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta2 +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta2 + template: + metadata: + labels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1beta2 + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "nginx.fullname" . }}-v1 + labels: + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1 +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1 + template: + metadata: + labels: + app.kubernetes.io/name: {{ template "nginx.name" . }}-v1 + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" diff --git a/testdata/charts/openshift-nginx/templates/ds.yaml b/testdata/charts/openshift-nginx/templates/ds.yaml new file mode 100755 index 0000000..6788785 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/ds.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ template "nginx.fullname" . }}-fluentd-es + labels: + k8s-app: fluentd-logging +spec: + selector: + matchLabels: + name: fluentd-elasticsearch + template: + metadata: + labels: + name: fluentd-elasticsearch + spec: + tolerations: + - key: node-role.kubernetes.io/master + effect: NoSchedule + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" diff --git a/testdata/charts/openshift-nginx/templates/pvc.yaml b/testdata/charts/openshift-nginx/templates/pvc.yaml new file mode 100755 index 0000000..37a58ed --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/pvc.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ template "nginx.fullname" . }} +spec: + accessModes: + - ReadWriteOnce + volumeMode: Filesystem + resources: + requests: + storage: 8Gi + # Change this to a non-existent name to force it to never provision + storageClassName: "{{ if .Values.breakme }}nonexistant{{ else }}standard{{ end }}" diff --git a/testdata/charts/openshift-nginx/templates/service.yaml b/testdata/charts/openshift-nginx/templates/service.yaml new file mode 100755 index 0000000..03f7aa2 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/service.yaml @@ -0,0 +1,39 @@ +apiVersion: v1 +kind: Service +metadata: +{{- if .Values.service.annotations }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +{{- end }} + labels: + app.kubernetes.io/name: {{ template "nginx.name" . }} + helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + app.kubernetes.io/instance: {{ .Release.Name }} + name: {{ template "nginx.fullname" . }} +spec: +# Provides options for the service so chart users have the full choice + type: "{{ .Values.service.type }}" + clusterIP: "{{ .Values.service.clusterIP }}" +{{- if .Values.service.externalIPs }} + externalIPs: +{{ toYaml .Values.service.externalIPs | indent 4 }} +{{- end }} +{{- if .Values.service.loadBalancerIP }} + loadBalancerIP: "{{ .Values.service.loadBalancerIP }}" +{{- end }} +{{- if .Values.service.loadBalancerSourceRanges }} + loadBalancerSourceRanges: +{{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }} +{{- end }} + ports: + - name: http + port: {{ .Values.service.port }} + protocol: TCP + targetPort: http + {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }} + nodePort: {{ .Values.service.nodePort }} + {{- end }} + selector: + app.kubernetes.io/name: {{ template "nginx.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/testdata/charts/openshift-nginx/templates/statefulset.yaml b/testdata/charts/openshift-nginx/templates/statefulset.yaml new file mode 100755 index 0000000..2f027c5 --- /dev/null +++ b/testdata/charts/openshift-nginx/templates/statefulset.yaml @@ -0,0 +1,32 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ template "nginx.fullname" . }}-web +spec: + selector: + matchLabels: + app: foobar # has to match .spec.template.metadata.labels + serviceName: "nginx" + replicas: 3 # by default is 1 + template: + metadata: + labels: + app: foobar # has to match .spec.selector.matchLabels + spec: + containers: + - name: {{ template "nginx.name" . }} + image: "alpine:latest" + imagePullPolicy: {{ .Values.image.pullPolicy }} + command: + - sleep + - "50000" + ports: + - name: http + containerPort: 80 + protocol: TCP + readinessProbe: + exec: + command: + - sh + - "-c" + - "echo bar | grep {{ if .Values.breakme }}foo{{ else }}bar{{ end }}" diff --git a/testdata/charts/openshift-nginx/values.yaml b/testdata/charts/openshift-nginx/values.yaml new file mode 100755 index 0000000..31d290c --- /dev/null +++ b/testdata/charts/openshift-nginx/values.yaml @@ -0,0 +1,18 @@ +# Uncomment/set this in order to cause deployment readiness probes to fail +# +# breakme: true +# + +image: + pullPolicy: IfNotPresent +replicaCount: 3 +restartPolicy: Never +service: + annotations: {} + clusterIP: "" + externalIPs: [] + loadBalancerIP: "" + loadBalancerSourceRanges: [] + nodePort: "" + port: 8888 + type: ClusterIP diff --git a/testsuites/kubernetes_versions.robot b/testsuites/kubernetes_versions.robot index 7645866..7c8514a 100644 --- a/testsuites/kubernetes_versions.robot +++ b/testsuites/kubernetes_versions.robot @@ -31,7 +31,7 @@ Library ../lib/ClusterProvider.py Library ../lib/Kubectl.py Library ../lib/Helm.py Library ../lib/Sh.py -Suite Setup Suite Setup +#Suite Setup Suite Setup Suite Teardown Suite Teardown @@ -73,7 +73,7 @@ Create test cluster with kube version Verify --wait flag works as expected # Install nginx chart in a good state, using --wait flag - Sh.Run helm delete wait-flag-good +# Sh.Run helm delete wait-flag-good Helm.Install test chart wait-flag-good nginx --wait --timeout=60s Helm.Return code should be 0 @@ -90,7 +90,7 @@ Verify --wait flag works as expected Kubectl.Pods with prefix are running default wait-flag-good-nginx-ext- 3 Kubectl.Return code should be 0 - Kubectl.Pods with prefix are running default wait-flag-good-nginx-fluentd-es- 1 + Kubectl.Deamon Set Pods With Prefix default wait-flag-good-nginx-fluentd-es- Kubectl.Return code should be 0 Kubectl.Pods with prefix are running default wait-flag-good-nginx-v1- 3 Kubectl.Return code should be 0 @@ -121,7 +121,7 @@ Verify --wait flag works as expected Kubectl.Pods with prefix are running default wait-flag-bad-nginx-ext- 3 Kubectl.Return code should not be 0 - Kubectl.Pods with prefix are running default wait-flag-bad-nginx-fluentd-es- 1 + Kubectl.Deamon Set Pods With Prefix default wait-flag-bad-nginx-fluentd-es- Kubectl.Return code should not be 0 Kubectl.Pods with prefix are running default wait-flag-bad-nginx-v1- 3 Kubectl.Return code should not be 0