builder

package
v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpstreamAlpine           string = "upstream-alpine"
	EnterpriseAlpine         string = "enterprise-alpine"
	EnterpriseDistroless     string = "enterprise-distroless"
	EnterpriseDistrolessFIPS string = "enterprise-distroless-fips"
)

Variables

View Source
var AllComponents = append(DefaultComponents,
	"image-reflector-controller",
	"image-automation-controller",
	"source-watcher",
)

AllComponents defines all available Flux 2.7+ controllers.

View Source
var DefaultComponents = []string{
	"source-controller",
	"kustomize-controller",
	"helm-controller",
	"notification-controller",
}

DefaultComponents defines the default set of Flux controllers.

Functions

func BuildResource added in v0.14.0

func BuildResource(tmpl *apix.JSON, inputSet map[string]any) (*unstructured.Unstructured, error)

BuildResource builds a Kubernetes resource from a JSON template using the provided inputs. Template functions are provided by the slim-sprig library https://go-task.github.io/slim-sprig/. In addition, the slugify function is available to generate slugs from strings using https://github.com/gosimple/slug/. And for readability, a toYaml function is available to encode an input value into a YAML string.

func BuildResourceSet added in v0.14.0

func BuildResourceSet(yamlTemplate string, templates []*apix.JSON, combinedInputs inputs.Combined) ([]*unstructured.Unstructured, error)

BuildResourceSet builds a list of Kubernetes resources from a YAML template, a list of JSON templates and the given combined inputs. The resulting objects are deduplicated by apiVersion, kind, namespace and name, with the objects built from the JSON templates taking precedence over the ones built from the YAML template.

func BuildResourcesFromYAML added in v0.14.0

func BuildResourcesFromYAML(yamlTemplate string, inputSet map[string]any) ([]*unstructured.Unstructured, error)

BuildResourcesFromYAML builds a list of Kubernetes resources from a multi-doc YAML template using the same templating functions as BuildResource.

func CheckMinimumVersion added in v0.28.0

func CheckMinimumVersion(fluxVersion, minimumVersion string) error

CheckMinimumVersion checks if the given Flux version is greater than or equal to the minimum required version.

func ExtractVersionDigest added in v0.28.0

func ExtractVersionDigest(input string) (string, string, error)

ExtractVersionDigest extracts the version and digest from the given string. The input string is expected to be in one of the following formats: - "proto://host:port/org/app:vX.Y.Z@sha256:hex" - "host:port/org/app:vX.Y.Z@sha256:hex" - "host/org/app:vX.Y.Z" - "vX.Y.Z-RC.N@sha256:hex" - "vX.Y.Z" This function returns the version and optionally the digest as separate strings. An error is returned if the input string does not conform to the expected patterns.

func FlattenSteps added in v0.53.0

func FlattenSteps(steps []StepBuildResult) []*unstructured.Unstructured

FlattenSteps returns the objects of all the given steps as a single slice, preserving the step order. The flattened slice shares the object pointers with the step slices, so in-place metadata mutations performed on the flattened objects are visible per step.

func GetArtifactDigest added in v0.12.0

func GetArtifactDigest(ctx context.Context, ociURL string, keyChain authn.Keychain) (string, error)

GetArtifactDigest looks up an artifact from an OCI repository and returns the digest of the artifact.

func GetProfileClusterSize added in v0.27.0

func GetProfileClusterSize(size string) string

GetProfileClusterSize returns a patch that configures the Flux controllers for a specific cluster size.

func GetProfileClusterType added in v0.27.0

func GetProfileClusterType(clusterType string) string

GetProfileClusterType returns a patch that configures the Flux controllers for a specific Kubernetes distribution.

func GetProfileMultitenant added in v0.27.0

func GetProfileMultitenant(defaultSA string) string

GetProfileMultitenant returns a patch to enable multitenancy in the Flux controllers.

func GetProfileMultitenantWorkloadIdentity added in v0.29.0

func GetProfileMultitenantWorkloadIdentity(cluster fluxcdv1.Cluster) string

GetProfileMultitenantWorkloadIdentity returns a patch to enable multitenant workload identity in the Flux controllers through the feature gate.

