setup

package
v5.23.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package setup provides helpers for cluster creation and setup workflows. It contains component installers, CNI setup, and registry stage handling that are used by the cluster create command.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCertManagerInstallerFactoryNil        = errors.New("cert-manager installer factory is nil")
	ErrArgoCDInstallerFactoryNil             = errors.New("argocd installer factory is nil")
	ErrKubeletCSRApproverInstallerFactoryNil = errors.New(
		"kubelet-csr-approver installer factory is nil",
	)
	ErrClusterConfigNil = errors.New("cluster config is nil")
)

Errors for component installation.

View Source
var ErrCSIInstallerFactoryNil = errors.New("CSI installer factory is nil")

ErrCSIInstallerFactoryNil is returned when the CSI installer factory is nil.

View Source
var ErrPolicyEngineDisabled = errors.New("policy engine is disabled")

ErrPolicyEngineDisabled is returned when the policy engine is disabled.

View Source
var ErrPolicyEngineInstallerFactoryNil = errors.New("policy engine installer factory is nil")

ErrPolicyEngineInstallerFactoryNil is returned when the policy engine installer factory is nil.

View Source
var ErrUnsupportedCNI = errors.New("unsupported CNI type")

ErrUnsupportedCNI is returned when an unsupported CNI type is encountered.

Functions

func EnsureArgoCDResources

func EnsureArgoCDResources(
	ctx context.Context,
	kubeconfig string,
	clusterCfg *v1alpha1.Cluster,
	clusterName string,
) error

EnsureArgoCDResources configures default Argo CD resources post-install.

func HelmClientForCluster

func HelmClientForCluster(clusterCfg *v1alpha1.Cluster) (*helm.Client, string, error)

HelmClientForCluster creates a Helm client configured for the cluster.

func InstallArgoCDSilent

func InstallArgoCDSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallArgoCDSilent installs ArgoCD silently for parallel execution.

func InstallCNI

func InstallCNI(
	cmd *cobra.Command,
	clusterCfg *v1alpha1.Cluster,
	tmr timer.Timer,
) (bool, error)

InstallCNI installs the configured CNI for the cluster. Returns true if a CNI was installed, false if using default/none.

func InstallCSISilent

func InstallCSISilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallCSISilent installs CSI silently for parallel execution.

func InstallCertManagerSilent

func InstallCertManagerSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallCertManagerSilent installs cert-manager silently for parallel execution.

func InstallFluxSilent

func InstallFluxSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallFluxSilent installs Flux silently for parallel execution.

func InstallKubeletCSRApproverSilent added in v5.17.0

func InstallKubeletCSRApproverSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallKubeletCSRApproverSilent installs kubelet-csr-approver silently for parallel execution. kubelet-csr-approver is required when metrics-server is installed with secure TLS enabled, as it automatically approves kubelet serving certificate CSRs.

func InstallMetricsServerSilent

func InstallMetricsServerSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallMetricsServerSilent installs metrics-server silently for parallel execution.

func InstallPolicyEngineSilent added in v5.17.0

func InstallPolicyEngineSilent(
	ctx context.Context,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
) error

InstallPolicyEngineSilent installs the policy engine silently for parallel execution.

func InstallPostCNIComponents

func InstallPostCNIComponents(
	cmd *cobra.Command,
	clusterCfg *v1alpha1.Cluster,
	factories *InstallerFactories,
	tmr timer.Timer,
) error

InstallPostCNIComponents installs all post-CNI components in parallel. This includes metrics-server, CSI, cert-manager, and GitOps engines (Flux/ArgoCD). For Flux, the OCI artifact push and readiness wait happens after installation.

func NeedsCSIInstall added in v5.22.0

func NeedsCSIInstall(clusterCfg *v1alpha1.Cluster) bool

NeedsCSIInstall determines if CSI needs to be installed.

In general, we install CSI only when it is explicitly Enabled AND the distribution × provider combination does not provide it by default.

Special case:

  • Talos × Hetzner: Hetzner CSI is not pre-installed and must be installed by KSail when CSI is either Default or Enabled.

func NeedsMetricsServerInstall

func NeedsMetricsServerInstall(clusterCfg *v1alpha1.Cluster) bool

