2018-04-24 11:32:38 +02:00
# Chart Testing
2019-03-15 21:51:50 +01:00
[](https://opensource.org/licenses/Apache-2.0)
2019-03-01 02:00:00 -05:00
[](https://goreportcard.com/report/github.com/helm/chart-testing)
2025-07-08 16:20:34 +03:00
[](https://github.com/helm/chart-testing/actions/workflows/ci.yaml)
2019-03-01 02:00:00 -05:00
2024-07-10 11:16:55 +02:00
`ct` is the tool for testing Helm charts.
2018-11-07 19:06:20 +01:00
It is meant to be used for linting and testing pull requests.
It automatically detects charts changed against the target branch.
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
## Installation
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
### Prerequisites
2018-06-06 15:42:53 +02:00
2024-07-16 02:58:39 -05:00
It is recommended to use the provided Docker image which can be [found on Quay ](https://quay.io/repository/helmpack/chart-testing ).
2018-08-29 17:27:56 +02:00
It comes with all necessary tools installed.
2018-06-06 15:42:53 +02:00
2019-03-28 16:46:30 -04:00
* [Helm ](http://helm.sh )
* [Git ](https://git-scm.com ) (2.17.0 or later)
* [Yamllint ](https://github.com/adrienverge/yamllint )
* [Yamale ](https://github.com/23andMe/Yamale )
* [Kubectl ](https://kubernetes.io/docs/reference/kubectl/overview/ )
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
### Binary Distribution
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
Download the release distribution for your OS from the Releases page:
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
https://github.com/helm/chart-testing/releases
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
Unpack the `ct` binary, add it to your PATH, and you are good to go!
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
### Docker Image
2018-06-06 15:42:53 +02:00
2018-11-09 06:30:01 -08:00
A Docker image is available at `quay.io/helmpack/chart-testing` with list of
available tags [here ](https://quay.io/repository/helmpack/chart-testing?tab=tags ).
2018-06-06 15:42:53 +02:00
2020-07-24 22:32:42 +02:00
### Homebrew
2019-02-18 14:43:23 -05:00
2020-07-24 22:32:42 +02:00
```console
$ brew install chart-testing
2019-02-18 14:43:23 -05:00
```
2018-06-06 15:42:53 +02:00
## Usage
2018-11-07 19:06:20 +01:00
See documentation for individual commands:
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
* [ct ](doc/ct.md )
* [ct install ](doc/ct_install.md )
* [ct lint ](doc/ct_lint.md )
* [ct lint-and-install ](doc/ct_lint-and-install.md )
2019-03-11 06:22:43 -04:00
* [ct list-changed ](doc/ct_list-changed.md )
2018-11-07 19:06:20 +01:00
* [ct version ](doc/ct_version.md )
2018-06-06 15:42:53 +02:00
2020-10-15 21:45:44 +02:00
For a more extensive how-to guide, please see:
* [charts-repo-actions-demo ](https://github.com/helm/charts-repo-actions-demo )
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
## Configuration
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
`ct` is a command-line application.
All command-line flags can also be set via environment variables or config file.
2019-02-12 21:44:06 +01:00
Environment variables must be prefixed with `CT_` .
Underscores must be used instead of hyphens.
2018-06-06 15:42:53 +02:00
2019-02-12 21:44:06 +01:00
CLI flags, environment variables, and a config file can be mixed.
The following order of precedence applies:
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
1. CLI flags
1. Environment variables
1. Config file
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
Note that linting requires config file for [yamllint ](https://github.com/adrienverge/yamllint ) and [yamale ](https://github.com/23andMe/Yamale ).
2022-10-11 15:27:38 +02:00
If not specified, these files are search in the current directory, the `.ct` directory in current directory, `$HOME/.ct` , and `/etc/ct` , in that order.
2018-11-07 19:06:20 +01:00
Samples are provided in the [etc ](etc ) folder.
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
### Examples
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
The following example show various way of configuring the same thing:
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
#### CLI
2018-09-21 16:58:02 +03:00
2022-02-02 11:10:40 +01:00
#### Remote repo
With remote repo:
2018-11-07 19:06:20 +01:00
ct install --remote upstream --chart-dirs stable,incubator --build-id pr-42
2018-09-21 16:58:02 +03:00
2022-02-02 11:10:40 +01:00
#### Local repo
If you have a chart in current directory and ct installed on the host then you can run:
ct install --chart-dirs . --charts .
With docker it works with:
2025-10-08 09:27:08 +02:00
docker run -it --network host --workdir=/data --volume ~/.kube/config:/root/.kube/config:ro --volume $(pwd):/data quay.io/helmpack/chart-testing:v3.14.0 ct install --chart-dirs . --charts .
2022-02-02 11:10:40 +01:00
Notice that `workdir` param is important and must be the same as volume mounted.
2018-11-07 19:06:20 +01:00
#### Environment Variables
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
export CT_REMOTE=upstream
export CT_CHART_DIRS=stable,incubator
export CT_BUILD_ID
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
ct install
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
#### Config File
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
`config.yaml` :
2018-06-06 15:42:53 +02:00
2018-11-07 19:06:20 +01:00
```yaml
remote: upstream
chart-dirs:
- stable
- incubator
build-id: pr-42
2018-06-06 15:42:53 +02:00
```
2018-11-09 06:30:01 -08:00
#### Config Usage
ct install --config config.yaml
2018-11-07 19:06:20 +01:00
`ct` supports any format [Viper ](https://github.com/spf13/viper ) can read, i. e. JSON, TOML, YAML, HCL, and Java properties files.
2018-11-09 06:30:01 -08:00
Notice that if no config file is specified, then `ct.yaml` (or any of the supported formats) is loaded from the current directory, `$HOME/.ct` , or `/etc/ct` , in that order, if found.
2019-01-07 21:13:30 +01:00
#### Using private chart repositories
2019-02-12 21:44:06 +01:00
When adding chart-repos you can specify additional arguments for the `helm repo add` command using `helm-repo-extra-args` on a per-repo basis.
2023-10-27 13:13:16 +01:00
You can also specify OCI registries which will be added using the `helm registry login` command, they also support the `helm-repo-extra-args` for authentication.
2019-02-12 21:44:06 +01:00
This could for example be used to authenticate a private chart repository.
2019-01-07 21:13:30 +01:00
`config.yaml` :
```yaml
chart-repos:
- incubator=https://incubator.io
- basic-auth=https://private.com
- ssl-repo=https://self-signed.ca
2023-10-27 13:13:16 +01:00
- oci-registry=oci://nice-oci-registry.pt
2019-01-07 21:13:30 +01:00
helm-repo-extra-args:
- ssl-repo=--ca-file ./my-ca.crt
```
ct install --config config.yaml --helm-repo-extra-args "basic-auth=--username user --password secret"
2018-11-07 19:06:20 +01:00
## Building from Source
2019-11-02 20:44:02 +01:00
`ct` is built using Go 1.13 or higher.
2018-09-21 16:58:02 +03:00
2019-11-02 20:44:02 +01:00
`build.sh` is used to build and release the tool.
It uses [Goreleaser ](https://goreleaser.com/ ) under the covers.
2018-09-21 16:58:02 +03:00
2019-02-12 21:44:06 +01:00
Note: on MacOS you will need `GNU Coreutils readlink` .
You can install it with:
2018-11-07 19:06:20 +01:00
```console
brew install coreutils
2018-09-21 16:58:02 +03:00
```
2018-11-07 19:06:20 +01:00
Then add `gnubin` to your `$PATH` , with:
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
```console
echo 'export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"' >> ~/.bash_profile
bash --login
2018-09-21 16:58:02 +03:00
```
2018-11-07 19:06:20 +01:00
To use the build script:
```console
$ ./build.sh -h
Usage: build.sh <options>
Build ct using Goreleaser.
2018-09-21 16:58:02 +03:00
2018-11-07 19:06:20 +01:00
-h, --help Display help
-d, --debug Display verbose output and run Goreleaser with --debug
-r, --release Create a release using Goreleaser. This includes the creation
of a GitHub release and building and pushing the Docker image.
If this flag is not specified, Goreleaser is run with --snapshot
2018-09-21 16:58:02 +03:00
```
2018-11-07 19:06:20 +01:00
## Releasing
2018-06-06 15:42:53 +02:00
2019-01-24 15:46:07 +01:00
### Prepare Release
Before a release is created, versions have to be updated in the examples.
A pull request needs to be created for this, which should be merged right before the release is cut.
Here's a previous one for reference: https://github.com/helm/chart-testing/pull/89
### Create Release
2020-11-24 07:36:52 +01:00
The release workflow is [dispatched from github actions ](https://github.com/helm/chart-testing/actions )
2025-10-08 09:27:08 +02:00
Versions must start with a lower-case `v` , e. g. `v3.14.0` .
2019-01-24 15:46:07 +01:00
2018-11-09 10:08:18 -05:00
## Supported versions
The previous MAJOR version will be supported for three months after each new MAJOR release.
2019-02-12 21:44:06 +01:00
Within this support window, pull requests for the previous MAJOR version should be made against the previous release branch.
For example, if the current MAJOR version is `v2` , the pull request base branch should be `release-v1` .
2018-11-09 10:08:18 -05:00
## Upgrading
2019-02-12 21:44:06 +01:00
When upgrading from `< v2.0.0` you will also need to change the usage in your scripts.
This is because, while the [v2.0.0 ](https://github.com/helm/chart-testing/releases/tag/v2.0.0 ) release has parity with `v1` , it was refactored from a bash library to Go so there are minor syntax differences.
Compare [v1 usage ](https://github.com/helm/chart-testing/tree/release-v1#usage ) with this (`v2` ) version's README [usage ](#usage ) section above.