func GetProfileObjectLevelWorkloadIdentity added in v0.29.0

func GetProfileObjectLevelWorkloadIdentity(controllers []string, enabled bool) string

GetProfileObjectLevelWorkloadIdentity returns a patch to enable object level workload identity in the Flux controllers through the feature gate.

func IsCompatibleVersion

func IsCompatibleVersion(fromVer, toVer string) error

IsCompatibleVersion checks if the version upgrade is compatible. It returns an error if a downgrade to a lower minor version is attempted.

func IsMinorUpgrade added in v0.31.0

func IsMinorUpgrade(fromVer, toVer string) (bool, error)

IsMinorUpgrade checks if the version upgrade is a minor version upgrade. It returns true if the major version is the same and the minor version is greater.

func MatchVersion

func MatchVersion(dataDir, semverRange string) (string, error)

MatchVersion returns the latest version dir path that matches the given semver range.

func MatchVersionWithEmbedded added in v0.54.0

func MatchVersionWithEmbedded(dataDir, embeddedDataDir, semverRange string) (string, error)

MatchVersionWithEmbedded returns the latest version dir that matches the given semver range and belongs to a Flux minor version present in the embedded version directory bundled with the running operator image.

func MkdirTempAbs

func MkdirTempAbs(dir, pattern string) (string, error)

MkdirTempAbs creates a tmp dir and returns the absolute path to the dir. This is required since certain OSes like MacOS create temporary files in e.g. `/private/var`, to which `/var` is a symlink.

func PullArtifact added in v0.5.0

func PullArtifact(ctx context.Context, ociURL, dstDir string, keyChain authn.Keychain) (string, error)

PullArtifact downloads an artifact from an OCI repository and extracts the content of the first tgz layer to the given destination directory. It returns the digest of the artifact.

func ValidateResourceSetSpec added in v0.53.0

func ValidateResourceSetSpec(spec fluxcdv1.ResourceSetSpec) error

ValidateResourceSetSpec validates that steps are not set together with resources or resourcesTemplate, and that each step sets at least one of resources or resourcesTemplate. The rules mirror the CRD CEL rules on api/v1 ResourceSetSpec and ResourceSetStep, enforcing them for offline builds (CLI) and for clusters running a CRD version without the rules. The validation is render-independent so that callers can reject an invalid spec even when no resources are built, e.g. when the input providers return no inputs.

Types

type ArtifactStorage added in v0.2.0

type ArtifactStorage struct {
	Class string
	Size  string
}

ArtifactStorage represents the source-controller PVC.

type ComponentImage added in v0.1.0

type ComponentImage struct {
	Name       string
	Repository string
	Tag        string
	Digest     string
}

ComponentImage represents a container image used by a component.

func ExtractComponentImages added in v0.1.0

func ExtractComponentImages(srcDir string, opts Options) ([]ComponentImage, error)

ExtractComponentImages reads the source directory and extracts the container images from the components manifests.

func ExtractComponentImagesFromObjects added in v0.28.0

func ExtractComponentImagesFromObjects(objects []*unstructured.Unstructured, opts Options) ([]ComponentImage, error)

ExtractComponentImagesFromObjects extracts the container images from the Deployment objects in the provided slice of unstructured objects. It returns a slice of ComponentImage containing the component name, repository, tag and digest (if available).

func ExtractComponentImagesWithDigest added in v0.5.0

func ExtractComponentImagesWithDigest(srcDir string, opts Options) (images []ComponentImage, err error)

ExtractComponentImagesWithDigest reads the source directory and extracts the container images with digest from the kustomize images patches.

type Options

type Options struct {
	Version                                         string
	VersionInfo                                     *VersionInfo
	Namespace                                       string
	Components                                      []string
	ComponentImages                                 []ComponentImage
	EventsAddr                                      string
	Registry                                        string
	Variant                                         string
	ImagePullSecret                                 string
	WatchAllNamespaces                              bool
	NetworkPolicy                                   bool
	LogLevel                                        string
	ClusterDomain                                   string
	TolerationKeys                                  []string
	Patches                                         string
	ArtifactStorage                                 *ArtifactStorage
	Sync                                            *Sync
	ShardingKey                                     string
	ShardingStorage                                 bool
	Shards                                          []string
	ShardName                                       string
	SourceAPIVersion                                string
	RemovePermissionForCreatingServiceAccountTokens bool
}

