Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconcharts
file-type-iconexamples
file-type-icontest
file-type-iconfixtures
file-type-iconREADME.md
file-type-icongo.mod
file-type-icongo.sum
file-type-iconk8s_service_canary_deployment_template_tes...
file-type-iconk8s_service_canary_deployment_test.go
file-type-iconk8s_service_config_injection_example_test.go
file-type-iconk8s_service_config_injection_template_test.go
file-type-iconk8s_service_example_test_helpers.go
file-type-iconk8s_service_horizontal_pod_autoscaler_temp...
file-type-iconk8s_service_nginx_example_test.go
file-type-iconk8s_service_service_account_template_test.go
file-type-iconk8s_service_service_monitor_template_test.go
file-type-iconk8s_service_template_render_helpers_for_te...
file-type-iconk8s_service_template_test.go
file-type-iconsample_app_test_helpers.go
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconGRUNTWORK_PHILOSOPHY.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.adoc
file-type-iconcore-concepts.md

Browse the Repo

file-type-icon.circleci
file-type-icon_docs
file-type-iconcharts
file-type-iconexamples
file-type-icontest
file-type-iconfixtures
file-type-iconREADME.md
file-type-icongo.mod
file-type-icongo.sum
file-type-iconk8s_service_canary_deployment_template_tes...
file-type-iconk8s_service_canary_deployment_test.go
file-type-iconk8s_service_config_injection_example_test.go
file-type-iconk8s_service_config_injection_template_test.go
file-type-iconk8s_service_example_test_helpers.go
file-type-iconk8s_service_horizontal_pod_autoscaler_temp...
file-type-iconk8s_service_nginx_example_test.go
file-type-iconk8s_service_service_account_template_test.go
file-type-iconk8s_service_service_monitor_template_test.go
file-type-iconk8s_service_template_render_helpers_for_te...
file-type-iconk8s_service_template_test.go
file-type-iconsample_app_test_helpers.go
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconCONTRIBUTING.md
file-type-iconGRUNTWORK_PHILOSOPHY.md
file-type-iconLICENSE
file-type-iconNOTICE
file-type-iconREADME.adoc
file-type-iconcore-concepts.md
Kubernetes Service

Kubernetes Service

Deploy a Kubernetes service with zero-downtime, rolling deployment, RBAC, auto scaling, secrets management, and more.

Code Preview

Preview the Code

mobile file icon

README.md

down

Tests

This folder contains automated tests for this Module. All of the tests are written in Go.

There are three tiers of tests for helm:

  • Template tests: These are tests designed to test the logic of the templates. These tests should run helm template with various input values and parse the yaml to validate any logic embedded in the templates (e.g by reading them in using client-go). Since templates are not statically typed, the goal of these tests is to promote fast cycle time while catching some of the common bugs from typos or logic errors before getting to the slower integration tests.
  • Integration tests: These are tests that are designed to deploy the infrastructure and validate that it actually works as expected. If you consider the template tests to be syntactic tests, these are semantic tests that validate the behavior of the deployed resources.
  • Production tests (helm tests): These are tests that are run with the helm chart after it is deployed to validate the chart installed and deployed correctly. These should be smoke tests with minimal validation to ensure that the common operator errors during deployment are captured as early as possible. Note that because these tests run even on a production system, they should be passive and not destructive.

This folder contains the "template tests" and "integration tests". Both types of tests use a helper library called Terratest. While "template tests" do not need any infrastructure, the "integration tests" deploy the charts to a Kubernetes cluster.

WARNING WARNING WARNING

Note #1: Many of these tests create real resources in a Kubernetes cluster and then try to clean those resources up at the end of a test run. That means these tests may potentially pollute your Kubernetes cluster with unnecessary resources! When adding tests, please be considerate of the resources you create and take extra care to clean everything up when you're done!

Note #2: Never forcefully shut the tests down (e.g. by hitting CTRL + C) or the cleanup tasks won't run!

Note #3: We set -timeout 60m on all tests not because they necessarily take that long, but because Go has a default test timeout of 10 minutes, after which it forcefully kills the tests with a SIGQUIT, preventing the cleanup tasks from running. Therefore, we set an overlying long timeout to make sure all tests have enough time to finish and clean up.

Running the tests

Prerequisites

One-time setup

Download Go dependencies using dep:

cd test
dep ensure

Run all the tests

We use build tags to categorize the tests. The tags are:

  • all: Run all the tests
  • tpl: Run the template tests
  • integration: Run the integration tests

You can run all the tests by passing the all build tag:

cd test
go test -v -tags all -timeout 60m

Run a specific test

To run a specific test called TestFoo:

cd test
go test -v -timeout 60m -tags all -run TestFoo

Run just the template tests

Since the integration tests require infrastructure, they can be considerably slower than the unit tests. As such, to promote fast test cycles, you may want to test just the template tests. To do so, you can pass the tpl build tag:

cd test
go test -v -tags tpl

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?