cluster

package
v5.58.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: Apache-2.0 Imports: 66 Imported by: 0

Documentation

Overview

Package cluster groups all KSail cluster lifecycle Cobra commands under a single namespace.

This package contains commands for managing local Kubernetes cluster lifecycles, including init, create, delete, start, stop, list, info, connect, and switch operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrAmbiguousCluster = errors.New("ambiguous cluster name")

ErrAmbiguousCluster is returned when multiple distribution contexts match the cluster name.

View Source
var ErrContextNotFound = errors.New("no matching context found for cluster")

ErrContextNotFound is returned when the specified cluster does not have a matching context in the kubeconfig.

View Source
var ErrInvalidCompressionLevel = errors.New(
	"compression level out of range",
)

ErrInvalidCompressionLevel is returned when the compression level is outside the valid range.

View Source
var ErrInvalidResourcePolicy = errors.New(
	"invalid existing-resource-policy: must be 'none' or 'update'",
)

ErrInvalidResourcePolicy is returned when an unsupported existing-resource-policy value is provided.

View Source
var ErrInvalidTarPath = errors.New("invalid tar entry path")

ErrInvalidTarPath is returned when a tar entry contains a path traversal attempt.

View Source
var ErrKubeconfigNotFound = errors.New(
	"kubeconfig not found; ensure cluster is created and configured",
)

ErrKubeconfigNotFound is returned when no kubeconfig path can be resolved.

View Source
var ErrRestoreFailed = errors.New("resource restore failed")

ErrRestoreFailed is returned when one or more resources fail to restore.

View Source
var ErrSymlinkInArchive = errors.New(
	"symbolic and hard links are not supported in backup archives",
)

ErrSymlinkInArchive is returned when a tar archive contains symbolic or hard links, which are not supported.

View Source
var ErrUnsupportedProvider = clustererr.ErrUnsupportedProvider

ErrUnsupportedProvider re-exports the shared error for backward compatibility.

Functions

func HandleInitRunE

func HandleInitRunE(
	cmd *cobra.Command,
	cfgManager *ksailconfigmanager.ConfigManager,
	deps InitDeps,
) error

HandleInitRunE handles the init command.

func HandleListRunE

func HandleListRunE(
	cmd *cobra.Command,
	providerFilter v1alpha1.Provider,
	deps ListDeps,
) error

HandleListRunE handles the list command. Exported for testing purposes.

func HandleSwitchRunE added in v5.46.0

func HandleSwitchRunE(
	cmd *cobra.Command,
	clusterName string,
	deps SwitchDeps,
) error

HandleSwitchRunE handles the switch command. Exported for testing purposes.

func InitFieldSelectors

func InitFieldSelectors() []ksailconfigmanager.FieldSelector[v1alpha1.Cluster]

InitFieldSelectors returns the field selectors used by the init command. Kept local (rather than separate file) to keep init-specific wiring cohesive.

func IsClusterContainer added in v5.24.0

func IsClusterContainer(containerName, clusterName string) bool

IsClusterContainer checks if a container name belongs to the given cluster. Exported for testing.

func NewBackupCmd added in v5.40.0

func NewBackupCmd(_ *di.Runtime) *cobra.Command

NewBackupCmd creates the cluster backup command.

func NewClusterCmd

func NewClusterCmd(runtimeContainer *di.Runtime) *cobra.Command

NewClusterCmd creates the parent cluster command and wires lifecycle subcommands beneath it.

func NewConnectCmd

func NewConnectCmd(_ *di.Runtime) *cobra.Command

NewConnectCmd creates the connect command for clusters.

func NewCreateCmd

func NewCreateCmd(runtimeContainer *di.Runtime) *cobra.Command

NewCreateCmd wires the cluster create command using the shared runtime container.

func NewDeleteCmd

func NewDeleteCmd(runtimeContainer *di.Runtime) *cobra.Command

NewDeleteCmd creates and returns the delete command. Delete uses --name and --provider flags to determine the cluster to delete.

func NewInfoCmd

func NewInfoCmd(_ *di.Runtime) *cobra.Command

NewInfoCmd creates the cluster info command. The command wraps kubectl cluster-info and appends TTL status when set.

func NewInitCmd

func NewInitCmd(runtimeContainer *di.Runtime) *cobra.Command

NewInitCmd creates and returns the init command.

func NewListCmd

func NewListCmd(runtimeContainer *di.Runtime) *cobra.Command

NewListCmd creates the list command for clusters.

func NewRestoreCmd added in v5.40.0

func NewRestoreCmd(_ *di.Runtime) *cobra.Command

NewRestoreCmd creates the cluster restore command.

func NewStartCmd

func NewStartCmd(_ any) *cobra.Command

NewStartCmd creates and returns the start command.

func NewStopCmd

func NewStopCmd(_ any) *cobra.Command

NewStopCmd creates and returns the stop command.

func NewSwitchCmd added in v5.46.0

func NewSwitchCmd(_ *di.Runtime) *cobra.Command

NewSwitchCmd creates the switch command for clusters.

func NewUpdateCmd added in v5.30.0