Options defines the builder configuration.

func MakeDefaultOptions

func MakeDefaultOptions() Options

MakeDefaultOptions returns the default builder configuration.

func (*Options) HasNotificationController added in v0.19.0

func (o *Options) HasNotificationController() bool

HasNotificationController returns true if the notification-controller is included in the selected components.

func (*Options) HasSourceWatcher added in v0.30.0

func (o *Options) HasSourceWatcher() bool

HasSourceWatcher returns true if the source-watcher is included in the selected components.

func (*Options) ValidateAndApplyWorkloadIdentityConfig added in v0.29.0

func (o *Options) ValidateAndApplyWorkloadIdentityConfig(cluster fluxcdv1.Cluster) error

ValidateAndApplyWorkloadIdentityConfig validates and applies the workload identity options based on the provided cluster configuration and Flux version in the Options struct.

func (*Options) ValidateAndPatchComponents added in v0.30.0

func (o *Options) ValidateAndPatchComponents() error

ValidateAndPatchComponents verifies that the selected components are valid and compatible with the specified Flux version. It also appends a patch to include the Flux Operator CRDs in the notification-controller configuration.

func (*Options) ValidateSync added in v0.49.0

func (o *Options) ValidateSync() error

ValidateSync validates the sync options against the Flux version in the Options struct, returning an error when the configuration is not supported.

type Result

type Result struct {
	Version         string
	Digest          string
	Revision        string
	Objects         []*unstructured.Unstructured
	ComponentImages []ComponentImage
}

Result holds the build result.

func Build

func Build(srcDir, tmpDir string, options Options) (*Result, error)

Build copies the source directory to a temporary directory, generates the required manifests and runs kustomize to build the final resources. The function returns a slice of unstructured objects.

type StepBuildResult added in v0.53.0

type StepBuildResult struct {
	// Name is the name of the step.
	Name string

	// Timeout is the health check timeout of the step, nil when
	// the step does not override the ResourceSet timeout.
	Timeout *metav1.Duration

	// Objects contains the Kubernetes resources built for the step.
	Objects []*unstructured.Unstructured
}

StepBuildResult holds the objects built for a single ResourceSet step.

func BuildResourceSetFromSpec added in v0.53.0

func BuildResourceSetFromSpec(spec fluxcdv1.ResourceSetSpec, combinedInputs inputs.Combined) ([]StepBuildResult, error)

BuildResourceSetFromSpec validates the given ResourceSet spec with ValidateResourceSetSpec and builds its resources using the combined inputs. When steps are set, the resources are built per step with BuildResourceSetSteps, otherwise the spec resources are built with BuildResourceSet and wrapped as a single anonymous step.

func BuildResourceSetSteps added in v0.53.0

func BuildResourceSetSteps(steps []fluxcdv1.ResourceSetStep, combinedInputs inputs.Combined) ([]StepBuildResult, error)

BuildResourceSetSteps builds the Kubernetes resources of each step using BuildResourceSet and the given combined inputs. The results preserve the order of the steps, including steps that build zero objects. A resource defined in multiple steps results in an error, while duplicates within a step follow the BuildResourceSet semantics. The step fields are expected to have been validated upfront with ValidateResourceSetSpec.

func (StepBuildResult) IsAnonymous added in v0.53.0

func (s StepBuildResult) IsAnonymous() bool

IsAnonymous returns true when the result is the single unnamed step wrapping the resources of a steps-less ResourceSet, in which case the step must not surface in user-facing messages to keep the steps-less behavior identical to the pre-steps releases.

type Sync added in v0.4.0

type Sync struct {
	Name       string
	Kind       string
	URL        string
	Ref        string
	Path       string
	Interval   string
	PullSecret string
	Provider   string
}

type VersionInfo added in v0.30.0

type VersionInfo struct {
	Major int
	Minor int
	Patch int
}

Jump to

Keyboard shortcuts

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