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 DeleteClusterByName(ctx context.Context, r *tools.Resolver, name 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 ListDevrigClusters(ctx context.Context, r *tools.Resolver) ([]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) ListPods(ctx context.Context, kubeconfig string) ([]PodInfo, error)
- func (m *Manager) RegistryName() string
- type PodInfo
- 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 DeleteClusterByName ¶ added in v0.38.2
DeleteClusterByName deletes a k3d cluster and its paired registry by cluster name alone (the registry deletion is best-effort). Unlike Manager.Delete it needs no config or slug, so it can tear down an orphaned cluster discovered via ListDevrigClusters. The registry created alongside a "devrig-<slug>" cluster is named "k3d-devrig-<slug>-reg" — i.e. "k3d-<clustername>-reg".
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 ListDevrigClusters ¶ added in v0.38.2
ListDevrigClusters returns the names of all k3d clusters devrig manages (those named "devrig-*"), discovered via `k3d cluster list` regardless of any local state or registry entry. It exists so `devrig delete --all` can reap a cluster orphaned by a `devrig start` that was interrupted (e.g. Ctrl-C'd while hanging in cluster creation) before it ever recorded the instance — the registry-driven cleanup path can't see such a cluster, but k3d still can.
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).
A configured cluster.name is qualified with the slug's unique suffix so that two worktrees/checkouts of the same project (which share the same cluster.name) don't collide on the k3d cluster and container names on a shared Docker host. The slug already encodes the config path, so its suffix differs per checkout; the network and registry names are slug-derived for the same reason.
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) ListPods ¶ added in v0.40.0
ListPods returns all pods across all namespaces in the cluster.
func (*Manager) RegistryName ¶
RegistryName returns the k3d registry container name.
type PodInfo ¶ added in v0.40.0
type PodInfo struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Phase string `json:"phase"`
Ready string `json:"ready"`
Restarts int `json:"restarts"`
Age string `json:"age"`
}
PodInfo represents a Kubernetes pod in the cluster.
type RebuildFunc ¶
RebuildFunc is called with the context when a file change is detected.