Documentation
¶
Overview ¶
Package kindutil provides shared utilities for creating and configuring Kind (Kubernetes in Docker) clusters in test environments.
Index ¶
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 DindKindConfig = `kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: "0.0.0.0"
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: KubeletConfiguration
maxPods: 500
kubeadmConfigPatchesJSON6902:
# Both kubeadm config versions: kind applies the one matching the node's
# k8s version (v1beta3 for <= 1.35, v1beta4 for >= 1.36) and skips the other.
# Integration/acceptance pin k8s 1.32 (v1beta3); keep both so the SAN lands
# regardless of node version. Do not collapse to a single version.
- group: kubeadm.k8s.io
version: v1beta3
kind: ClusterConfiguration
patch: |
- op: add
path: /apiServer/certSANs/-
value: docker
- group: kubeadm.k8s.io
version: v1beta4
kind: ClusterConfiguration
patch: |
- op: add
path: /apiServer/certSANs/-
value: docker
` + etcdNoFsyncPatches
DindKindConfig is the kind cluster configuration for Docker-in-Docker environments. It binds the API server to 0.0.0.0, adds "docker" as a certificate SAN, and increases the pod limit for parallel test execution.
Variables ¶
This section is empty.
Functions ¶
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 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 PatchKubeconfigForDind ¶
PatchKubeconfigForDind replaces localhost/0.0.0.0 with the dind hostname in the kubeconfig server URL.
Types ¶
This section is empty.