func NewUpdateCmd(runtimeContainer *di.Runtime) *cobra.Command

NewUpdateCmd creates the cluster update command. The update command applies configuration changes to a running cluster. It supports in-place updates where possible and falls back to recreation when necessary.

func SetArgoCDInstallerFactoryForTests

func SetArgoCDInstallerFactoryForTests(
	factory func(*v1alpha1.Cluster) (installer.Installer, error),
) func()

SetArgoCDInstallerFactoryForTests overrides the Argo CD installer factory.

func SetCSIInstallerFactoryForTests

func SetCSIInstallerFactoryForTests(
	factory func(*v1alpha1.Cluster) (installer.Installer, error),
) func()

SetCSIInstallerFactoryForTests overrides the CSI installer factory.

func SetCertManagerInstallerFactoryForTests

func SetCertManagerInstallerFactoryForTests(
	factory func(*v1alpha1.Cluster) (installer.Installer, error),
) func()

SetCertManagerInstallerFactoryForTests overrides the cert-manager installer factory.

func SetDockerClientInvokerForTests

func SetDockerClientInvokerForTests(
	invoker func(*cobra.Command, func(client.APIClient) error) error,
) func()

SetDockerClientInvokerForTests overrides the Docker client invoker for testing.

func SetEnsureArgoCDResourcesForTests

func SetEnsureArgoCDResourcesForTests(
	fn func(context.Context, string, *v1alpha1.Cluster, string) error,
) func()

SetEnsureArgoCDResourcesForTests overrides the Argo CD resource ensure function.

func SetEnsureOCIArtifactForTests added in v5.21.6

func SetEnsureOCIArtifactForTests(
	fn func(context.Context, *cobra.Command, *v1alpha1.Cluster, string, io.Writer) (bool, error),
) func()

SetEnsureOCIArtifactForTests overrides the OCI artifact ensure function.

func SetFluxInstallerFactoryForTests added in v5.15.0

func SetFluxInstallerFactoryForTests(
	factory func(*v1alpha1.Cluster) (installer.Installer, error),
) func()

SetFluxInstallerFactoryForTests overrides the Flux installer factory.

func SetLocalRegistryServiceFactoryForTests added in v5.15.0

func SetLocalRegistryServiceFactoryForTests(factory localregistry.ServiceFactoryFunc) func()

SetLocalRegistryServiceFactoryForTests overrides the local registry service factory for testing.

func SetPolicyEngineInstallerFactoryForTests added in v5.56.0

func SetPolicyEngineInstallerFactoryForTests(
	factory func(*v1alpha1.Cluster) (installer.Installer, error),
) func()

SetPolicyEngineInstallerFactoryForTests overrides the policy engine installer factory.

func SetProvisionerFactoryForTests added in v5.30.0

func SetProvisionerFactoryForTests(factory clusterprovisioner.Factory) func()

SetProvisionerFactoryForTests overrides the cluster provisioner factory for testing.

func SetSetupFluxInstanceForTests added in v5.21.6

func SetSetupFluxInstanceForTests(
	fn func(context.Context, string, *v1alpha1.Cluster, string, string) error,
) func()

SetSetupFluxInstanceForTests overrides the FluxInstance setup function.

func SetWaitForFluxReadyForTests added in v5.21.6

func SetWaitForFluxReadyForTests(fn func(context.Context, string) error) func()

SetWaitForFluxReadyForTests overrides the Flux readiness wait function.

Types

type BackupMetadata added in v5.40.0

type BackupMetadata struct {
	Version       string    `json:"version"`
	Timestamp     time.Time `json:"timestamp"`
	ClusterName   string    `json:"clusterName"`
	Distribution  string    `json:"distribution"`
	Provider      string    `json:"provider"`
	KSailVersion  string    `json:"ksailVersion"`
	ResourceCount int       `json:"resourceCount"`
	ResourceTypes []string  `json:"resourceTypes"`
}

BackupMetadata contains metadata about a backup.

type InitDeps

type InitDeps struct {
	Timer timer.Timer
}

InitDeps captures dependencies required for the init command.

type ListDeps

type ListDeps struct {
	// DistributionFactoryCreator is an optional function that creates factories for distributions.
	// If nil, real factories with empty configs are used.
	// This is primarily for testing purposes.
	DistributionFactoryCreator func(v1alpha1.Distribution) clusterprovisioner.Factory

	// HetznerProvider is an optional Hetzner provider for listing Hetzner clusters.
	// If nil, a real provider will be created if HCLOUD_TOKEN is set.
	HetznerProvider *hetzner.Provider

	// OmniProvider is an optional Omni provider for listing Omni clusters.
	// If nil, a real provider will be created if OMNI_SERVICE_ACCOUNT_KEY is set.
	OmniProvider *omni.Provider
}

ListDeps captures dependencies needed for the list command logic.

type SwitchDeps added in v5.46.0

type SwitchDeps struct {
	// KubeconfigPath overrides the kubeconfig path resolution.
	// If empty, the path is resolved from ksail.yaml or the default.
	KubeconfigPath string
}

SwitchDeps captures injectable dependencies for the switch command.

Jump to

Keyboard shortcuts

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