k3d

package
v6.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package k3d provides configuration management for K3d clusters.

This package contains the core Manager implementation for loading K3d cluster configurations from files, with support for environment variable overrides and Viper-based configuration management.

Index

Constants

View Source
const ContainerdConfigTemplatePath = "/var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl"

ContainerdConfigTemplatePath is the path inside K3d node containers where K3s looks for a custom containerd config template. When this file exists, K3s uses it instead of its built-in default to generate the final containerd config.

View Source
const DefaultClusterName = "k3d-default"

DefaultClusterName is the default K3d cluster name when none is specified. This matches K3d's internal default naming convention.

View Source
const DefaultImageVerifierDir = "k3d/containerd"

DefaultImageVerifierDir is the default directory for the K3d containerd config template relative to the project root. The template file is generated during `ksail cluster init` when image verification is enabled for the K3s distribution.

View Source
const ImageVerificationConfigTemplate = `` /* 1758-byte string literal not displayed */

ImageVerificationConfigTemplate is a K3s containerd config template (Go template) that enables the image verifier plugin. K3s processes this template to generate the final containerd config.toml. The template includes K3s's essential Go template markers ({{ .PrivateRegistryConfig }}) so K3s can inject its dynamic configuration (e.g., registry mirrors configured via K3d's registries.yaml).

The image verifier plugin section configures containerd's bindir verifier, which invokes verifier binaries (e.g., Cosign, Notation) from bin_dir before pulling images. If bin_dir is empty or contains no verifier binaries, image pulls proceed without verification (containerd's default behavior).

Requires K3s v1.35+ (containerd 2.2+). See: https://github.com/containerd/containerd/blob/main/docs/image-verification.md

Variables

View Source
var DefaultK3sImage = k3sImage()

DefaultK3sImage is the default K3s container image. This value is read from the Dockerfile in this package which is updated by Dependabot.

Functions

func ApplyImageVerificationVolumes added in v6.2.0

func ApplyImageVerificationVolumes(
	k3dConfig *v1alpha5.SimpleConfig,
	templateHostPath string,
)

ApplyImageVerificationVolumes adds a volume mount to the K3d config to inject the containerd config template into K3d node containers. The template is mounted at K3s's custom containerd config template path so K3s uses it to generate the final containerd config with the image verifier plugin enabled.

This function is idempotent — it skips appending if the volume mount is already present.

func NewK3dSimpleConfig

func NewK3dSimpleConfig(name, apiVersion, kind string) *v1alpha5.SimpleConfig

NewK3dSimpleConfig creates a new v1alpha5.SimpleConfig with the specified name and TypeMeta. This function provides a canonical way to create K3d clusters with proper field initialization. Use empty string for name to create a cluster without a specific name.

func ParseRegistryConfig

func ParseRegistryConfig(raw string) map[string][]string

ParseRegistryConfig parses K3d registry mirror configuration from raw YAML string. Returns a map of host to endpoints, filtering out empty entries. Intentionally returns an empty map (instead of an error) for invalid YAML to support graceful degradation when registry configuration is malformed or missing.

func ResolveClusterName

func ResolveClusterName(
	clusterCfg *v1alpha1.Cluster,
	k3dConfig *v1alpha5.SimpleConfig,
) string

ResolveClusterName returns the effective cluster name from K3d config or cluster config. Priority: k3dConfig.Name > clusterCfg.Spec.Cluster.Connection.Context > DefaultClusterName. Returns DefaultClusterName if both configs are nil or have empty names.

func ResolveNetworkName

func ResolveNetworkName(clusterName string) string

ResolveNetworkName returns the Docker network name for a K3d cluster. K3d uses "k3d-<clustername>" as the network naming convention.

Types

type ConfigManager

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

ConfigManager implements configuration management for K3d v1alpha5.SimpleConfig configurations. It provides file-based configuration loading without Viper dependency.

func NewConfigManager

func NewConfigManager(configPath string) *ConfigManager

NewConfigManager creates a new configuration manager for K3d cluster configurations. configPath specifies the path to the K3d configuration file to load.

func (*ConfigManager) Load

Load loads the K3d configuration from the specified file. Returns the loaded config, either freshly loaded or previously cached. If the file doesn't exist, returns a default K3d cluster configuration. Validates the configuration after loading and returns an error if validation fails. The opts parameter is accepted for interface compliance but not currently used.

Jump to

Keyboard shortcuts

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