Documentation
¶
Overview ¶
Package registryresolver provides OCI registry detection, resolution, and artifact push utilities.
Index ¶
- Constants
- Variables
- func DetectGitOpsEngine(ctx context.Context) (v1alpha1.GitOpsEngine, error)
- func FormatRegistryURL(host string, port int32, repository string) string
- type Info
- func DetectRegistryFromArgoCD(ctx context.Context) (*Info, error)
- func DetectRegistryFromConfig(cfg *v1alpha1.Cluster) (*Info, error)
- func DetectRegistryFromDocker(ctx context.Context, clusterName string) (*Info, error)
- func DetectRegistryFromFlux(ctx context.Context) (*Info, error)
- func DetectRegistryFromViper(v *viper.Viper) (*Info, error)
- func ResolveRegistry(ctx context.Context, opts ResolveRegistryOptions) (*Info, error)
- type PushOCIArtifactOptions
- type PushOCIArtifactResult
- type ResolveRegistryOptions
Constants ¶
const (
// ViperRegistryKey is the viper key for the registry flag/env var.
ViperRegistryKey = "registry"
)
Registry secret constants for GitOps engines.
Variables ¶
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.
var ErrExternalRegistryCredentialsIncomplete = errors.New(
"external registry credentials are incomplete: username is set but password is empty\n" +
" - ensure the token environment variable (e.g. GITHUB_TOKEN) is exported in the current environment\n" +
" - configure the external registry in your cluster config (spec.cluster.localRegistry.registry in ksail.yaml),\n" +
" for example via: ksail cluster init --local-registry 'user:token@host/repo'",
)
ErrExternalRegistryCredentialsIncomplete is returned when an external registry has a username but no password (e.g. GITHUB_ACTOR set but GITHUB_TOKEN missing).
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.
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 FormatRegistryURL ¶
FormatRegistryURL formats a registry URL using a pre-allocated byte buffer to avoid the intermediate allocations from net.JoinHostPort + strconv.Itoa + fmt.Sprintf. IPv6 addresses are wrapped in brackets per RFC 3986 (e.g., [::1]:5000).
Types ¶
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 ¶
DetectRegistryFromArgoCD tries to get registry URL from ArgoCD Application source.
func DetectRegistryFromConfig ¶
DetectRegistryFromConfig extracts registry info from ksail cluster configuration.
func DetectRegistryFromDocker ¶
DetectRegistryFromDocker tries to find a local registry Docker container.
func DetectRegistryFromFlux ¶
DetectRegistryFromFlux tries to get registry URL from FluxInstance sync configuration.
func DetectRegistryFromViper ¶
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. For external registries (e.g. GHCR) the entire build+push cycle is wrapped with higher-level retry logic to tolerate transient blips. 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.