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 ¶
- Constants
- func AssertImageGlobals(t *testing.T, spec Spec, g ImageGlobals)
- func AssertPlatformLabels(t *testing.T, spec Spec, extraArgs ...string)
- func Describe(obj map[string]any) string
- func DuplicateKeys(t *testing.T, manifests string) []string
- func Images(template map[string]any) []string
- func PodTemplates(objects []Object, ownChartOnly bool) map[string]map[string]any
- func PullSecretNames(template map[string]any) []string
- func Render(t *testing.T, spec Spec, extraArgs ...string) string
- func RewriteImage(registry, ref string) string
- func RunContract(t *testing.T, spec Spec)
- func Selectors(t *testing.T, objects []Object) map[string]string
- func Set(pairs ...string) []string
- func SetJSON(key, jsonValue string) []string
- func StringMap(obj map[string]any, path ...string) map[string]string
- func TryRender(t *testing.T, spec Spec, extraArgs ...string) (string, error)
- type ImageGlobals
- type Object
- type Spec
Constants ¶
const ( PartOfLabel = "app.kubernetes.io/part-of" ComponentLabel = "devzero.io/component" PartOf = "dz-platform" )
Platform labels every DevZero chart takes from devzero-common.
Variables ¶
This section is empty.
Functions ¶
func AssertImageGlobals ¶ added in v0.1.22
func AssertImageGlobals(t *testing.T, spec Spec, g ImageGlobals)
AssertImageGlobals checks the contract for the chart's default render and each variant.
func AssertPlatformLabels ¶ added in v0.1.22
AssertPlatformLabels checks that every rendered object carries devzero-common's platform labels, naming the chart it was rendered from, and that no pod template does: pod labels come from podLabels and the selector labels only, so adopting the library restarts no pods by itself.
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 Images ¶ added in v0.1.22
Images lists a pod template's init container and container images, in order.
func PodTemplates ¶
PodTemplates returns the spec.template of every workload object. When ownChartOnly is set, subchart objects are skipped.
func PullSecretNames ¶ added in v0.1.22
PullSecretNames lists the names in a pod template's imagePullSecrets. An entry without a name (the bare-string shape the API rejects) is reported as "<invalid>".
func RewriteImage ¶ added in v0.1.22
RewriteImage is the reference rule devzero-common.imageRef implements, restated independently so the test does not trust the template it checks: keep the path, tag and digest, replace the registry host with registry, and spell out Docker Hub's implicit library/ namespace. A first path component is a host when it has a ".", a ":" or an uppercase letter, or is localhost.
func RunContract ¶
RunContract asserts the full site-metadata contract for one chart, and for each of its Variants.
func Selectors ¶ added in v0.1.22
Selectors returns every object's spec.selector as JSON, keyed by kind/name. Workload selectors are immutable, so tests pin them exactly.
Types ¶
type ImageGlobals ¶ added in v0.1.22
type ImageGlobals struct {
// PullSecretsKey is the chart's own pull-secrets value key, merged with
// global.imagePullSecrets (for example "imagePullSecrets").
PullSecretsKey string
// OwnChartOnly skips subchart objects, for a parent whose bundled
// subchart is covered by its own package.
OwnChartOnly bool
// Variants are extra configurations, each rendering pod templates or
// containers the default does not.
Variants map[string][]string
}
ImageGlobals describes how a chart takes part in the contract.
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.