shared

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package shared provides reusable helpers for command wiring.

This package contains shared utilities for command construction including configuration loading and kubeconfig path resolution.

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingClusterProvisionerDependency = errors.New("missing cluster provisioner dependency")

ErrMissingClusterProvisionerDependency indicates that a lifecycle command resolved a nil provisioner.

Functions

func GetDefaultKubeconfigPath

func GetDefaultKubeconfigPath() string

GetDefaultKubeconfigPath returns the default kubeconfig path.

func GetKubeconfigPathFromConfig

func GetKubeconfigPathFromConfig(cfg *v1alpha1.Cluster) (string, error)

GetKubeconfigPathFromConfig extracts and expands the kubeconfig path from a loaded cluster config. If the config doesn't specify a path, returns the default kubeconfig path.

func GetKubeconfigPathSilently

func GetKubeconfigPathSilently() string

GetKubeconfigPathSilently tries to load config and get kubeconfig path without any output.

func HandleLifecycleRunE

func HandleLifecycleRunE(
	cmd *cobra.Command,
	cfgManager *ksailconfigmanager.ConfigManager,
	deps LifecycleDeps,
	config LifecycleConfig,
) error

HandleLifecycleRunE orchestrates the standard lifecycle workflow including config loading and timing.

func LoadConfig

func LoadConfig(cfgManager *ksailconfigmanager.ConfigManager, deps ConfigLoadDeps) error

LoadConfig loads the KSail configuration while tracking timing information.

func NewConfigLoaderRunE

func NewConfigLoaderRunE(runtimeContainer *runtime.Runtime) func(*cobra.Command, []string) error

NewConfigLoaderRunE returns a cobra RunE that loads the KSail configuration using the runtime container.

func NewLifecycleCommandWrapper

func NewLifecycleCommandWrapper(
	runtimeContainer *runtime.Runtime,
	cfgManager *ksailconfigmanager.ConfigManager,
	config LifecycleConfig,
) func(*cobra.Command, []string) error

NewLifecycleCommandWrapper creates a cobra RunE wrapper that resolves dependencies and calls HandleLifecycleRunE.

func RunLifecycleWithConfig

func RunLifecycleWithConfig(
	cmd *cobra.Command,
	deps LifecycleDeps,
	config LifecycleConfig,
	clusterCfg *v1alpha1.Cluster,
) error

RunLifecycleWithConfig executes a lifecycle command using a pre-loaded cluster configuration.

func WithDockerClient

func WithDockerClient(cmd *cobra.Command, operation func(client.APIClient) error) error

WithDockerClient creates a Docker client, executes the given function, and cleans up. Returns an error if client creation fails or if the function returns an error. For testing, use WithDockerClientInstance with a mock client instead.

func WithDockerClientInstance

func WithDockerClientInstance(
	cmd *cobra.Command,
	dockerClient client.APIClient,
	operation func(client.APIClient) error,
) error

WithDockerClientInstance executes the given function with a provided Docker client and handles cleanup. This is useful for testing with mock clients. The client will be closed after the operation completes.

func WrapLifecycleHandler

func WrapLifecycleHandler(
	runtimeContainer *runtime.Runtime,
	cfgManager *ksailconfigmanager.ConfigManager,
	handler func(*cobra.Command, *ksailconfigmanager.ConfigManager, LifecycleDeps) error,
) func(*cobra.Command, []string) error

WrapLifecycleHandler resolves lifecycle dependencies from the runtime container before calling the provided handler.

Types

type ConfigLoadDeps

type ConfigLoadDeps struct {
	Timer timer.Timer
}

ConfigLoadDeps captures dependencies required for loading KSail configuration files.

type LifecycleAction

type LifecycleAction func(
	ctx context.Context,
	provisioner clusterprovisioner.ClusterProvisioner,
	clusterName string,
) error

LifecycleAction represents a lifecycle operation executed against a cluster provisioner.

type LifecycleConfig

type LifecycleConfig struct {
	TitleEmoji         string
	TitleContent       string
	ActivityContent    string
	SuccessContent     string
	ErrorMessagePrefix string
	Action             LifecycleAction
}

LifecycleConfig describes the messaging and action behaviour for a lifecycle command.

type LifecycleDeps

type LifecycleDeps struct {
	Timer   timer.Timer
	Factory clusterprovisioner.Factory
}

LifecycleDeps groups the injectable collaborators required by lifecycle commands.

Jump to

Keyboard shortcuts

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