registrystage

package
v5.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package registrystage provides registry setup and connection stages for cluster creation. It handles mirror registry provisioning, network creation, and containerd configuration for Kind, K3d, and Talos distributions.

Index

Constants

View Source
const (
	MirrorStageTitle    = "Create mirror registry..."
	MirrorStageEmoji    = "🪞"
	MirrorStageActivity = "creating mirror registries"
	MirrorStageSuccess  = "mirror registries created"
	MirrorStageFailure  = "failed to setup registries"

	ConnectStageTitle    = "Connect registry..."
	ConnectStageEmoji    = "🔗"
	ConnectStageActivity = "connecting registries"
	ConnectStageSuccess  = "registries connected"
	ConnectStageFailure  = "failed to connect registries"
)

Stage message constants for registry operations.

View Source
const DefaultNetworkMTU = "1500"

DefaultNetworkMTU is the default MTU for Docker bridge networks. Required by the Talos SDK's Reflect() function which reads com.docker.network.driver.mtu to parse network state.

Variables

View Source
var ConnectInfo = Info{
	Title:         ConnectStageTitle,
	Emoji:         ConnectStageEmoji,
	Activity:      ConnectStageActivity,
	Success:       ConnectStageSuccess,
	FailurePrefix: ConnectStageFailure,
}

ConnectInfo returns the stage info for registry connection.

View Source
var MirrorInfo = Info{
	Title:         MirrorStageTitle,
	Emoji:         MirrorStageEmoji,
	Activity:      MirrorStageActivity,
	Success:       MirrorStageSuccess,
	FailurePrefix: MirrorStageFailure,
}

MirrorInfo returns the stage info for mirror registry creation.

View Source
var StageDefinitions = map[Role]Definition{
	RoleMirror: {
		Info:        MirrorInfo,
		KindAction:  KindMirrorAction,
		K3dAction:   K3dMirrorAction,
		TalosAction: TalosMirrorAction,
	},
	RoleConnect: {
		Info:        ConnectInfo,
		KindAction:  KindConnectAction,
		K3dAction:   K3dConnectAction,
		TalosAction: TalosConnectAction,
	},
}

StageDefinitions maps stage roles to their definitions.

Functions

func ConnectRegistriesToClusterNetwork

func ConnectRegistriesToClusterNetwork(params StageParams) error

ConnectRegistriesToClusterNetwork attaches mirror registries to the cluster network after creation.

func EnsureDockerNetworkExists

func EnsureDockerNetworkExists(
	ctx context.Context,
	dockerClient client.APIClient,
	networkName string,
	networkCIDR string,
	writer io.Writer,
) error

EnsureDockerNetworkExists creates a Docker network if it doesn't already exist. This is used to pre-create the cluster network before registry setup, allowing registry containers to be connected and accessible via Docker DNS when nodes start pulling images during boot.

The network is created with Talos-compatible labels and CIDR so that the Talos SDK will recognize and reuse it when creating the cluster.

func GetKindMirrorsDir

func GetKindMirrorsDir(clusterCfg *v1alpha1.Cluster) string

GetKindMirrorsDir returns the configured Kind mirrors directory or the default.

func K3dConnectAction

func K3dConnectAction(_ *Context) func(context.Context, client.APIClient) error

K3dConnectAction returns the action function for K3d registry connection.

func K3dMirrorAction

func K3dMirrorAction(ctx *Context) func(context.Context, client.APIClient) error

K3dMirrorAction returns the action function for K3d mirror registry setup.

func KindConnectAction

func KindConnectAction(ctx *Context) func(context.Context, client.APIClient) error

KindConnectAction returns the action function for Kind registry connection.

func KindMirrorAction

func KindMirrorAction(ctx *Context) func(context.Context, client.APIClient) error

KindMirrorAction returns the action function for Kind mirror registry setup.

func PrepareK3dConfigWithMirrors

func PrepareK3dConfigWithMirrors(
	clusterCfg *v1alpha1.Cluster,
	k3dConfig *v1alpha5.SimpleConfig,
	mirrorSpecs []registry.MirrorSpec,
) bool

PrepareK3dConfigWithMirrors prepares the K3d config by setting up mirror registries. Returns true if mirror configuration is needed, false otherwise.

func PrepareKindConfigWithMirrors

func PrepareKindConfigWithMirrors(
	clusterCfg *v1alpha1.Cluster,
	cfgManager *ksailconfigmanager.ConfigManager,
	kindConfig *v1alpha4.Cluster,
) bool

PrepareKindConfigWithMirrors prepares the Kind config by setting up hosts directory for mirrors. Returns true if mirror configuration is needed, false otherwise. This uses the modern hosts directory pattern instead of deprecated ContainerdConfigPatches.

func PrepareTalosConfigWithMirrors

