diff --git a/README.md b/README.md index 66ca86c..ffba1ad 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ that extends Flux with advanced source composition and decomposition patterns. The source-watcher controller implements the [ArtifactGenerator](docs/README.md) API, which allows Flux users to: -- 🔗 **Compose** multiple Flux sources (GitRepository, OCIRepository, Bucket, HelmChart) into a single deployable artifact +- 🔗 **Compose** multiple Flux sources (GitRepository, OCIRepository, Bucket, HelmChart, ExternalArtifact) into a single deployable artifact - 📦 **Decompose** monorepos into multiple independent artifacts with separate deployment lifecycles - 🎯 **Optimize** reconciliation by only triggering updates when specific paths change - 🏗️ **Structure** complex deployments from distributed sources maintained by different teams diff --git a/api/v1beta1/artifactgenerator_types.go b/api/v1beta1/artifactgenerator_types.go index 2ab2302..4a39db4 100644 --- a/api/v1beta1/artifactgenerator_types.go +++ b/api/v1beta1/artifactgenerator_types.go @@ -83,7 +83,7 @@ type SourceReference struct { Namespace string `json:"namespace,omitempty"` // Kind of the source. - // +kubebuilder:validation:Enum=Bucket;GitRepository;OCIRepository;HelmChart + // +kubebuilder:validation:Enum=Bucket;GitRepository;OCIRepository;HelmChart;ExternalArtifact // +required Kind string `json:"kind"` } diff --git a/config/crd/bases/source.extensions.fluxcd.io_artifactgenerators.yaml b/config/crd/bases/source.extensions.fluxcd.io_artifactgenerators.yaml index 0c94867..bb755a9 100644 --- a/config/crd/bases/source.extensions.fluxcd.io_artifactgenerators.yaml +++ b/config/crd/bases/source.extensions.fluxcd.io_artifactgenerators.yaml @@ -159,6 +159,7 @@ spec: - GitRepository - OCIRepository - HelmChart + - ExternalArtifact type: string name: description: Name of the source. diff --git a/config/samples/source_v1beta1_artifactgenerator.yaml b/config/samples/source_v1beta1_artifactgenerator.yaml index 270eb44..02840c7 100644 --- a/config/samples/source_v1beta1_artifactgenerator.yaml +++ b/config/samples/source_v1beta1_artifactgenerator.yaml @@ -4,7 +4,7 @@ metadata: name: podinfo spec: # Sources is a list of references to Flux source-controller resources - # (GitRepository, OCIRepository, Bucket and HelmChart) that will be + # (GitRepository, OCIRepository, Bucket, HelmChart and ExternalArtifact) that will be # used to generate ExternalArtifact resources. sources: - alias: chart diff --git a/docs/spec/v1beta1/artifactgenerators.md b/docs/spec/v1beta1/artifactgenerators.md index 7fb9183..304b2f2 100644 --- a/docs/spec/v1beta1/artifactgenerators.md +++ b/docs/spec/v1beta1/artifactgenerators.md @@ -4,7 +4,7 @@ The ArtifactGenerator is an extension of Flux APIs that allows source composition and decomposition. It enables the generation of [ExternalArtifacts][externalartifact] from multiple sources -([GitRepositories][gitrepository], [OCIRepositories][ocirepository], [Buckets][bucket] and [HelmChart][helmchart]) +([GitRepositories][gitrepository], [OCIRepositories][ocirepository], [Buckets][bucket], [HelmCharts][helmchart] and [ExternalArtifacts][externalartifact]) or the splitting of a single source into multiple artifacts. ## Source Composition Example @@ -203,7 +203,7 @@ for artifact generation. Each source must specify: - `alias`: A unique identifier used to reference the source in copy operations. Alias names must be unique within the same ArtifactGenerator and can only contain alphanumeric characters, dashes and underscores. -- `kind`: The type of Flux source resource (`GitRepository`, `OCIRepository`, `Bucket` or `HelmChart`) +- `kind`: The type of Flux source resource (`GitRepository`, `OCIRepository`, `Bucket`, `HelmChart`, or `ExternalArtifact`) - `name`: The name of the source resource - `namespace` (optional): The namespace of the source resource if different from the ArtifactGenerator namespace diff --git a/internal/controller/artifactgenerator_controller.go b/internal/controller/artifactgenerator_controller.go index 4c9b68d..7da2e29 100644 --- a/internal/controller/artifactgenerator_controller.go +++ b/internal/controller/artifactgenerator_controller.go @@ -318,6 +318,16 @@ func (r *ArtifactGeneratorReconciler) observeSources(ctx context.Context, return nil, fmt.Errorf("unable to get source '%s': %w", namespacedName, err) } source = &chart + case sourcev1.ExternalArtifactKind: + var chart sourcev1.ExternalArtifact + err := r.Get(ctx, namespacedName, &chart) + if err != nil { + if apierrors.IsNotFound(err) { + return nil, err + } + return nil, fmt.Errorf("unable to get source '%s': %w", namespacedName, err) + } + source = &chart default: return nil, fmt.Errorf("source `%s` kind '%s' not supported", src.Name, src.Kind) diff --git a/internal/controller/artifactgenerator_manager.go b/internal/controller/artifactgenerator_manager.go index 6b94334..a261774 100644 --- a/internal/controller/artifactgenerator_manager.go +++ b/internal/controller/artifactgenerator_manager.go @@ -85,6 +85,11 @@ func (r *ArtifactGeneratorReconciler) SetupWithManager(ctx context.Context, handler.EnqueueRequestsFromMapFunc(r.requestsForSourceChange), builder.WithPredicates(sourceChangePredicate), ). + Watches( + &sourcev1.ExternalArtifact{}, + handler.EnqueueRequestsFromMapFunc(r.requestsForSourceChange), + builder.WithPredicates(sourceChangePredicate), + ). WithOptions(controller.Options{ RateLimiter: opts.RateLimiter, }).