NeedsMetricsServerInstall determines if metrics-server needs to be installed. Returns true only when MetricsServer is Enabled AND the distribution doesn't provide it by default. When MetricsServer is Default, we don't install (rely on distribution's default behavior).

func ResolveClusterNameFromContext added in v5.21.6

func ResolveClusterNameFromContext(clusterCfg *v1alpha1.Cluster) string

ResolveClusterNameFromContext resolves the cluster name from the cluster config. This uses the distribution's default cluster name for registry naming. The cluster name is used for constructing registry container names (e.g., k3d-default-local-registry).

func RunDockerStage

func RunDockerStage(
	cmd *cobra.Command,
	tmr timer.Timer,
	info StageInfo,
	action func(context.Context, client.APIClient) error,
	dockerInvoker DockerClientInvoker,
) error

RunDockerStage executes a Docker-based stage with standard progress messaging. This provides a consistent pattern for all Docker operations that need to: 1. Track timing via Timer.NewStage() 2. Show a title message with emoji 3. Show an activity message (optional) 4. Execute a Docker action 5. Show success/failure messages

Parameters:

  • cmd: The Cobra command for output context
  • tmr: Timer for stage timing
  • info: Stage display information
  • action: The Docker action to execute
  • dockerInvoker: Function to create/invoke Docker client (use nil for default)

func ShouldPushOCIArtifact added in v5.21.6

func ShouldPushOCIArtifact(clusterCfg *v1alpha1.Cluster) bool

ShouldPushOCIArtifact determines if OCI artifact push should happen for Flux. Returns true if Flux is enabled and a local registry is configured.

Types

type ComponentRequirements added in v5.17.0

type ComponentRequirements struct {
	NeedsMetricsServer      bool
	NeedsKubeletCSRApprover bool
	NeedsCSI                bool
	NeedsCertManager        bool
	NeedsPolicyEngine       bool
	NeedsArgoCD             bool
	NeedsFlux               bool
}

ComponentRequirements represents which components need to be installed.

func GetComponentRequirements added in v5.17.0

func GetComponentRequirements(clusterCfg *v1alpha1.Cluster) ComponentRequirements

GetComponentRequirements determines which components need to be installed based on cluster config.

func (ComponentRequirements) Count added in v5.17.0

func (r ComponentRequirements) Count() int

Count returns the number of components that need to be installed.

type DockerClientInvoker

type DockerClientInvoker func(*cobra.Command, func(client.APIClient) error) error

DockerClientInvoker is a function that invokes an operation with a Docker client.

func DefaultDockerClientInvoker

func DefaultDockerClientInvoker() DockerClientInvoker

DefaultDockerClientInvoker returns the default Docker client invoker.

type InstallerFactories

type InstallerFactories struct {
	Flux               func(client helm.Interface, timeout time.Duration) installer.Installer
	CertManager        func(clusterCfg *v1alpha1.Cluster) (installer.Installer, error)
	CSI                func(clusterCfg *v1alpha1.Cluster) (installer.Installer, error)
	PolicyEngine       func(clusterCfg *v1alpha1.Cluster) (installer.Installer, error)
	ArgoCD             func(clusterCfg *v1alpha1.Cluster) (installer.Installer, error)
	KubeletCSRApprover func(clusterCfg *v1alpha1.Cluster) (installer.Installer, error)
	// EnsureArgoCDResources configures default Argo CD resources post-install.
	EnsureArgoCDResources func(
		ctx context.Context, kubeconfig string, clusterCfg *v1alpha1.Cluster, clusterName string,
	) error
	// EnsureFluxResources enforces default Flux resources post-install.
	// If artifactPushed is false, the function will skip waiting for FluxInstance readiness
	// because the artifact doesn't exist yet (will be pushed later via workload push).
	EnsureFluxResources func(
		ctx context.Context, kubeconfig string, clusterCfg *v1alpha1.Cluster, clusterName string, artifactPushed bool,
	) error
	// SetupFluxInstance creates the FluxInstance CR without waiting for readiness.
	// Use with WaitForFluxReady after pushing artifacts.
	SetupFluxInstance func(
		ctx context.Context, kubeconfig string, clusterCfg *v1alpha1.Cluster, clusterName string,
	) error
	// WaitForFluxReady waits for the FluxInstance to be ready.
	// Call after pushing OCI artifacts.
	WaitForFluxReady func(ctx context.Context, kubeconfig string) error
	// EnsureOCIArtifact checks if an OCI artifact exists and pushes one if needed.
	// Returns true if artifact exists or was pushed, false if not needed.
	// Set to nil to use the default implementation.
	EnsureOCIArtifact func(
		ctx context.Context, cmd *cobra.Command, clusterCfg *v1alpha1.Cluster, clusterName string, writer io.Writer,
	) (bool, error)
	// HelmClientFactory creates a Helm client for the cluster.
	HelmClientFactory func(clusterCfg *v1alpha1.Cluster) (*helm.Client, string, error)
}

InstallerFactories holds factory functions for creating component installers. These can be overridden in tests for dependency injection.

func DefaultInstallerFactories

func DefaultInstallerFactories() *InstallerFactories

DefaultInstallerFactories returns the default installer factories.

type StageInfo

type StageInfo struct {
	Title         string
	Emoji         string
	Activity      string
	Success       string
	FailurePrefix string
}

StageInfo contains display information for a setup stage. Note: Leading newlines between stages are handled automatically by StageSeparatingWriter.

Directories

Path Synopsis
Package localregistry provides local registry lifecycle operations for cluster commands.
Package localregistry provides local registry lifecycle operations for cluster commands.
Package mirrorregistry provides mirror registry setup and connection stages for cluster creation.
Package mirrorregistry provides mirror registry setup and connection stages for cluster creation.

Jump to

Keyboard shortcuts

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