registryresolver

package
v5.36.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package registryresolver provides OCI registry detection, resolution, and artifact push utilities.

Index

Constants

View Source
const (
	// ViperRegistryKey is the viper key for the registry flag/env var.
	ViperRegistryKey = "registry"
)

Registry secret constants for GitOps engines.

Variables

View Source
var (
	// ErrNoRegistryFound is returned when no registry can be detected from any source.
	ErrNoRegistryFound = errors.New(
		"unable to detect registry; provide --registry flag, set KSAIL_REGISTRY, or configure local-registry",
	)
	// ErrViperNil is returned when a nil viper instance is provided.
	ErrViperNil = errors.New("viper instance is nil")
	// ErrRegistryNotSet is returned when registry is not set via flag or environment.
	ErrRegistryNotSet = errors.New("registry not set via flag or environment variable")
	// ErrLocalRegistryNotConfigured is returned when local registry is not in config.
	ErrLocalRegistryNotConfigured = errors.New("local registry not configured in ksail.yaml")
	// ErrFluxNoSyncURL is returned when FluxInstance has no sync.url.
	ErrFluxNoSyncURL = errors.New("FluxInstance has no sync.url configured")
	// ErrArgoCDNoRepoURL is returned when ArgoCD Application has no source.repoURL.
	ErrArgoCDNoRepoURL = errors.New("ArgoCD Application has no source.repoURL configured")
	// ErrEmptyOCIURL is returned when an empty OCI URL is provided.
	ErrEmptyOCIURL = errors.New("empty OCI URL")
)

Static errors for registry detection.

View Source
var ErrNoGitOpsEngine = errors.New(
	"no GitOps engine detected in cluster; " +
		"create a cluster with '--gitops-engine Flux|ArgoCD' during cluster init",
)

ErrNoGitOpsEngine is returned when no GitOps engine is detected.

View Source
var ErrNoLocalRegistry = errors.New(
	"no running local registry found; " +
		"create a cluster with '--local-registry' during cluster init",
)

ErrNoLocalRegistry is returned when no local registry container is found.

Functions

func DetectGitOpsEngine

func DetectGitOpsEngine(ctx context.Context) (v1alpha1.GitOpsEngine, error)

DetectGitOpsEngine checks if Flux or ArgoCD is deployed in the cluster.

func DetectLocalRegistryPort

func DetectLocalRegistryPort(ctx context.Context) (int32, error)

DetectLocalRegistryPort finds the host port of a running local-registry container. It checks for cluster-prefixed registries (e.g., "kind-local-registry", "k3d-default-local-registry") by searching for containers matching the "*-local-registry" pattern. Both KSail-managed registries (with labels) and K3d-managed registries are detected.

func FormatRegistryURL

func FormatRegistryURL(host string, port int32, repository string) string

FormatRegistryURL formats a registry URL using net.JoinHostPort for proper host:port handling.

Types

type ClusterEnvironment

type ClusterEnvironment struct {
	RegistryPort int32
	GitOpsEngine v1alpha1.GitOpsEngine
}

ClusterEnvironment holds auto-detected cluster configuration from the running environment.

func DetectClusterEnvironment

func DetectClusterEnvironment(ctx context.Context) (*ClusterEnvironment, error)

DetectClusterEnvironment auto-detects the registry port and GitOps engine from the running Docker containers and Kubernetes cluster.

type Info

type Info struct {
	Host       string
	Port       int32
	Repository string
	Tag        string
	Username   string
	Password   string
	// IsExternal is true if the registry is external (e.g., ghcr.io) vs local Docker registry
	IsExternal bool
	// Source describes where the registry info was detected from
	Source string
}

Info contains detected registry information.

func DetectRegistryFromArgoCD

func DetectRegistryFromArgoCD(ctx context.Context) (*Info, error)

DetectRegistryFromArgoCD tries to get registry URL from ArgoCD Application source.

func DetectRegistryFromConfig

func DetectRegistryFromConfig(cfg *v1alpha1.Cluster) (*Info, error)

DetectRegistryFromConfig extracts registry info from ksail cluster configuration.

func DetectRegistryFromDocker

func DetectRegistryFromDocker(ctx context.Context, clusterName string) (*Info, error)

DetectRegistryFromDocker tries to find a local registry Docker container.

func DetectRegistryFromFlux

func DetectRegistryFromFlux(ctx context.Context) (*Info, error)

DetectRegistryFromFlux tries to get registry URL from FluxInstance sync configuration.

func DetectRegistryFromViper

func DetectRegistryFromViper(v *viper.Viper) (*Info, error)

DetectRegistryFromViper checks for registry configuration from a Viper instance. This handles both --registry flag and KSAIL_REGISTRY environment variable since Viper binds them together.

func ResolveRegistry

func ResolveRegistry(ctx context.Context, opts ResolveRegistryOptions) (*Info, error)

ResolveRegistry resolves registry configuration using a priority-based approach. Priority order: 1. CLI flag or env var via Viper (--registry / KSAIL_REGISTRY). 2. Config file (ksail.yaml localRegistry). 3. Cluster GitOps resources (FluxInstance or ArgoCD Application). 4. Docker containers (matching cluster name). 5. Error (no registry found).

type PushOCIArtifactOptions

type PushOCIArtifactOptions struct {
	// ClusterConfig for resolving registry and gitops engine
	ClusterConfig *v1alpha1.Cluster
	// ClusterName for registry resolution
	ClusterName string
	// SourceDir is the directory containing manifests to push
	SourceDir string
	// Ref is the artifact tag/version (defaults to "dev")
	Ref string
	// Validate enables manifest validation before pushing
	Validate bool
}

PushOCIArtifactOptions contains parameters for pushing OCI artifacts.

type PushOCIArtifactResult

type PushOCIArtifactResult struct {
	// Pushed indicates if an artifact was actually pushed.
	Pushed bool
	// Empty indicates if an empty artifact was pushed (source directory was missing).
	Empty bool
}

PushOCIArtifactResult contains the result of a push operation.

func PushOCIArtifact

func PushOCIArtifact(
	ctx context.Context,
	opts PushOCIArtifactOptions,
) (*PushOCIArtifactResult, error)

PushOCIArtifact builds and pushes an OCI artifact to the configured registry. This function reuses the core logic from `ksail workload push` for consistency. The ctx parameter must be non-nil. If the source directory doesn't exist, an empty OCI artifact is pushed instead. Returns a result indicating whether an artifact was actually pushed.

type ResolveRegistryOptions

type ResolveRegistryOptions struct {
	// Viper is the viper instance with bound flags and env vars.
	// If provided, it's used to resolve registry from --registry flag or KSAIL_REGISTRY env var.
	Viper *viper.Viper
	// ClusterConfig is the parsed ksail.yaml configuration
	ClusterConfig *v1alpha1.Cluster
	// ClusterName is the name of the cluster (used for Docker container lookup)
	ClusterName string
}

ResolveRegistryOptions contains configuration for registry resolution.

Jump to

Keyboard shortcuts

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