Documentation
¶
Overview ¶
Package scaffolder provides utilities for scaffolding KSail project files and configuration.
This package handles the generation and initialization of KSail project structures, including creating cluster configuration files, directory structures, and registry configurations for different Kubernetes distributions (Kind, K3d).
Key functionality:
- Scaffold: Main orchestration for project file generation
- GenerateContainerdPatches: Kind mirror registry configuration
- GenerateK3dRegistryConfig: K3d mirror registry configuration
- CreateK3dConfig: K3d-specific configuration with CNI and metrics-server settings
- Distribution-specific config generation (kind.yaml, k3d.yaml, ksail.yaml)
- Kustomization file generation for GitOps workflows
The Scaffolder struct manages generators for different configuration types and handles the orchestration of file generation with force/overwrite logic.
Index ¶
- Constants
- Variables
- type GenerationParams
- type Scaffolder
- func (s *Scaffolder) CreateK3dConfig() k3dv1alpha5.SimpleConfig
- func (s *Scaffolder) GenerateK3dRegistryConfig() k3dv1alpha5.SimpleConfigRegistries
- func (s *Scaffolder) GetKindMirrorsDir() string
- func (s *Scaffolder) Scaffold(output string, force bool) error
- func (s *Scaffolder) WithClusterName(name string) *Scaffolder
Constants ¶
const ( // KindConfigFile is the default filename for Kind distribution configuration. KindConfigFile = "kind.yaml" // K3dConfigFile is the default filename for K3d distribution configuration. K3dConfigFile = "k3d.yaml" // TalosConfigDir is the default directory for Talos distribution configuration (Talos patches). TalosConfigDir = "talos" )
const DefaultKindMirrorsDir = kindconfigmanager.DefaultMirrorsDir
DefaultKindMirrorsDir is the default directory name for Kind containerd host mirror configuration.
Deprecated: Use kindconfigmanager.DefaultMirrorsDir instead. This alias is kept for backwards compatibility.
Variables ¶
var ( // ErrUnknownDistribution indicates an unsupported distribution was requested. ErrUnknownDistribution = errors.New("unknown distribution") // ErrKSailConfigGeneration wraps failures when creating ksail.yaml. ErrKSailConfigGeneration = errors.New("failed to generate ksail configuration") // ErrKindConfigGeneration wraps failures when creating Kind configuration. ErrKindConfigGeneration = errors.New("failed to generate kind configuration") // ErrK3dConfigGeneration wraps failures when creating K3d configuration. ErrK3dConfigGeneration = errors.New("failed to generate k3d configuration") // ErrTalosConfigGeneration wraps failures when creating Talos configuration. ErrTalosConfigGeneration = errors.New("failed to generate talos configuration") // ErrKustomizationGeneration wraps failures when creating kustomization.yaml. ErrKustomizationGeneration = errors.New("failed to generate kustomization configuration") // ErrGitOpsConfigGeneration wraps failures when creating GitOps CR manifests. ErrGitOpsConfigGeneration = errors.New("failed to generate gitops configuration") )
Scaffolding errors.
Functions ¶
This section is empty.
Types ¶
type GenerationParams ¶
type GenerationParams[T any] struct { Gen generator.Generator[T, yamlgenerator.Options] Model T Opts yamlgenerator.Options DisplayName string Force bool WrapErr func(error) error }
GenerationParams groups parameters for generateWithFileHandling.
type Scaffolder ¶
type Scaffolder struct {
KSailConfig v1alpha1.Cluster
KSailYAMLGenerator generator.Generator[v1alpha1.Cluster, yamlgenerator.Options]
KindGenerator generator.Generator[*v1alpha4.Cluster, yamlgenerator.Options]
K3dGenerator generator.Generator[*k3dv1alpha5.SimpleConfig, yamlgenerator.Options]
TalosGenerator *talosgenerator.TalosGenerator
KustomizationGenerator generator.Generator[*ktypes.Kustomization, yamlgenerator.Options]
Writer io.Writer
MirrorRegistries []string // Format: "name=upstream" (e.g., "docker.io=https://registry-1.docker.io")
ClusterName string // Optional override for cluster name. If set, overrides distribution defaults.
}
Scaffolder is responsible for generating KSail project files and configurations.
func NewScaffolder ¶
NewScaffolder creates a new Scaffolder instance with the provided KSail cluster configuration.
func (*Scaffolder) CreateK3dConfig ¶
func (s *Scaffolder) CreateK3dConfig() k3dv1alpha5.SimpleConfig
CreateK3dConfig creates a K3d configuration with distribution-specific settings. Node counts can be set via --control-planes and --workers CLI flags.
func (*Scaffolder) GenerateK3dRegistryConfig ¶
func (s *Scaffolder) GenerateK3dRegistryConfig() k3dv1alpha5.SimpleConfigRegistries
GenerateK3dRegistryConfig generates K3d registry configuration for mirror registry. Input format: "name=upstream" (e.g., "docker.io=https://registry-1.docker.io") K3d requires one registry per proxy, so we generate multiple create configs. Registry containers are prefixed with the cluster name to avoid Docker DNS collisions.
func (*Scaffolder) GetKindMirrorsDir ¶ added in v5.10.0
func (s *Scaffolder) GetKindMirrorsDir() string
GetKindMirrorsDir returns the configured mirrors directory or the default.
func (*Scaffolder) Scaffold ¶
func (s *Scaffolder) Scaffold(output string, force bool) error
Scaffold generates project files and configurations.
This method orchestrates the generation of:
- ksail.yaml configuration
- Distribution-specific configuration (kind.yaml or k3d.yaml)
- kind/mirrors directory with hosts.toml files (for Kind with mirror registries)
- kustomization.yaml in the source directory
Parameters:
- output: The output directory for generated files
- force: If true, overwrites existing files; if false, skips existing files
Returns:
- error: Any error encountered during scaffolding
func (*Scaffolder) WithClusterName ¶ added in v5.18.0
func (s *Scaffolder) WithClusterName(name string) *Scaffolder
WithClusterName sets an explicit cluster name override for the scaffolder. When set, this name is used for distribution configs (kind.yaml Name, k3d.yaml metadata.name), Talos cluster patches, and to derive the kubeconfig context in ksail.yaml.