helmlint

package module
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 15 Imported by: 0

README

helmlint

Go library for testing Helm charts.

Why?

A way to parse Helm charts into a complete AST doesn't currently exist. Good parsers exist for Go templates and YAML, but not Go templates + YAML. For large charts it's important to lint every branch of the chart's control flow. But without an AST it's impossible to know when a branch isn't reached.

helmlint provides a workaround: injecting comments under every if statement and checking for them in the rendered chart output. Missing comments will fail the test unless ignored.

The library uses conftest to handle the actual linting (bring your own policies).

Usage

See the examples directory to get started and the Godocs for complete documentation of more obscure options.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lint

func Lint(t T, args ...Option)

Types

type Option

type Option func(*options)

func WithChartDir

func WithChartDir(dir string) Option

WithChartDir sets the directory of the chart to be tested. Defaults to the current directory.

func WithFixturesDir

func WithFixturesDir(dir string) Option

WithFixturesDir overrides the default fixtures directory, which is "fixtures" in the chart directory. Multiple fixtures directores are supported.

func WithMaxConcurrency

func WithMaxConcurrency(n int) Option

WithMaxConcurrency sets the maximum number of concurrent goroutines used by the linters. Defaults to 2 * runtime.NumCPU().

func WithPoliciesDir

func WithPoliciesDir(dir string) Option

WithPolicyDir overrides the default policies directory, which is "policies" in the chart directory.

func WithPreserve

func WithPreserve() Option

WithPreserve causes the temporary directory to be logged after the test instead of being deleted. Useful for debugging.

func WithRecursion

func WithRecursion(fn RecursionFn, opts ...Option) Option

WithRecursion provides a hook for extracting a k8s manifest to be linted out of another resource. For example: if a chart renders some resources into a configmap, this hook can be used to lint the "nested" resources. Multiple recursions are allowed. Only the WithPolicyDir option is supported.

func WithVisitor

func WithVisitor(fn VisitorFn) Option

WithVisitor is called for every fixture and given the path of the rendered chart directory. Multiple visitors are allowed. Might be called concurrently!

func WithWriteExceptions

func WithWriteExceptions() Option

WithWriteExceptions causes the linter to update the chart to ignore conditional branches that are not currently covered by the given fixtures.

Disabled by default. Can also be enabled by setting HELMLINT_WRITE_EXCEPTIONS=true.

type RecursionFn

type RecursionFn func(renderedDir, outputDir string) error

func RecurseConfigmap

func RecurseConfigmap(manifestPath string) RecursionFn

RecurseConfigmap recurses into resource manifests stored in each key of a ConfigMap at the given file path relative to the chart output.

type T

type T interface {
	Logf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Cleanup(func())
	FailNow()
}

type VisitorFn

type VisitorFn func(t T, dir string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL