Documentation
¶
Overview ¶
Package kindutil provides shared utilities for creating and configuring Kind (Kubernetes in Docker) clusters in test environments.
Index ¶
- Constants
- Variables
- func BlackholeCluster(ctx context.Context, runner process.Runner, name string, ...) error
- func BuildHAProxyAgentImage(baseImage, tag string) error
- func ClusterExists(ctx context.Context, runner process.Runner, name string, ...) (bool, error)
- func ClusterKubeconfig(ctx context.Context, runner process.Runner, name string, ...) (string, error)
- func DockerEnvironment(getenv func(string) string) map[string]string
- func DockerUsable() error
- func GetDindHostname() string
- func GetNodePortHost() string
- func HapticBinary() (string, error)
- func IsDockerInDocker() bool
- func RemoveImage(tag string)
- func RepoRoot() (string, error)
- func RunDocker(stdin io.Reader, args ...string) (string, error)
- func SetDeploymentFixtureImage(manifest []byte, containerName, image string) ([]byte, error)
- func SyntheticBackendRanges() []string
- func ValidateChartImageTag(image, tag string) error
- func ValidatePodContainerImages(pods []corev1.Pod, expected map[string]string) error
- type ChartImages
- type Cluster
- func (c *Cluster) Blackhole(ctx context.Context) error
- func (c *Cluster) Client(namespace string) kubeexec.Client
- func (c *Cluster) Close(ctx context.Context) error
- func (c *Cluster) Create(ctx context.Context, image string) error
- func (c *Cluster) LoadImages(ctx context.Context, images ...string) error
- type ClusterOptions
Constants ¶
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.
const DockerTimeout = 5 * time.Minute
DockerTimeout bounds one docker invocation, including a build.
Variables ¶
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 ¶
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 ClusterKubeconfig ¶
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 ¶
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 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 SetDeploymentFixtureImage ¶
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 ¶
ValidateChartImageTag rejects an independent tag that changes the chart image.
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.