source

package
v0.7.2 Latest Latest
Warning

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

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

Documentation

Overview

Package source contains Flux source-controller integration helpers.

Index

Constants

View Source
const (
	SourceKindOCIRepository = "OCIRepository"
	SourceKindGitRepository = "GitRepository"
	SourceKindBucket        = "Bucket"
)

Source kinds supported by Resolve.

View Source
const MaxArtifactSize int64 = 64 << 20

MaxArtifactSize is the maximum allowed artifact download size (64 MB).

View Source
const MaxTarFiles = 10000

MaxTarFiles is the maximum number of files allowed in a tar.gz archive.

View Source
const MaxZipFiles = 10000

MaxZipFiles is the maximum number of files allowed in a zip archive.

Variables

View Source
var ErrMissingCUEModule = errors.New("artifact does not contain a cue module")

ErrMissingCUEModule indicates the fetched artifact does not contain a CUE module.

View Source
var ErrSourceNotFound = errors.New("source not found")

ErrSourceNotFound indicates the referenced source object does not exist.

View Source
var ErrSourceNotReady = errors.New("source not ready")

ErrSourceNotReady indicates the source exists but is not ready.

View Source
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

func ValidateCUEModule(dir string) error

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 Release reconciler.

All three kinds produce tar.gz: GitRepository/Bucket bundle the repo tree as tar.gz natively, and OCIRepository artifacts for Release 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 ModuleRelease 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,
	releaseNamespace 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 releaseNamespace 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 (Release CR) should enable this.
	SkipRootCUEModuleValidation bool
}

FetchOptions controls extraction behavior for ArtifactFetcher.Fetch.

type Fetcher

type Fetcher interface {
	Fetch(ctx context.Context, artifactURL, artifactDigest, dir string, opts FetchOptions) error
}

Fetcher fetches a resolved source artifact into a local directory.

Jump to

Keyboard shortcuts

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