helm test test details

1. Introduction

The test templates / in helm chart is located in this directory and is a job definition that specifies the container with the given command to run. The container should exit successfully (exit 0), and the test is considered successful. Job definition: Helm sh/hook: test.

Note that before Helm v3, the job definition needs to include one of the following helm test hook comments: helm SH / hook: test success or helm sh/hook: test-failure. helm.sh/hook: test success is still accepted as a backward compatible alternative to helm sh/hook: test.

Example test:

  • Verify values Whether the configuration in yaml file has been injected correctly.
  • Make sure your user name and password are used correctly
  • Make sure that incorrect user names and passwords do not work
  • Assert that your service is started and properly load balanced
  • wait.

You can use the command to run the predefined test Helm test < release in Helm_ NAME>. For chart users, this is a good way to check that the chart (or application) they publish works as expected.

2. demo

This is bitnami wordpress Example of helm test pod definition in the chart. If you download a copy of the chart, you can view the file locally:

$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm pull bitnami/wordpress --untar
wordpress/
  Chart.yaml
  README.md
  values.yaml
  charts/
  templates/
  templates/tests/test-mariadb-connection.yaml

In WordPress / templates / tests / test MariaDB connection In yaml, you will see a test you can try:

{{- if .Values.mariadb.enabled }}
apiVersion: v1
kind: Pod
metadata:
  name: "{{ .Release.Name }}-credentials-test"
  annotations:
    "helm.sh/hook": test
spec:
  containers:
    - name: {{ .Release.Name }}-credentials-test
      image: {{ template "wordpress.image" . }}
      imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        runAsUser: {{ .Values.securityContext.runAsUser }}
      {{- end }}
      env:
        - name: MARIADB_HOST
          value: {{ template "mariadb.fullname" . }}
        - name: MARIADB_PORT
          value: "3306"
        - name: WORDPRESS_DATABASE_NAME
          value: {{ default "" .Values.mariadb.db.name | quote }}
        - name: WORDPRESS_DATABASE_USER
          value: {{ default "" .Values.mariadb.db.user | quote }}
        - name: WORDPRESS_DATABASE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: {{ template "mariadb.fullname" . }}
              key: mariadb-password
      command:
        - /bin/bash
        - -ec
        - |
                    mysql --host=$MARIADB_HOST --port=$MARIADB_PORT --user=$WORDPRESS_DATABASE_USER --password=$WORDPRESS_DATABASE_PASSWORD
  restartPolicy: Never
{{- end }}

To run a test suite on a version
First, install the chart on the cluster to create the publication. You may have to wait until all pod s are activated; If you test immediately after this installation, a delivery failure may be displayed and you will need to retest.

$ helm install quirky-walrus wordpress --namespace default
$ helm test quirky-walrus
Pod quirky-walrus-credentials-test pending
Pod quirky-walrus-credentials-test pending
Pod quirky-walrus-credentials-test pending
Pod quirky-walrus-credentials-test succeeded
Pod quirky-walrus-mariadb-test-dqas5 pending
Pod quirky-walrus-mariadb-test-dqas5 pending
Pod quirky-walrus-mariadb-test-dqas5 pending
Pod quirky-walrus-mariadb-test-dqas5 pending
Pod quirky-walrus-mariadb-test-dqas5 succeeded
NAME: quirky-walrus
LAST DEPLOYED: Mon Jun 22 17:24:31 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE:     quirky-walrus-mariadb-test-dqas5
Last Started:   Mon Jun 22 17:27:19 2020
Last Completed: Mon Jun 22 17:27:21 2020
Phase:          Succeeded
TEST SUITE:     quirky-walrus-credentials-test
Last Started:   Mon Jun 22 17:27:17 2020
Last Completed: Mon Jun 22 17:27:19 2020
Phase:          Succeeded
[...]
  • You can define any number of tests in a single yaml file or distribute them in multiple yaml files in the templates / directory.
  • Your test suite is nested under tests / similar directories to achieve more isolation with < chart name > / templates / tests /.
  • A test is a Helm
    Hook, so annotations can be used with test resources sh/hook-weight. helm.sh/hook-delete-policy

Keywords: Linux Kubernetes helm

Added by binto on Thu, 10 Mar 2022 11:24:07 +0200