Reader small image

You're reading from  Learn Helm

Product typeBook
Published inJun 2020
PublisherPackt
ISBN-139781839214295
Edition1st Edition
Right arrow
Authors (2):
Andrew Block
Andrew Block
author image
Andrew Block

Andrew Block is a core maintainer on the Helm project and a Distinguished Architect at Red Hat. He specializes in the use of continuous integration and continuous delivery methodologies to streamline the delivery process and incorporate security at each stage. He works with organizations to adopt and implement these technologies and concepts within their organization. As an open source enthusiast, Andrew not only has authored several publications, but he is also a contributor to several open source communities and a lead within the sigstore project, which aims at simplifying how software is signed and verified.
Read more about Andrew Block

Austin Dewey
Austin Dewey
author image
Austin Dewey

Austin Dewey is a DevOps engineer focused on delivering a streamlined developer experience on cloud and container technologies. Austin started his career with Red Hat's consulting organization, where he helped drive success at Fortune 500 companies by automating deployments on Red Hat's Kubernetes-based PaaS, OpenShift Container Platform. Currently, Austin works at fintech start-up Prime Trust, where he builds automation to scale financial infrastructure and supports developers on Kubernetes and AWS.
Read more about Austin Dewey

View More author details
Right arrow

Chapter 6: Testing Helm Charts

Testing is a common task that engineers must perform during software development. Testing is performed to validate the functionality of a product as well as to prevent regressions as a product evolves over time. Well-tested software is easier to maintain over time and allows developers to more confidently provide new releases to end users.

A Helm chart should be properly tested in order to ensure that it delivers its features to the level of quality expected. In this chapter, we will discuss the ways that robust Helm chart testing can be achieved, including the following topics:

  • Setting up your environment
  • Verifying Helm templating
  • Testing in a live cluster
  • Improving chart tests with the chart testing project
  • Cleaning up

Technical requirements

This chapter will use the following technologies:

  • minikube
  • kubectl
  • helm
  • git
  • yamllint
  • yamale
  • chart-testing (ct)

In addition to these tools, you can follow along with the samples in the Packt GitHub repository located at https://github.com/PacktPublishing/-Learn-Helm, which will be referenced throughout this chapter. In many of the example commands used throughout this chapter, we will reference the Packt repository, so you may find it helpful to clone this repository by running the git clone command:

$ git clone https://github.com/PacktPublishing/-Learn-Helm Learn-Helm

Now, let's proceed with setting up your local minikube environment.

Setting up your environment

In this chapter, we will create and run a series of tests for the Guestbook chart created in the previous chapter. Run the following steps to set up your minikube environment, where we will test the Guestbook chart:

  1. Start minikube by running the minikube start command:
    minikube start
  2. Then, create a new namespace called chapter6:
    kubectl create namespace chapter6

With your minikube environment ready, let's begin by discussing how Helm charts can be tested. We will begin the discussion by outlining the methods you can use to verify your Helm templates.

Verifying Helm templating

In the previous chapter, we built a Helm chart from scratch. The final product was quite complex, containing parameterization, conditional templating, and life cycle hooks. Since one of the primary purposes of Helm is to create Kubernetes resources, you should ensure that your resource templates are generated properly before they are applied to a Kubernetes cluster. This can be done in a variety of ways, which we will discuss in the following section.

Validating template generation locally with helm template

The first way to validate your chart's templating is to use the helm template command, which can be used to render a chart template locally and display its fully rendered contents in the standard output.

The helm template command has the following syntax:

$ helm template [NAME] [CHART] [flags]

This command renders a template locally, using the NAME argument to satisfy the .Release built-in object and the CHART argument for the chart...

Testing in a live cluster

Creating chart tests is an important part of developing and maintaining your Helm charts. Chart tests help verify that your chart is functioning as intended and they can help prevent regressions as features and fixes to your chart are added.

