Documentation
¶
Overview ¶
Package charttest holds the shared assertions for the site-metadata contract (commonLabels, commonAnnotations, podLabels, podAnnotations) that every chart in this directory implements.
Clusters running an admission policy engine (OPA Gatekeeper, Kyverno) commonly require site-specific labels on every object before they will admit it. A chart with no way to set them cannot be installed there at all, so these assertions are what keep the knobs working as templates change.
The assertions sweep every rendered object rather than a hand-listed sample. That matters more than it sounds: the equivalent contract was first written with a hand-maintained list of chart-owned keys, and the list was wrong twice. Anything derived from a render cannot drift from the templates.
Index ¶
- func Describe(obj map[string]any) string
- func DuplicateKeys(t *testing.T, manifests string) []string
- func PodTemplates(objects []Object, ownChartOnly bool) map[string]map[string]any
- func Render(t *testing.T, spec Spec, extraArgs ...string) string
- func RunContract(t *testing.T, spec Spec)
- func SetJSON(key, jsonValue string) []string
- func StringMap(obj map[string]any, path ...string) map[string]string
- type Object
- type Spec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DuplicateKeys ¶
DuplicateKeys reports every mapping in the stream that defines the same key twice. sigs.k8s.io/yaml routes through JSON and silently keeps the last value, so a duplicate is invisible to the other assertions here — but the API server rejects it under strict decoding, which is how a user would find out.
func PodTemplates ¶
PodTemplates returns the spec.template of every workload object. When ownChartOnly is set, subchart objects are skipped.
func RunContract ¶
RunContract asserts the full site-metadata contract for one chart, and for each of its Variants.
Types ¶
type Object ¶
type Object struct {
// Source is the `# Source:` path Helm emits above each document.
Source string
Doc map[string]any
}
Object is one rendered document plus the chart path Helm attributed it to.
func (Object) FromSubchart ¶
FromSubchart reports whether Helm rendered this object from a subchart.
Helm values are chart-scoped: a chart-local commonLabels applies to the chart it is set on and does not cross into a subchart, which is what global.* is for. Assertions about a chart-local value therefore have to skip these, while the global assertion covers every object.
type Spec ¶
type Spec struct {
// ChartDir is the chart directory, relative to the test file.
ChartDir string
// BaseArgs are the --set flags this chart needs in order to render at all.
BaseArgs []string
// SubchartPrefix, when set, is a rendered-source prefix that must appear in
// the output, proving the parent's global values reached that subchart.
SubchartPrefix string
// Variants are additional configurations the whole contract is re-run
// against, named for the subtest.
//
// A chart that renders a metadata block only under some condition satisfies
// the contract in the default render and breaks it elsewhere — the nodemon
// DaemonSet put its annotations inside `if $v.withDcgm`, so turning DCGM off
// dropped commonAnnotations entirely while the default render stayed green.
Variants map[string][]string
}
Spec describes one chart under test.