top of page
Writer's pictureAna Maria Mihalceanu

Smoke Testing for Kubernetes with Helm Charts

Helm, the Kubernetes package manager, allows you to deploy applications and their dependencies as templates using a single command: helm install. Smoke tests are a native feature of helm known via "test hooks" and in this article, we will explore it by example.


smoke

Helm Charts are written using go templates to render YAML, which sometimes can lead to a frustrating experience. Mixing go template with YAML makes syntax highlighting a hard chore for IDEs, and confusing error messages can contribute to painful experiences while developing charts.

The first step to guard ourselves against errors in chart installation is to add a JSON schema for the different values files. You can determine incompatible values for the created charts when invoking the following commands and add --dry-run to each of them if you want to avoid resource creation:

  • helm install

  • helm upgrade

  • helm template

  • helm lint

When you create your charts via helm create command, a test-connection.yaml the file is generated. You can modify and use this file for smoke testing. Smoke testing is a subset of software testing that helps teams verify whether a version of a deployed software is stable or not.

Smoke testing can play an important role in the continuous delivery lifecycle as it ensures the system's correctness in the initial stages. Typically, once smoke testing runs successfully, functional testing can start.

Let's look at the following scenario that can be used for smoke testing: your application contains different versions of an endpoint. A certain proportion of consumers is using either version.


Assuming that version 2 is used by 95% of your users, you can create a smoke test that checks its functionality:

You may notice that I decided to fulfill the path to check from values.yaml, via

{{ .Values.service.controlPath.success }} . However, a good practice is to run these smoke tests and employ a delete policy, meaning to clean up the Kubernetes resources that have scope test:

  • add "helm.sh/hook-delete-policy": before-hook-creation to instruct Helm to delete any previous test resource.

  • add "helm.sh/hook-delete-policy": hook-succeeded to instruct Helm that it should delete the test resource upon running it successfully.

Since both endpoint versions are used, it would be great to have a smoke test for both, and I created a new test file:

When creating multiple tests, please add a "helm.sh/hook-weight" to each test to establish an order for running them. Finally, helm test $RELEASE_NAME to execute the test suite, $RELEASE_NAME an environment variable can be defined as a pipeline parameter.

You can find sample Helm charts with validation and tests at https://github.com/ammbra/helm-smoke-tests.

2,067 views0 comments

Comments


bottom of page