Documentation
¶
Overview ¶
Package source contains Flux source-controller integration helpers.
Index ¶
Constants ¶
const ( SourceKindOCIRepository = "OCIRepository" SourceKindGitRepository = "GitRepository" SourceKindBucket = "Bucket" )
Source kinds supported by Resolve.
const MaxArtifactSize int64 = 64 << 20
MaxArtifactSize is the maximum allowed artifact download size (64 MB).
const MaxTarFiles = 10000
MaxTarFiles is the maximum number of files allowed in a tar.gz archive.
const MaxZipFiles = 10000
MaxZipFiles is the maximum number of files allowed in a zip archive.
Variables ¶
var ErrMissingCUEModule = errors.New("artifact does not contain a cue module")
ErrMissingCUEModule indicates the fetched artifact does not contain a CUE module.
var ErrSourceNotFound = errors.New("source not found")
ErrSourceNotFound indicates the referenced source object does not exist.
var ErrSourceNotReady = errors.New("source not ready")
ErrSourceNotReady indicates the source exists but is not ready.
var ErrUnsupportedSourceKind = errors.New("unsupported source kind")
ErrUnsupportedSourceKind indicates the source reference kind is not one of the supported Flux source kinds (OCIRepository, GitRepository, Bucket).
Functions ¶
func ValidateCUEModule ¶
ValidateCUEModule checks that dir contains a valid CUE module layout. Currently validates that cue.mod/module.cue exists and is non-empty. Returns ErrMissingCUEModule on failure.
Types ¶
type ArchiveFormat ¶
type ArchiveFormat int
ArchiveFormat identifies the encoding of a Flux source artifact.
const ( // ArchiveFormatZip is used by Flux OCIRepository artifacts. ArchiveFormatZip ArchiveFormat = iota // ArchiveFormatTarGz is used by Flux GitRepository and Bucket artifacts. ArchiveFormatTarGz )
func FormatForKind ¶
func FormatForKind(_ string) ArchiveFormat
FormatForKind returns the archive format used by the given Flux source kind when consumed by the ModulePackage reconciler.
All three kinds produce tar.gz: GitRepository/Bucket bundle the repo tree as tar.gz natively, and OCIRepository artifacts for ModulePackage are expected to be published via `flux push artifact`, which emits `application/vnd.cncf.flux.content.v1.tar+gzip`.
The legacy zip format (used by `cue mod publish`) belongs to the ModuleInstance cue-native path and does NOT flow through this fetcher.
type ArtifactFetcher ¶
type ArtifactFetcher struct {
// HTTPClient is the HTTP client used for downloads. If nil, http.DefaultClient is used.
HTTPClient *http.Client
// MaxSize is the maximum artifact size in bytes. Defaults to MaxArtifactSize.
MaxSize int64
}
ArtifactFetcher downloads Flux source artifacts via HTTP and extracts them as either zip or tar.gz. Implements the Fetcher interface.
Zip is used by CUE OCI artifacts (despite URLs often ending in .tar.gz); tar.gz is used by GitRepository and Bucket artifacts. The caller selects the format via FetchOptions.
func (*ArtifactFetcher) Fetch ¶
func (f *ArtifactFetcher) Fetch(ctx context.Context, artifactURL, artifactDigest, dir string, opts FetchOptions) error
Fetch downloads the artifact from artifactURL, verifies its SHA-256 digest matches artifactDigest, and extracts it to dir using the format selected in opts. When opts.SkipRootCUEModuleValidation is false, ValidateCUEModule is called on dir after extraction.
type ArtifactRef ¶
type ArtifactRef struct {
// Kind is the source kind (OCIRepository, GitRepository, Bucket).
// Determines extraction format: OCIRepository → zip, others → tar.gz.
Kind string
// URL is the HTTP(S) address where the artifact can be fetched.
URL string
// Revision is the source revision string (e.g., "v0.0.1@sha256:abc...").
Revision string
// Digest is the artifact content digest (e.g., "sha256:abc...").
Digest string
}
ArtifactRef carries resolved artifact metadata from a Flux source object.
func Resolve ¶
func Resolve( ctx context.Context, c client.Client, sourceRef releasesv1alpha1.SourceReference, objectNamespace string, ) (*ArtifactRef, error)
Resolve looks up the Flux source referenced by sourceRef, validates its readiness, and extracts artifact metadata. Supports OCIRepository, GitRepository, and Bucket source kinds. The source is looked up in objectNamespace unless sourceRef.Namespace is set.
type FetchOptions ¶
type FetchOptions struct {
// Format selects the extraction format. Defaults to ArchiveFormatZip.
Format ArchiveFormat
// SkipRootCUEModuleValidation skips the post-extraction check that
// cue.mod/module.cue exists at the destination root. Callers that place
// the CUE module at a subdirectory (ModulePackage CR) should enable this.
SkipRootCUEModuleValidation bool
}
FetchOptions controls extraction behavior for ArtifactFetcher.Fetch.