Testing consists of two different steps. First, you need to create pod templates under your chart's templates/ directory that contain the helm.sh/hook: test annotation. These pods will run commands that test the functionality of your chart and application. Next, you need to run the helm test command, which initiates a test hook and creates resources with the aforementioned annotation.

In this section, we will learn how to test in a live cluster by adding tests to the Guestbook chart, continuing the development of the chart you created in the previous chapter. As a reference, the tests that you will create can be viewed in the Guestbook chart in the Packt repository, located at https://github.com/PacktPublishing...

Improving chart tests with the chart testing project

The tests written in the previous section are sufficient enough to test whether the Guestbook application can be successfully installed. However, there are some key limitations that are inherent to the standard Helm testing process that need to be called out.

The first limitation to consider is the difficulty of testing the different permutations that can occur within a chart's values. Because the helm test command does not provide the ability to modify your release's values beyond those set at the time of an installation or upgrade, the following workflow must be followed when running helm test against different values settings:

  1. Install your chart with an initial set of values.
  2. Run helm test against your release.
  3. Delete your release.
  4. Install your chart with a different set of values.
  5. Repeat steps 2 through 4 until a significant amount of value possibilities are tested.

In addition to...

Cleaning up

If you are finished with the examples described in this chapter, you can remove the chapter6 namespace from your minikube cluster:

$ kubectl delete ns chapter6

Finally, shut down your minikube cluster by running minikube stop.

Summary

In this chapter, you learned about the different methods you can apply to test your Helm charts. The most basic way of testing a chart is to run the helm template command against a local chart directory to determine whether its resources are properly generated. You can also use the helm lint command to ensure that your chart follows the correct format and you can use the yamllint command to lint the YAML style used in your chart.

Apart from local templating and linting, you can also perform live tests on a Kubernetes environment with the helm test command and the ct tool. In addition to performing chart tests, chart testing also provides capabilities that make it easier for chart developers to maintain Helm charts in a monorepo.

In the next chapter, you will learn how Helm can be used in a Continuous Integration/Continuous Delivery (CI/CD) and GitOps setting, from both the perspective of a chart developer that is building and testing Helm charts and from the perspective...

Further reading

For additional information on the helm template and helm lint commands, please refer to the following resources:

The following pages from the Helm documentation discuss chart tests and the helm test command:

Questions

  1. What is the purpose of the helm template command? How does it differ from the helm lint command?
  2. What can you do to validate your chart templates before installing them in Kubernetes?
  3. What tool can be leveraged to lint the style of your YAML resources?
  4. How is a chart test created? How is a chart test executed?
  5. What additional value does the ct tool bring to Helm's built-in testing capabilities?
  6. What is the purpose of the ci/ folder when used with the ct tool?
  7. How does the --upgrade flag change the behavior of the ct lint-and-install command?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Helm
Published in: Jun 2020Publisher: PacktISBN-13: 9781839214295
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Authors (2)

author image
Andrew Block

Andrew Block is a core maintainer on the Helm project and a Distinguished Architect at Red Hat. He specializes in the use of continuous integration and continuous delivery methodologies to streamline the delivery process and incorporate security at each stage. He works with organizations to adopt and implement these technologies and concepts within their organization. As an open source enthusiast, Andrew not only has authored several publications, but he is also a contributor to several open source communities and a lead within the sigstore project, which aims at simplifying how software is signed and verified.
Read more about Andrew Block

author image
Austin Dewey

Austin Dewey is a DevOps engineer focused on delivering a streamlined developer experience on cloud and container technologies. Austin started his career with Red Hat's consulting organization, where he helped drive success at Fortune 500 companies by automating deployments on Red Hat's Kubernetes-based PaaS, OpenShift Container Platform. Currently, Austin works at fintech start-up Prime Trust, where he builds automation to scale financial infrastructure and supports developers on Kubernetes and AWS.
Read more about Austin Dewey