kindutil

package
v0.8.0 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: 37 Imported by: 0

Documentation

Overview

Package kindutil provides shared utilities for creating and configuring Kind (Kubernetes in Docker) clusters in test environments.

Index

Constants

View Source
const BaseKindConfig = `kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: KubeletConfiguration
    maxPods: 500
kubeadmConfigPatchesJSON6902:
` + etcdNoFsyncPatches

BaseKindConfig is the default kind cluster configuration with increased pod limits. The default maxPods (110) is too restrictive for integration tests running in parallel.

etcd runs with --unsafe-no-fsync (same dual-version patch pattern as the cert SAN below; see etcdNoFsyncPatches): on hosts with slow fsync (Docker Desktop's VM disk, shared CI runners) etcd commit latency under parallel pod churn makes kube-controller-manager lose its leader-election lease, which kills the ServiceAccount controller mid-suite and surfaces as apiserver "TLS handshake timeout" / "serviceaccount not found" test failures. Durability is irrelevant for a throwaway test cluster — kind's own CI runs etcd the same way.

View Source
const DockerTimeout = 5 * time.Minute

DockerTimeout bounds one docker invocation, including a build.

View Source
const PodSubnet = "10.244.0.0/16"

PodSubnet is Kind's default pod subnet; Calico's IP pool must match kube-proxy's cluster CIDR.

Variables

View Source
var ErrAgentUnavailable = errors.New("no haptic agent to drive")

ErrAgentUnavailable means the built binary has no `haptic agent` subcommand, so a suite that drives one has nothing to drive.

Functions

func BlackholeCluster

func BlackholeCluster(ctx context.Context, runner process.Runner, name string, environment map[string]string) error

BlackholeCluster isolates a caller-selected, already-created Kind cluster without taking ownership.

func BuildHAProxyAgentImage

func BuildHAProxyAgentImage(baseImage, tag string) error

BuildHAProxyAgentImage tags an image that is baseImage plus the haptic binary, which lets the agent run as its own container against the same mounts — the chart's topology. It verifies `haptic agent --help` in the built image, so a binary without the subcommand fails here rather than as a crash-looping container.

func ClusterExists

func ClusterExists(ctx context.Context, runner process.Runner, name string, environment map[string]string) (bool, error)

func ClusterKubeconfig

func ClusterKubeconfig(ctx context.Context, runner process.Runner, name string, environment map[string]string) (string, error)

func DockerEnvironment

func DockerEnvironment(getenv func(string) string) map[string]string

func DockerUsable

func DockerUsable() error

DockerUsable returns why docker cannot be driven from here, or nil.

func GetDindHostname

func GetDindHostname() string

GetDindHostname extracts the hostname from DOCKER_HOST. For "tcp://docker:2376" it returns "docker".

func GetNodePortHost

func GetNodePortHost() string

GetNodePortHost returns the hostname for accessing NodePort services. In Docker-in-Docker, this is the dind hostname; otherwise localhost.

func HapticBinary

func HapticBinary() (string, error)

HapticBinary resolves a linux binary to run in a container: an explicit override, then `make build`'s output while it is newer than every Go source, then a fresh build.

func InstallCNICluster added in v0.7.0

func InstallCNICluster(ctx context.Context, runner process.Runner, name string, environment map[string]string) error

InstallCNICluster installs the test CNI on a caller-selected, already-created Kind cluster without taking ownership.

func IsDockerInDocker

func IsDockerInDocker() bool

IsDockerInDocker returns true if running in a Docker-in-Docker environment. This is detected by checking if DOCKER_HOST is set to a tcp:// URL, which is typical for GitLab CI dind services.

func RemoveImage

func RemoveImage(tag string)

RemoveImage drops a tag built for one run.

func RepoRoot

func RepoRoot() (string, error)

RepoRoot walks up from the working directory to the module root.

func RunDocker

func RunDocker(stdin io.Reader, args ...string) (string, error)

RunDocker runs one docker command with stdin and returns its combined output.

func SetDeploymentFixtureImage

func SetDeploymentFixtureImage(manifest []byte, containerName, image string) ([]byte, error)

SetDeploymentFixtureImage replaces exactly one named container across a fixture's Deployments.

func SyntheticBackendRanges

func SyntheticBackendRanges() []string

SyntheticBackendRanges keeps fixture health checks from reaching the host network.

func ValidateChartImageTag

func ValidateChartImageTag(image, tag string) error

ValidateChartImageTag rejects an independent tag that changes the chart image.

func ValidatePodContainerImages

func ValidatePodContainerImages(pods []corev1.Pod, expected map[string]string) error

ValidatePodContainerImages requires each named container, sidecar or regular, and checks every replica.

Types

type ChartImages

type ChartImages struct {
	HAProxyVersion string `json:"haproxyVersion"`
	HAProxy        string `json:"haproxy"`
	Vector         string `json:"vector"`
	Varnish        string `json:"varnish"`
	Valkey         string `json:"valkey"`
	SPOAHub        string `json:"spoaHub"`
}

ChartImages is the runtime selection made by this checkout's Helm chart.

func LoadChartImages

func LoadChartImages(series string) (ChartImages, error)

LoadChartImages uses the chart's default series unless a matrix series is given.

type Cluster

type Cluster struct {
	Name          string            `json:"name"`
	Kubeconfig    string            `json:"kubeconfig"`
	Artifacts     string            `json:"artifacts"`
	Owner         string            `json:"owner"`
	Environment   map[string]string `json:"environment"`
	NetworkLabels map[string]string `json:"networkLabels,omitempty"`
	ReadyTimeout  time.Duration     `json:"readyTimeout,omitempty"`
	// contains filtered or unexported fields
}

Cluster owns only nodes bearing its unique mount, including failed startup.

func NewCluster

func NewCluster(runner process.Runner, options *ClusterOptions) (*Cluster, error)

func ResumeCluster

func ResumeCluster(ctx context.Context, runner process.Runner, name string, environment map[string]string) (*Cluster, bool, error)

ResumeCluster returns nil for a cluster without this harness's ownership mount.

func (*Cluster) Blackhole

func (c *Cluster) Blackhole(ctx context.Context) error

func (*Cluster) Client

func (c *Cluster) Client(namespace string) kubeexec.Client

func (*Cluster) Close

func (c *Cluster) Close(ctx context.Context) error

Close leaves diagnostic files and the private kubeconfig available for inspection.

func (*Cluster) Create

func (c *Cluster) Create(ctx context.Context, image string) error

func (*Cluster) LoadImages

func (c *Cluster) LoadImages(ctx context.Context, images ...string) error

type ClusterOptions

type ClusterOptions struct {
	Name          string
	Kubeconfig    string
	Artifacts     string
	Config        []byte
	Environment   map[string]string
	NetworkLabels map[string]string
	ReadyTimeout  time.Duration
}

Jump to

Keyboard shortcuts

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