kuretest

package
v0.2.0-beta.21 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Overview

Package kuretest holds the test helpers that hold kure's output to what a cluster would accept: every object is validated, as the YAML a user would apply, against the CustomResourceDefinitions of the exact module versions the kinds registry pins, with the API server's own validation routines (crdvalidate). A kind whose module ships no definition gets the server's ObjectMeta validation under the kind's own name rule, and nothing more; TestEveryKindHasOneSource names each such kind and why.

A second pass holds the objects to each other: AssertConsistent, AssertConsistentYAML and AssertConsistentDir check that what a tree references and the namespaces it applies into exist in it or are declared. On a written tree, AssertConsistentDir also resolves every path the tree names and builds what each Flux Kustomization applies, as kustomize-controller builds it.

It is for tests only: it registers the -update flag and reads the module cache through go list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertConsistent

func AssertConsistent(t testing.TB, objs []client.Object, declared ...Declared)

AssertConsistent encodes the objects with kure's default options and holds the YAML to AssertConsistentYAML.

func AssertConsistentDir

func AssertConsistentDir(t testing.TB, root string, declared ...Declared)

AssertConsistentDir holds every .yaml and .yml file under root, and every file a kustomization file names as a resources entry whatever its name, to AssertConsistentYAML, as one set of objects, then holds the tree to the paths it names and builds what each Flux Kustomization in it applies:

  • every Flux Kustomization's spec.path is a directory in the tree;
  • every resources and components entry of a kustomization file is a file or a directory holding a kustomization file (a components entry a directory only), anywhere in the tree; every patches path and configMapGenerator or secretGenerator files, envs or env entry is a file;
  • every Flux Kustomization with such a path builds as kustomize-controller builds it: Flux generates or amends the directory's kustomization file with the Kustomization's own fields, then kustomize builds it, plugins off, loading anywhere in the tree. The builds run in the order the Kustomizations are read — walk order, then those found under a scanned path (below) — on one copy of the tree, which each leaves as it found it, so the tree itself is never written.

Nothing is built when a path could take a build past the tree, or a write past the copy: an entry of a form kustomize's parser can take for a repository — a URL or git form Flux's own test refuses, a file:// base, a github.com host, or a user@ prefix — wherever it appears, where kustomize would only read it as a file (a patch or generator source) and where it could not complete the repository (a bare user@ name) included, since kustomize tries the repository before a directory, and before a file once the file fails to load: the refusal is by form, not by what exists at the path; a kustomization field whose loads the pass does not resolve (bases, crds, openapi, configurations, generators, transformers, validators, the helm fields, patchesStrategicMerge, patchesJson6902, replacements); an entry of a kustomization file, or a Kustomization's spec.components entry resolved against its spec.path, that leaves the tree; a symbolic link anywhere under root — the copy keeps it as a link, and Flux's generator and kustomize write through one; or a file named <kustomization file>.original, which Flux's generator overwrites with its own backup and then consumes. Each of those is a finding. A link is still read as what its name says, so the other checks run once it reads and decodes — one whose read fails, a link to a directory under a manifest's name, fails the test on that read, before its finding is reported.

Three rules are stricter than a Flux build, because the pass holds a tree to the layout kure writes; a hand-written tree that breaks one gets a finding where Flux would build. A file entry stays in or below its kustomization file's directory — kustomize's default load restriction, which Flux lifts to the source root. The repository forms above are refused as a policy, on every position: even when a file or directory so named exists, and even where kustomize would only read the entry as a file; a name with a : and no such form is read whatever it holds. And spec.path is a relative path that stays in the tree, where Flux joins an absolute or escaping one under the source root. kure writes relative paths, so none of its trees breaks one, short of a file named for an object whose name puts an @ where a username goes — the finding names the form.

root is the directory the Flux source serves, the one every spec.path is relative to: for layout.WriteManifest(base, cfg, ml) that is filepath.Join(base, cfg.ManifestsDir), for WriteToDisk(base) it is base.

A file kustomize recognizes as a kustomization file is read as its configuration, not as objects, and a file one names as data — a configMapGenerator or secretGenerator files, envs or env entry, a patches path — is not decoded, unless a kustomization file also names it as a resources entry or Flux's generator lists it under a Kustomization's spec.path (below): kustomize applies it as a manifest then, so it is read as one. A file a kustomization file names as a resources entry is read as a manifest whatever its name — kustomize applies it by name, not by suffix — so one a layout Config.ManifestFileName names without .yaml or .yml is read where Flux's own scan of a directory would skip it; a file no kustomization file names is read under those two suffixes only. A data-named .yaml or .yml file is read all the same where Flux's generator lists it: under a Flux Kustomization's spec.path that holds no kustomization file, Flux scans the directory and writes one naming every .yaml and .yml file below — a subdirectory holding its own left to that file — so the data file is applied as a manifest. A Kustomization read that way is followed to its own path. Every manifest so read decodes or fails the test. A tree whose files hold no object fails.

func AssertConsistentYAML

func AssertConsistentYAML(t testing.TB, data []byte, declared ...Declared)

AssertConsistentYAML checks that the objects in data agree with each other and with what is declared, and fails the test with every finding at once:

  • every Flux Kustomization's spec.sourceRef and spec.dependsOn, and every HelmRelease's spec.chartRef, spec.chart.spec.sourceRef and spec.dependsOn, names an object in data or an External declaration;
  • every object's metadata.namespace, and every Kustomization's spec.targetNamespace, is a Namespace in data, a Namespace declaration or one the cluster creates itself (default, kube-system, kube-public, kube-node-lease).

An object is known by kind, namespace and name: its group is not compared. An omitted namespace reads as default on an object, a declaration and a reference alike, except that a reference without one is in its referrer's; a cluster-scoped kind has none. kustomize's own configuration is not an object and is read past. Data with no object in it fails: there is nothing a pass could be about.

func AssertValid

func AssertValid(t testing.TB, objs ...client.Object)

AssertValid encodes the objects with kure's default options and validates the YAML.

func AssertValidDir

func AssertValidDir(t testing.TB, dir string)

AssertValidDir validates every .yaml and .yml file under dir. A directory whose files hold no object fails: there is nothing a pass could be about.

func AssertValidYAML

func AssertValidYAML(t testing.TB, data []byte)

AssertValidYAML validates every document in data and fails the test with all of the findings at once. Data with no object in it fails too: there is nothing a pass could be about.

func Golden

func Golden(t testing.TB, filename string, obj client.Object)

Golden encodes obj the way the golden fixtures are written, validates the result, then compares it with testdata/filename — or rewrites the file under -update. Validation comes first, so -update can never write a fixture a cluster would reject.

Types

type Declared

type Declared struct {
	// contains filtered or unexported fields
}

Declared is something a tree relies on without creating it.

func External

func External(kind, namespace, name string) Declared

External declares an object outside the tree that a reference may name. A reference names a namespaced kind only, so an omitted namespace reads as default, as it does on an object.

func Namespace

func Namespace(name string) Declared

Namespace declares a namespace the cluster already has.

Jump to

Keyboard shortcuts

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