cluster

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package cluster manages the k3d cluster lifecycle for devrig.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildAndDeploy

func BuildAndDeploy(
	ctx context.Context,
	r *tools.Resolver,
	name string,
	cfg *config.ClusterDeployConfig,
	cs *state.ClusterState,
	stateDir string,
) error

BuildAndDeploy builds an image, pushes it to the registry, and applies the service manifests. It updates cs with the new image tag. r resolves the kubectl binary.

func BuildImage

func BuildImage(
	ctx context.Context,
	name string,
	cfg *config.ClusterImageConfig,
	cs *state.ClusterState,
) (string, error)

BuildImage builds and pushes an image for a standalone image config (no deploy).

func InstallAddons

func InstallAddons(
	ctx context.Context,
	r *tools.Resolver,
	addons map[string]config.AddonConfig,
	cs *state.ClusterState,
	stateDir string,
) error

InstallAddons installs all configured addons in topological order, then starts port-forwards. ctx cancellation stops the port-forwards. r resolves the kubectl/helm binaries.

func KubectlApply

func KubectlApply(ctx context.Context, r *tools.Resolver, kubeconfig, path string) error

KubectlApply runs kubectl apply -f path with the given kubeconfig.

func KubectlApplyDir

func KubectlApplyDir(ctx context.Context, r *tools.Resolver, kubeconfig, path string, kustomize bool) error

KubectlApplyDir runs kubectl apply -f (or -k for kustomize) on a path.

func KubectlPortForward

func KubectlPortForward(ctx context.Context, r *tools.Resolver, kubeconfig, namespace, target string, localPort uint16)

KubectlPortForward starts a port-forward subprocess in the background. The caller is responsible for cancelling ctx to stop the forward.

func KubectlRollout

func KubectlRollout(ctx context.Context, r *tools.Resolver, kubeconfig, namespace, name string) error

KubectlRollout restarts a deployment by name in the given namespace.

func RegistryHostPort

func RegistryHostPort(containerName string) (uint16, error)

RegistryHostPort discovers the host-side port for the k3d registry container by inspecting its Docker port bindings.

func WaitForRegistry

func WaitForRegistry(ctx context.Context, port uint16) error

WaitForRegistry polls the registry's /v2/ endpoint until it responds 200.

func WatchAndRebuild

func WatchAndRebuild(ctx context.Context, contextDir string, rebuild RebuildFunc) error

WatchAndRebuild watches contextDir for changes and calls rebuild when files change. It debounces by 500ms and cancels in-progress rebuilds on new changes. It blocks until ctx is cancelled.

func WriteLogCollectorManifest

func WriteLogCollectorManifest(
	otlpEndpoint string,
	logsCfg *config.ClusterLogsConfig,
	stateDir string,
) (string, error)

WriteLogCollectorManifest writes a Fluent Bit DaemonSet manifest to stateDir/log-collector.yaml and returns the path.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager orchestrates the full cluster lifecycle.

func NewManager

func NewManager(cfg *config.ClusterConfig, resolver *tools.Resolver, slug, stateDir, network string) *Manager

NewManager creates a cluster manager. slug and network are the devrig project slug and Docker network name. resolver locates the k3d/kubectl/helm binaries; pass nil for defaults (managed, on-demand fetch disabled).

func (*Manager) ApplyRegistriesConfig

func (m *Manager) ApplyRegistriesConfig(ctx context.Context, stateDir string) error

ApplyRegistriesConfig writes a registries.yaml to the k3d data dir if external registries are configured, for mirror/auth support.

func (*Manager) ClusterName

func (m *Manager) ClusterName() string

ClusterName returns the k3d cluster name (dev-friendly if not configured).

func (*Manager) Delete

func (m *Manager) Delete(ctx context.Context) error

Delete removes the k3d cluster and (optionally) the registry.

func (*Manager) Ensure

func (m *Manager) Ensure(ctx context.Context) (*state.ClusterState, error)

Ensure creates the cluster if it doesn't exist, then returns the cluster state (kubeconfig path, registry info).

func (*Manager) KubeconfigPath

func (m *Manager) KubeconfigPath() string

KubeconfigPath returns the path where the kubeconfig is written.

func (*Manager) RegistryName

func (m *Manager) RegistryName() string

RegistryName returns the k3d registry container name.

type RebuildFunc

type RebuildFunc func(ctx context.Context) error

RebuildFunc is called with the context when a file change is detected.

Jump to

Keyboard shortcuts

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