package v1alpha1 import ( "time" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "edge-infra.dev/pkg/f8n/warehouse/cluster" "edge-infra.dev/pkg/k8s/meta" ) // Option describes options for constructing Warehouse K8s objects. If a specific // option only applies to a single type of Warehouse K8s object, it will be // ignored by the constructor. See individual option documentation for details. // +kubebuilder:object:generate=false type Option func(*options) // +kubebuilder:object:generate=false type options struct { apply ApplyOptions unpack UnpackOptions packagePullOptions PackagePullOptions labels map[string]string parameters map[string]string repo string artifact *Artifact // Shipment specific options artifacts []BaseArtifact // UnpackedPallet specific options owningShipment string deps []meta.LocalObjectReference } func makeOptions(opts ...Option) *options { o := &options{ apply: ApplyOptions{}, unpack: UnpackOptions{}, packagePullOptions: PackagePullOptions{}, parameters: make(map[string]string), } for _, opt := range opts { opt(o) } return o } // WithPrune enables object pruning. func WithPrune() Option { return func(o *options) { o.apply.Prune = true } } // WithRetryInterval configures how often failed reconciles are retried. func WithRetryInterval(t time.Duration) Option { return func(o *options) { o.apply.RetryInterval = &v1.Duration{Duration: t} } } // WithTimeout configures how long the controller will wait for the applied objects to // reconcile func WithTimeout(t time.Duration) Option { return func(o *options) { o.apply.Timeout = &v1.Duration{Duration: t} } } // WithInfra enables unpacking infra layers. func WithInfra() Option { return func(o *options) { o.unpack.Infra = true } } // WithRuntime enables unpacking runtime layers. func WithRuntime() Option { return func(o *options) { o.unpack.Runtime = true } } // WithCapabilities configures the runtime capabilities to unpack. func WithCapabilities(caps ...string) Option { return func(o *options) { o.unpack.Capabilities = caps } } // ForProvider controls the K8s cluster provider that we will unpack for. func ForProvider(p cluster.Provider) Option { return func(o *options) { o.unpack.Provider = p } } // WithUnpackOpts sets the entirety of spec.unpack func WithUnpackOpts(u UnpackOptions) Option { return func(o *options) { o.unpack = u } } // WithImagePullOpts sets the entirety of spec.imagePull func WithImagePullOpts(p PackagePullOptions) Option { return func(o *options) { o.packagePullOptions = p } } // WithParameters sets the inlined rendering parameters for both Shipments and // UnpackedPallets func WithParameters(parameters map[string]string) Option { return func(o *options) { o.parameters = parameters } } // WithLabels sets the K8s labels on the result object. func WithLabels(labels map[string]string) Option { return func(o *options) { o.labels = labels } } // FromRepo sets the repository the package will be pulled from. For // UnpackedPallets, this will override the repository provided via WithArtifact. func FromRepo(r string) Option { return func(o *options) { o.repo = r } } // WithArtifact sets spec.artifact for UnpackedPallets and will populate // spec.pallets with a single value and spec.repository for Shipments. // // FromRepo and WithArtifacts take precedence, allowing a partially specified // artifact to be provided to WithArtifact if FromRepo is also provided. func WithArtifact(a Artifact) Option { return func(o *options) { o.artifact = &a } } // ForShipment sets status.shipment for UnpackedPallets func ForShipment(shipment string) Option { return func(o *options) { o.owningShipment = shipment } } // WithDeps sets spec.dependsOn for UnpackedPallets func WithDeps(unpackedPallets ...string) Option { return func(o *options) { o.deps = make([]meta.LocalObjectReference, len(unpackedPallets)) for i, d := range unpackedPallets { o.deps[i] = meta.LocalObjectReference{Name: d} } } } // WithArtifacts sets spec.pallets for Shipments. func WithArtifacts(artifacts ...BaseArtifact) Option { return func(o *options) { o.artifacts = artifacts } }