func PrepareTalosConfigWithMirrors(
	clusterCfg *v1alpha1.Cluster,
	talosConfig *talosconfigmanager.Configs,
	mirrorSpecs []registry.MirrorSpec,
) bool

PrepareTalosConfigWithMirrors prepares the Talos config by setting up mirror registries. Returns true if mirror configuration is needed, false otherwise.

func ResolveTalosClusterName

func ResolveTalosClusterName(talosConfig *talosconfigmanager.Configs) string

ResolveTalosClusterName extracts the cluster name from Talos config or returns the default.

func ResolveTalosNetworkCIDR

func ResolveTalosNetworkCIDR(_ *talosconfigmanager.Configs) string

ResolveTalosNetworkCIDR returns the Docker network CIDR for Talos. This is always DefaultNetworkCIDR (10.5.0.0/24) - NOT the pod CIDR from cluster config. The Talos SDK uses this CIDR for the Docker bridge network that nodes connect to.

func RunStage

func RunStage(
	cmd *cobra.Command,
	clusterCfg *v1alpha1.Cluster,
	deps lifecycle.Deps,
	cfgManager *ksailconfigmanager.ConfigManager,
	kindConfig *v1alpha4.Cluster,
	k3dConfig *v1alpha5.SimpleConfig,
	talosConfig *talosconfigmanager.Configs,
	role Role,
	firstActivityShown *bool,
	dockerInvoker DockerClientInvoker,
) error

RunStage executes the registry stage for the given role.

func SetupMirrorRegistries

func SetupMirrorRegistries(params StageParams) error

SetupMirrorRegistries configures mirror registries before cluster creation.

func SetupTalosMirrorRegistries

func SetupTalosMirrorRegistries(
	ctx context.Context,
	dockerAPIClient client.APIClient,
	clusterName string,
	networkName string,
	networkCIDR string,
	registryInfos []registry.Info,
	writer io.Writer,
) error

SetupTalosMirrorRegistries creates network, registry containers, and connects them.

func TalosConnectAction

func TalosConnectAction(_ *Context) func(context.Context, client.APIClient) error

TalosConnectAction returns the action function for Talos registry connection.

func TalosMirrorAction

func TalosMirrorAction(ctx *Context) func(context.Context, client.APIClient) error

TalosMirrorAction returns the action function for Talos mirror registry setup.

Types

type Context

type Context struct {
	Cmd         *cobra.Command
	ClusterCfg  *v1alpha1.Cluster
	KindConfig  *v1alpha4.Cluster
	K3dConfig   *v1alpha5.SimpleConfig
	TalosConfig *talosconfigmanager.Configs
	MirrorSpecs []registry.MirrorSpec
}

Context contains all the configuration needed for registry stage execution.

type Definition

type Definition struct {
	Info        Info
	KindAction  func(*Context) func(context.Context, client.APIClient) error
	K3dAction   func(*Context) func(context.Context, client.APIClient) error
	TalosAction func(*Context) func(context.Context, client.APIClient) error
}

Definition maps a stage role to its info and distribution-specific actions.

type DockerClientInvoker

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

DockerClientInvoker is a function that invokes Docker client operations. Can be overridden in tests to avoid real Docker connections.

var DefaultDockerClientInvoker DockerClientInvoker = docker.WithClient

DefaultDockerClientInvoker is the default Docker client invoker.

type Handler

type Handler struct {
	Prepare func() bool
	Action  func(context.Context, client.APIClient) error
}

Handler contains the prepare and action functions for a registry stage.

type Info

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

Info contains display information for a registry stage.

type K3dRegistryAction

type K3dRegistryAction func(
	context.Context,
	*v1alpha5.SimpleConfig,
	string,
	client.APIClient,
	io.Writer,
) error

K3dRegistryAction is the function signature for K3d registry actions.

type Role

type Role int

Role represents the type of registry stage operation.

const (
	// RoleMirror is the stage that creates mirror registries before cluster creation.
	RoleMirror Role = iota
	// RoleConnect is the stage that connects registries after cluster creation.
	RoleConnect
)

type StageParams

type StageParams struct {
	Cmd                *cobra.Command
	ClusterCfg         *v1alpha1.Cluster
	Deps               lifecycle.Deps
	CfgManager         *ksailconfigmanager.ConfigManager
	KindConfig         *v1alpha4.Cluster
	K3dConfig          *v1alpha5.SimpleConfig
	TalosConfig        *talosconfigmanager.Configs
	FirstActivityShown *bool
	DockerInvoker      DockerClientInvoker
}

StageParams bundles all parameters needed for registry stage execution. This reduces code duplication between SetupMirrorRegistries and ConnectRegistriesToClusterNetwork.

Jump to

Keyboard shortcuts

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