Skip to content

Commit 2512976

Browse files
authored
Merge pull request #297 from renatovassao/rv/helm-chart-support
Add HelmChart support
2 parents 1b5dd51 + 652d675 commit 2512976

9 files changed

Lines changed: 29 additions & 7 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config/crd/bases/ocirepositories.yaml
2121
config/crd/bases/gitrepositories.yaml
2222
config/crd/bases/buckets.yaml
2323
config/crd/bases/externalartifacts.yaml
24+
config/crd/bases/helmcharts.yaml
2425

2526
# Release manifests generated at build time
2627
config/release/

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SOURCE_CRD_VER=$(BUILD_DIR)/.src-crd-$(SOURCE_VER)
3030
GITREPO_CRD ?= config/crd/bases/gitrepositories.yaml
3131
BUCKET_CRD ?= config/crd/bases/buckets.yaml
3232
OCIREPO_CRD ?= config/crd/bases/ocirepositories.yaml
33+
HELMCHART_CRD ?= config/crd/bases/helmcharts.yaml
3334
EA_CRD ?= config/crd/bases/externalartifacts.yaml
3435

3536
all: manager
@@ -65,15 +66,18 @@ $(BUCKET_CRD):
6566
$(OCIREPO_CRD):
6667
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER}/config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml -o $(OCIREPO_CRD)
6768

69+
$(HELMCHART_CRD):
70+
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER}/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml -o $(HELMCHART_CRD)
71+
6872
$(EA_CRD):
6973
curl -s https://raw.githubusercontent.com/fluxcd/source-controller/${SOURCE_VER}/config/crd/bases/source.toolkit.fluxcd.io_externalartifacts.yaml -o $(EA_CRD)
7074

7175
# Download the CRDs the controller depends on
72-
download-crd-deps: $(SOURCE_CRD_VER) $(GITREPO_CRD) $(BUCKET_CRD) $(OCIREPO_CRD) $(EA_CRD)
76+
download-crd-deps: $(SOURCE_CRD_VER) $(GITREPO_CRD) $(BUCKET_CRD) $(OCIREPO_CRD) $(HELMCHART_CRD) $(EA_CRD)
7377

7478
# Delete the downloaded CRD dependencies.
7579
cleanup-crd-deps:
76-
rm -f $(GITREPO_CRD) $(BUCKET_CRD) $(OCIREPO_CRD) $(EA_CRD)
80+
rm -f $(GITREPO_CRD) $(BUCKET_CRD) $(OCIREPO_CRD) $(HELMCHART_CRD) $(EA_CRD)
7781

7882
# Install CRDs into a cluster
7983
install: manifests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ that extends Flux with advanced source composition and decomposition patterns.
1414
The source-watcher controller implements the [ArtifactGenerator](docs/README.md) API,
1515
which allows Flux users to:
1616

17-
- 🔗 **Compose** multiple Flux sources (GitRepository, OCIRepository, Bucket) into a single deployable artifact
17+
- 🔗 **Compose** multiple Flux sources (GitRepository, OCIRepository, Bucket, HelmChart) into a single deployable artifact
1818
- 📦 **Decompose** monorepos into multiple independent artifacts with separate deployment lifecycles
1919
- 🎯 **Optimize** reconciliation by only triggering updates when specific paths change
2020
- 🏗️ **Structure** complex deployments from distributed sources maintained by different teams

api/v1beta1/artifactgenerator_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type SourceReference struct {
8383
Namespace string `json:"namespace,omitempty"`
8484

8585
// Kind of the source.
86-
// +kubebuilder:validation:Enum=Bucket;GitRepository;OCIRepository
86+
// +kubebuilder:validation:Enum=Bucket;GitRepository;OCIRepository;HelmChart
8787
// +required
8888
Kind string `json:"kind"`
8989
}

config/crd/bases/source.extensions.fluxcd.io_artifactgenerators.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ spec:
158158
- Bucket
159159
- GitRepository
160160
- OCIRepository
161+
- HelmChart
161162
type: string
162163
name:
163164
description: Name of the source.

config/samples/source_v1beta1_artifactgenerator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metadata:
44
name: podinfo
55
spec:
66
# Sources is a list of references to Flux source-controller resources
7-
# (GitRepository, OCIRepository and Bucket) that will be
7+
# (GitRepository, OCIRepository, Bucket and HelmChart) that will be
88
# used to generate ExternalArtifact resources.
99
sources:
1010
- alias: chart

docs/spec/v1beta1/artifactgenerators.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The ArtifactGenerator is an extension of Flux APIs that allows source composition and decomposition.
66
It enables the generation of [ExternalArtifacts][externalartifact] from multiple sources
7-
([GitRepositories][gitrepository], [OCIRepositories][ocirepository] and [Buckets][bucket])
7+
([GitRepositories][gitrepository], [OCIRepositories][ocirepository], [Buckets][bucket] and [HelmChart][helmchart])
88
or the splitting of a single source into multiple artifacts.
99

1010
## Source Composition Example
@@ -203,7 +203,7 @@ for artifact generation. Each source must specify:
203203
- `alias`: A unique identifier used to reference the source in copy operations.
204204
Alias names must be unique within the same ArtifactGenerator and can only contain
205205
alphanumeric characters, dashes and underscores.
206-
- `kind`: The type of Flux source resource (`GitRepository`, `OCIRepository`, or `Bucket`)
206+
- `kind`: The type of Flux source resource (`GitRepository`, `OCIRepository`, `Bucket` or `HelmChart`)
207207
- `name`: The name of the source resource
208208
- `namespace` (optional): The namespace of the source resource if different from the ArtifactGenerator namespace
209209

@@ -462,3 +462,4 @@ the ArtifactGenerator name and namespace.
462462
[gitrepository]: https://github.com/fluxcd/source-controller/blob/main/docs/spec/v1/gitrepositories.md
463463
[ocirepository]: https://github.com/fluxcd/source-controller/blob/main/docs/spec/v1/ocirepositories.md
464464
[bucket]: https://github.com/fluxcd/source-controller/blob/main/docs/spec/v1/buckets.md
465+
[helmchart]: https://github.com/fluxcd/source-controller/blob/main/docs/spec/v1/helmcharts.md

internal/controller/artifactgenerator_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ func (r *ArtifactGeneratorReconciler) observeSources(ctx context.Context,
308308
return nil, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
309309
}
310310
source = &bucket
311+
case sourcev1.HelmChartKind:
312+
var chart sourcev1.HelmChart
313+
err := r.Get(ctx, namespacedName, &chart)
314+
if err != nil {
315+
if apierrors.IsNotFound(err) {
316+
return nil, err
317+
}
318+
return nil, fmt.Errorf("unable to get source '%s': %w", namespacedName, err)
319+
}
320+
source = &chart
311321
default:
312322
return nil, fmt.Errorf("source `%s` kind '%s' not supported",
313323
src.Name, src.Kind)

internal/controller/artifactgenerator_manager.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func (r *ArtifactGeneratorReconciler) SetupWithManager(ctx context.Context,
8080
handler.EnqueueRequestsFromMapFunc(r.requestsForSourceChange),
8181
builder.WithPredicates(sourceChangePredicate),
8282
).
83+
Watches(
84+
&sourcev1.HelmChart{},
85+
handler.EnqueueRequestsFromMapFunc(r.requestsForSourceChange),
86+
builder.WithPredicates(sourceChangePredicate),
87+
).
8388
WithOptions(controller.Options{
8489
RateLimiter: opts.RateLimiter,
8590
}).

0 commit comments

Comments
 (0)