Skip to content

Commit

Permalink
Merge pull request #945 from fluxcd/enable-hc-sources
Browse files Browse the repository at this point in the history
Add support for `HelmChart` as chartRef
  • Loading branch information
souleb authored Apr 23, 2024
2 parents 5e760db + 8b95f35 commit 9f82dde
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ jobs:
kubectl -n install-create-target-ns get deployment install-create-target-ns-install-create-target-ns-podinfo
kubectl -n helm-system delete -f config/testdata/install-create-target-ns
- name: Run install from helmChart test
run: |
kubectl -n helm-system apply -f config/testdata/install-from-hc-source
kubectl -n helm-system wait helmreleases/podinfo-from-hc --for=condition=ready --timeout=4m
kubectl -n helm-system delete -f config/testdata/install-from-hc-source
- name: Run install from ocirepo test
run: |
kubectl -n helm-system apply -f config/testdata/install-from-ocirepo-source
Expand Down
2 changes: 1 addition & 1 deletion api/v2beta2/reference_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type CrossNamespaceSourceReference struct {
APIVersion string `json:"apiVersion,omitempty"`

// Kind of the referent.
// +kubebuilder:validation:Enum=OCIRepository
// +kubebuilder:validation:Enum=OCIRepository;HelmChart
// +required
Kind string `json:"kind"`

Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ spec:
description: Kind of the referent.
enum:
- OCIRepository
- HelmChart
type: string
name:
description: Name of the referent.
Expand Down
29 changes: 29 additions & 0 deletions config/testdata/install-from-hc-source/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
metadata:
name: podinfo-hc
spec:
chart: podinfo
version: '6.2.1'
sourceRef:
kind: HelmRepository
name: podinfo-oci
interval: 30s
verify:
provider: cosign
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: podinfo-from-hc
spec:
chartRef:
kind: HelmChart
name: podinfo-hc
interval: 30s
values:
resources:
requests:
cpu: 100m
memory: 64Mi
51 changes: 43 additions & 8 deletions docs/spec/v2beta2/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,17 @@ HelmRelease object.

### Chart reference

`.spec.chartRef` is an optional field used to refer to an [OCIRepository resource](https://fluxcd.io/flux/components/source/ocirepositories/)
`.spec.chartRef` is an optional field used to refer to an [OCIRepository resource](https://fluxcd.io/flux/components/source/ocirepositories/) or a [HelmChart resource](https://fluxcd.io/flux/components/source/helmcharts/)
from which to fetch the Helm chart. The chart is fetched by the controller with the
information provided by `.status.artifact` of the OCIRepository.
information provided by `.status.artifact` of the referenced resource.

The chart version of the last release attempt is reported in `.status.lastAttemptedRevision`.
The version is in the format `<version>+<digest[0:12]>`. The digest of the OCI artifact
is appended to the version to ensure that a change in the artifact content triggers
a new release. The controller will automatically perform a Helm upgrade when the
OCIRepository detects a new digest in the OCI artifact stored in registry, even if
the version inside `Chart.yaml` is unchanged.
For a referenced resource of `kind OCIRepository`, the chart version of the last
release attempt is reported in `.status.lastAttemptedRevision`. The version is in
the format `<version>+<digest[0:12]>`. The digest of the OCI artifact is appended
to the version to ensure that a change in the artifact content triggers a new release.
The controller will automatically perform a Helm upgrade when the `OCIRepository`
detects a new digest in the OCI artifact stored in registry, even if the version
inside `Chart.yaml` is unchanged.

**Warning:** One of `.spec.chart` or `.spec.chartRef` must be set, but not both.
When switching from `.spec.chart` to `.spec.chartRef`, the controller will perform
Expand All @@ -225,6 +226,8 @@ references with the `--no-cross-namespace-refs=true` controller flag. When this
set, the HelmRelease can only refer to OCIRepositories in the same namespace as the
HelmRelease object.

#### OCIRepository reference example

```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: OCIRepository
Expand Down Expand Up @@ -252,6 +255,38 @@ spec:
replicaCount: 2
```

#### HelmChart reference example

```yaml
apiVersion: source.toolkit.fluxcd.io/v1beta2
kind: HelmChart
metadata:
name: podinfo
namespace: default
spec:
interval: 5m0s
chart: podinfo
reconcileStrategy: ChartVersion
sourceRef:
kind: HelmRepository
name: podinfo
version: '5.*'
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: podinfo
namespace: default
spec:
interval: 10m
chartRef:
kind: HelmChart
name: podinfo
namespace: default
values:
replicaCount: 2
```

### Release name

`.spec.releaseName` is an optional field used to specify the name of the Helm
Expand Down
Loading

0 comments on commit 9f82dde

Please sign in to comment.