Documentation
¶
Overview ¶
Package cluster manages the k3d cluster lifecycle for devrig.
Index ¶
- func BuildAndDeploy(ctx context.Context, r *tools.Resolver, name string, ...) error
- func BuildImage(ctx context.Context, name string, cfg *config.ClusterImageConfig, ...) (string, error)
- func ImageBuildOrder(images map[string]config.ClusterImageConfig) ([]string, error)
- func InstallAddons(ctx context.Context, r *tools.Resolver, addons map[string]config.AddonConfig, ...) error
- func KubectlApply(ctx context.Context, r *tools.Resolver, kubeconfig, path string) error
- func KubectlApplyDir(ctx context.Context, r *tools.Resolver, kubeconfig, path string, ...) error
- func KubectlPortForward(ctx context.Context, r *tools.Resolver, kubeconfig, namespace, target string, ...)
- func KubectlRollout(ctx context.Context, r *tools.Resolver, kubeconfig, namespace, name string) error
- func RegistryHostPort(containerName string) (uint16, error)
- func WaitForRegistry(ctx context.Context, port uint16) error
- func WatchAndRebuild(ctx context.Context, contextDir string, rebuild RebuildFunc) error
- func WriteLogCollectorManifest(otlpEndpoint string, logsCfg *config.ClusterLogsConfig, stateDir string) (string, error)
- type Manager
- func (m *Manager) ApplyRegistriesConfig(ctx context.Context, stateDir string) error
- func (m *Manager) ClusterName() string
- func (m *Manager) Delete(ctx context.Context) error
- func (m *Manager) Ensure(ctx context.Context) (*state.ClusterState, error)
- func (m *Manager) KubeconfigPath() string
- func (m *Manager) RegistryName() string
- type RebuildFunc
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, configDir 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. configDir anchors the build context and manifest paths.
func BuildImage ¶
func BuildImage( ctx context.Context, name string, cfg *config.ClusterImageConfig, cs *state.ClusterState, configDir string, ) (string, error)
BuildImage builds and pushes an image for a standalone image config (no deploy). configDir is the directory of the devrig config file; the build context and dockerfile are resolved relative to it. build_args support {{ cluster.image.<name>.tag }} references to images already built (read from cs.DeployedServices). The resulting image tag is recorded in cs.
func ImageBuildOrder ¶ added in v0.34.3
func ImageBuildOrder(images map[string]config.ClusterImageConfig) ([]string, error)
ImageBuildOrder returns cluster image names ordered so that an image is built after every image it depends on. Dependencies come from explicit depends_on and from {{ cluster.image.<name>.tag }} references in build_args (e.g. a runtime image whose FROM is a base image built by devrig). Returns an error on a dependency cycle.
func InstallAddons ¶
func InstallAddons( ctx context.Context, r *tools.Resolver, addons map[string]config.AddonConfig, cs *state.ClusterState, stateDir string, configDir 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 ¶
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 ¶
RegistryHostPort discovers the host-side port for the k3d registry container by inspecting its Docker port bindings.
func WaitForRegistry ¶
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, configDir, network string) *Manager
NewManager creates a cluster manager. slug and network are the devrig project slug and Docker network name. configDir is the directory containing the devrig config file, used to resolve relative volume host paths. resolver locates the k3d/kubectl/helm binaries; pass nil for defaults (managed, on-demand fetch disabled).
func (*Manager) ApplyRegistriesConfig ¶
ApplyRegistriesConfig writes a registries.yaml to the k3d data dir if external registries are configured, for mirror/auth support.
func (*Manager) ClusterName ¶
ClusterName returns the k3d cluster name (dev-friendly if not configured).
func (*Manager) Ensure ¶
Ensure creates the cluster if it doesn't exist, then returns the cluster state (kubeconfig path, registry info).
func (*Manager) KubeconfigPath ¶
KubeconfigPath returns the path where the kubeconfig is written.
func (*Manager) RegistryName ¶
RegistryName returns the k3d registry container name.
type RebuildFunc ¶
RebuildFunc is called with the context when a file change is detected.