From a165ff63c199c954a24476b58d12ab34f638a1fa Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 31 Aug 2020 15:22:34 +0200 Subject: [PATCH] Support charts from GitRepository sources --- .github/workflows/e2e.yaml | 1 + api/v2alpha1/helmrelease_types.go | 37 +++--- api/v2alpha1/reference_types.go | 2 +- api/v2alpha1/zz_generated.deepcopy.go | 22 +++- .../helm.toolkit.fluxcd.io_helmreleases.yaml | 67 ++++++----- config/default/kustomization.yaml | 4 +- config/samples/helm_v2alpha1_helmrelease.yaml | 17 --- ...lm_v2alpha1_helmrelease_gitrepository.yaml | 18 +++ ...m_v2alpha1_helmrelease_helmrepository.yaml | 19 +++ .../source_v1alpha1_gitrepository.yaml | 9 ++ ...ml => source_v1alpha1_helmrepository.yaml} | 0 .../dependencies/helmrelease-backend.yaml | 13 +- .../dependencies/helmrelease-frontend.yaml | 13 +- .../install-fail-remediate/helmrelease.yaml | 13 +- .../install-fail-retry/helmrelease.yaml | 13 +- config/testdata/install-fail/helmrelease.yaml | 13 +- .../install-test-fail-ignore/helmrelease.yaml | 13 +- .../install-test-fail/helmrelease.yaml | 13 +- config/testdata/podinfo/gitrepository.yaml | 9 ++ config/testdata/podinfo/helmrelease-git.yaml | 18 +++ config/testdata/podinfo/helmrelease.yaml | 13 +- .../install.yaml | 13 +- .../upgrade.yaml | 13 +- .../upgrade-fail-remediate/install.yaml | 13 +- .../upgrade-fail-remediate/upgrade.yaml | 13 +- .../testdata/upgrade-fail-retry/install.yaml | 13 +- .../testdata/upgrade-fail-retry/upgrade.yaml | 13 +- config/testdata/upgrade-fail/install.yaml | 13 +- config/testdata/upgrade-fail/upgrade.yaml | 13 +- .../testdata/upgrade-test-fail/install.yaml | 13 +- .../testdata/upgrade-test-fail/upgrade.yaml | 13 +- config/testdata/valuesfrom/helmrelease.yaml | 13 +- controllers/helmrelease_controller.go | 17 +-- docs/api/helmrelease.md | 111 ++++++++++++++++-- docs/spec/v2alpha1/helmreleases.md | 33 +++--- go.mod | 10 +- go.sum | 22 +++- 37 files changed, 444 insertions(+), 219 deletions(-) delete mode 100644 config/samples/helm_v2alpha1_helmrelease.yaml create mode 100644 config/samples/helm_v2alpha1_helmrelease_gitrepository.yaml create mode 100644 config/samples/helm_v2alpha1_helmrelease_helmrepository.yaml create mode 100644 config/samples/source_v1alpha1_gitrepository.yaml rename config/samples/{source_v1alpha1_helmchart.yaml => source_v1alpha1_helmrepository.yaml} (100%) create mode 100644 config/testdata/podinfo/gitrepository.yaml create mode 100644 config/testdata/podinfo/helmrelease-git.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 2610cfa01..f5f7e88ac 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -61,6 +61,7 @@ jobs: run: | kubectl -n helm-system apply -f config/testdata/podinfo/ kubectl -n helm-system wait helmreleases/podinfo --for=condition=ready --timeout=4m + kubectl -n helm-system wait helmreleases/podinfo-git --for=condition=ready --timeout=4m - name: Run dependency tests run: | kubectl -n helm-system apply -f config/testdata/dependencies diff --git a/api/v2alpha1/helmrelease_types.go b/api/v2alpha1/helmrelease_types.go index 9c7d8e55c..39524adc2 100644 --- a/api/v2alpha1/helmrelease_types.go +++ b/api/v2alpha1/helmrelease_types.go @@ -32,7 +32,8 @@ const HelmReleaseFinalizer = "finalizers.fluxcd.io" // HelmReleaseSpec defines the desired state of HelmRelease. type HelmReleaseSpec struct { - // Chart defines the Helm chart name, version and repository. + // Chart defines the template of the v1alpha1.HelmChart that should be created + // for this HelmRelease. // +required Chart HelmChartTemplate `json:"chart"` @@ -139,41 +140,49 @@ func (in HelmReleaseSpec) GetUninstall() Uninstall { return *in.Uninstall } -// HelmChartTemplate defines the template from which the controller -// will generate a HelmChart object in the same namespace as the HelmRepository. +// HelmChartTemplate defines the template from which the controller will generate a +// v1alpha1.HelmChart object in the same namespace as the referenced v1alpha1.Source. type HelmChartTemplate struct { - // Name of the Helm chart, as made available by the referenced Helm repository. // +required - Name string `json:"name"` + Spec HelmChartTemplateSpec `json:"spec"` +} + +type HelmChartTemplateSpec struct { + // The name or path the Helm chart is available at in the SourceRef. + // +required + Chart string `json:"chart"` - // Version semver expression, defaults to latest when omitted. + // Version semver expression, ignored for charts from GitRepository sources. + // Defaults to latest when omitted. // +optional Version string `json:"version,omitempty"` - // The name and namespace of the source HelmRepository the chart is available at. + // The name and namespace of the v1alpha1.Source the chart is available at. // +required SourceRef CrossNamespaceObjectReference `json:"sourceRef"` - // Interval at which to check the Helm repository for chart updates. + // Interval at which to check the v1alpha1.Source for updates. // Defaults to 'HelmReleaseSpec.Interval'. // +optional Interval *metav1.Duration `json:"interval,omitempty"` } -// GetInterval returns the configured interval for the HelmChart, or the given default. +// GetInterval returns the configured interval for the v1alpha1.HelmChart, +// or the given default. func (in HelmChartTemplate) GetInterval(defaultInterval metav1.Duration) metav1.Duration { - if in.Interval == nil { + if in.Spec.Interval == nil { return defaultInterval } - return *in.Interval + return *in.Spec.Interval } -// GetNamespace returns the namespace targeted namespace for the HelmChart, or the given default. +// GetNamespace returns the namespace targeted namespace for the v1alpha1.HelmChart, +// or the given default. func (in HelmChartTemplate) GetNamespace(defaultNamespace string) string { - if in.SourceRef.Namespace == "" { + if in.Spec.SourceRef.Namespace == "" { return defaultNamespace } - return in.SourceRef.Namespace + return in.Spec.SourceRef.Namespace } // DeploymentAction defines a consistent interface for Install and Upgrade. diff --git a/api/v2alpha1/reference_types.go b/api/v2alpha1/reference_types.go index 0818c6507..8195f9a5d 100644 --- a/api/v2alpha1/reference_types.go +++ b/api/v2alpha1/reference_types.go @@ -24,7 +24,7 @@ type CrossNamespaceObjectReference struct { APIVersion string `json:"apiVersion,omitempty"` // Kind of the referent. - // +kubebuilder:validation:Enum=HelmRepository + // +kubebuilder:validation:Enum=HelmRepository;GitRepository // +required Kind string `json:"kind,omitempty"` diff --git a/api/v2alpha1/zz_generated.deepcopy.go b/api/v2alpha1/zz_generated.deepcopy.go index 2dffa35bf..a5684f369 100644 --- a/api/v2alpha1/zz_generated.deepcopy.go +++ b/api/v2alpha1/zz_generated.deepcopy.go @@ -59,6 +59,22 @@ func (in *CrossNamespaceObjectReference) DeepCopy() *CrossNamespaceObjectReferen // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HelmChartTemplate) DeepCopyInto(out *HelmChartTemplate) { + *out = *in + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartTemplate. +func (in *HelmChartTemplate) DeepCopy() *HelmChartTemplate { + if in == nil { + return nil + } + out := new(HelmChartTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *HelmChartTemplateSpec) DeepCopyInto(out *HelmChartTemplateSpec) { *out = *in out.SourceRef = in.SourceRef if in.Interval != nil { @@ -68,12 +84,12 @@ func (in *HelmChartTemplate) DeepCopyInto(out *HelmChartTemplate) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartTemplate. -func (in *HelmChartTemplate) DeepCopy() *HelmChartTemplate { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HelmChartTemplateSpec. +func (in *HelmChartTemplateSpec) DeepCopy() *HelmChartTemplateSpec { if in == nil { return nil } - out := new(HelmChartTemplate) + out := new(HelmChartTemplateSpec) in.DeepCopyInto(out) return out } diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index 9f3e591b9..00d5219eb 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -49,44 +49,51 @@ spec: description: HelmReleaseSpec defines the desired state of HelmRelease. properties: chart: - description: Chart defines the Helm chart name, version and repository. + description: Chart defines the template of the v1alpha1.HelmChart + that should be created for this HelmRelease. properties: - interval: - description: Interval at which to check the Helm repository for - chart updates. Defaults to 'HelmReleaseSpec.Interval'. - type: string - name: - description: Name of the Helm chart, as made available by the - referenced Helm repository. - type: string - sourceRef: - description: The name and namespace of the source HelmRepository - the chart is available at. + spec: properties: - apiVersion: - description: APIVersion of the referent. + chart: + description: The name or path the Helm chart is available + at in the SourceRef. type: string - kind: - description: Kind of the referent. - enum: - - HelmRepository + interval: + description: Interval at which to check the v1alpha1.Source + for updates. Defaults to 'HelmReleaseSpec.Interval'. type: string - name: - description: Name of the referent. - type: string - namespace: - description: Namespace of the referent. + sourceRef: + description: The name and namespace of the v1alpha1.Source + the chart is available at. + properties: + apiVersion: + description: APIVersion of the referent. + type: string + kind: + description: Kind of the referent. + enum: + - HelmRepository + - GitRepository + type: string + name: + description: Name of the referent. + type: string + namespace: + description: Namespace of the referent. + type: string + required: + - name + type: object + version: + description: Version semver expression, ignored for charts + from GitRepository sources. Defaults to latest when omitted. type: string required: - - name + - chart + - sourceRef type: object - version: - description: Version semver expression, defaults to latest when - omitted. - type: string required: - - name - - sourceRef + - spec type: object dependsOn: description: DependsOn may contain a list of HelmReleases that must diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index 651ea3ab3..0b3ccc066 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -5,6 +5,6 @@ resources: - ../crd - ../rbac - ../manager -- github.com/fluxcd/source-controller/config//crd?ref=v0.0.9 -- github.com/fluxcd/source-controller/config//manager?ref=v0.0.9 +- github.com/fluxcd/source-controller/config//crd?ref=v0.0.13 +- github.com/fluxcd/source-controller/config//manager?ref=v0.0.13 - namespace.yaml diff --git a/config/samples/helm_v2alpha1_helmrelease.yaml b/config/samples/helm_v2alpha1_helmrelease.yaml deleted file mode 100644 index 48ae48b91..000000000 --- a/config/samples/helm_v2alpha1_helmrelease.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: helm.toolkit.fluxcd.io/v2alpha1 -kind: HelmRelease -metadata: - name: podinfo -spec: - interval: 5m - chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m - test: - enable: true - rollback: - enable: true diff --git a/config/samples/helm_v2alpha1_helmrelease_gitrepository.yaml b/config/samples/helm_v2alpha1_helmrelease_gitrepository.yaml new file mode 100644 index 000000000..5bb21d618 --- /dev/null +++ b/config/samples/helm_v2alpha1_helmrelease_gitrepository.yaml @@ -0,0 +1,18 @@ +apiVersion: helm.toolkit.fluxcd.io/v2alpha1 +kind: HelmRelease +metadata: + name: podinfo-gitrepository +spec: + interval: 5m + chart: + spec: + chart: ./charts/podinfo + sourceRef: + kind: GitRepository + name: podinfo + interval: 1m + upgrade: + remediation: + remediateLastFailure: true + test: + enable: true diff --git a/config/samples/helm_v2alpha1_helmrelease_helmrepository.yaml b/config/samples/helm_v2alpha1_helmrelease_helmrepository.yaml new file mode 100644 index 000000000..4d471fa41 --- /dev/null +++ b/config/samples/helm_v2alpha1_helmrelease_helmrepository.yaml @@ -0,0 +1,19 @@ +apiVersion: helm.toolkit.fluxcd.io/v2alpha1 +kind: HelmRelease +metadata: + name: podinfo-helmrepository +spec: + interval: 5m + chart: + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m + upgrade: + remediation: + remediateLastFailure: true + test: + enable: true diff --git a/config/samples/source_v1alpha1_gitrepository.yaml b/config/samples/source_v1alpha1_gitrepository.yaml new file mode 100644 index 000000000..33b989544 --- /dev/null +++ b/config/samples/source_v1alpha1_gitrepository.yaml @@ -0,0 +1,9 @@ +apiVersion: source.toolkit.fluxcd.io/v1alpha1 +kind: GitRepository +metadata: + name: podinfo +spec: + interval: 1m + url: https://github.com/stefanprodan/podinfo + ref: + branch: master diff --git a/config/samples/source_v1alpha1_helmchart.yaml b/config/samples/source_v1alpha1_helmrepository.yaml similarity index 100% rename from config/samples/source_v1alpha1_helmchart.yaml rename to config/samples/source_v1alpha1_helmrepository.yaml diff --git a/config/testdata/dependencies/helmrelease-backend.yaml b/config/testdata/dependencies/helmrelease-backend.yaml index 193885078..0e25a9eab 100644 --- a/config/testdata/dependencies/helmrelease-backend.yaml +++ b/config/testdata/dependencies/helmrelease-backend.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: webapp - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: webapp + interval: 1m values: service: grpcService: backend diff --git a/config/testdata/dependencies/helmrelease-frontend.yaml b/config/testdata/dependencies/helmrelease-frontend.yaml index c3507bd30..e19e7d700 100644 --- a/config/testdata/dependencies/helmrelease-frontend.yaml +++ b/config/testdata/dependencies/helmrelease-frontend.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: webapp - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: webapp + interval: 1m dependsOn: - backend values: diff --git a/config/testdata/install-fail-remediate/helmrelease.yaml b/config/testdata/install-fail-remediate/helmrelease.yaml index 84931d9dc..44a2781dc 100644 --- a/config/testdata/install-fail-remediate/helmrelease.yaml +++ b/config/testdata/install-fail-remediate/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m install: remediation: remediateLastFailure: true diff --git a/config/testdata/install-fail-retry/helmrelease.yaml b/config/testdata/install-fail-retry/helmrelease.yaml index b38f759c2..90f0f6999 100644 --- a/config/testdata/install-fail-retry/helmrelease.yaml +++ b/config/testdata/install-fail-retry/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m install: remediation: retries: 1 diff --git a/config/testdata/install-fail/helmrelease.yaml b/config/testdata/install-fail/helmrelease.yaml index d1a216796..a565bb145 100644 --- a/config/testdata/install-fail/helmrelease.yaml +++ b/config/testdata/install-fail/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/install-test-fail-ignore/helmrelease.yaml b/config/testdata/install-test-fail-ignore/helmrelease.yaml index ca4974a0b..5e0ecbe51 100644 --- a/config/testdata/install-test-fail-ignore/helmrelease.yaml +++ b/config/testdata/install-test-fail-ignore/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m test: enable: true ignoreFailures: true diff --git a/config/testdata/install-test-fail/helmrelease.yaml b/config/testdata/install-test-fail/helmrelease.yaml index 42152b5c5..df30d0a13 100644 --- a/config/testdata/install-test-fail/helmrelease.yaml +++ b/config/testdata/install-test-fail/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m test: enable: true values: diff --git a/config/testdata/podinfo/gitrepository.yaml b/config/testdata/podinfo/gitrepository.yaml new file mode 100644 index 000000000..33b989544 --- /dev/null +++ b/config/testdata/podinfo/gitrepository.yaml @@ -0,0 +1,9 @@ +apiVersion: source.toolkit.fluxcd.io/v1alpha1 +kind: GitRepository +metadata: + name: podinfo +spec: + interval: 1m + url: https://github.com/stefanprodan/podinfo + ref: + branch: master diff --git a/config/testdata/podinfo/helmrelease-git.yaml b/config/testdata/podinfo/helmrelease-git.yaml new file mode 100644 index 000000000..4aa25b791 --- /dev/null +++ b/config/testdata/podinfo/helmrelease-git.yaml @@ -0,0 +1,18 @@ +apiVersion: helm.toolkit.fluxcd.io/v2alpha1 +kind: HelmRelease +metadata: + name: podinfo-git +spec: + interval: 5m + chart: + spec: + chart: ./charts/podinfo + sourceRef: + kind: GitRepository + name: podinfo + interval: 1m + values: + resources: + requests: + cpu: 100m + memory: 64Mi diff --git a/config/testdata/podinfo/helmrelease.yaml b/config/testdata/podinfo/helmrelease.yaml index fffdadbbf..a48c2053f 100644 --- a/config/testdata/podinfo/helmrelease.yaml +++ b/config/testdata/podinfo/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-fail-remediate-uninstall/install.yaml b/config/testdata/upgrade-fail-remediate-uninstall/install.yaml index 9a7ed56d5..faec5875d 100644 --- a/config/testdata/upgrade-fail-remediate-uninstall/install.yaml +++ b/config/testdata/upgrade-fail-remediate-uninstall/install.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-fail-remediate-uninstall/upgrade.yaml b/config/testdata/upgrade-fail-remediate-uninstall/upgrade.yaml index d3e02bb8f..2789ad2f6 100644 --- a/config/testdata/upgrade-fail-remediate-uninstall/upgrade.yaml +++ b/config/testdata/upgrade-fail-remediate-uninstall/upgrade.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m upgrade: remediation: remediateLastFailure: true diff --git a/config/testdata/upgrade-fail-remediate/install.yaml b/config/testdata/upgrade-fail-remediate/install.yaml index 9ae8ae28c..b111f914a 100644 --- a/config/testdata/upgrade-fail-remediate/install.yaml +++ b/config/testdata/upgrade-fail-remediate/install.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-fail-remediate/upgrade.yaml b/config/testdata/upgrade-fail-remediate/upgrade.yaml index 78c3c2f74..509ff2de1 100644 --- a/config/testdata/upgrade-fail-remediate/upgrade.yaml +++ b/config/testdata/upgrade-fail-remediate/upgrade.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m upgrade: remediation: remediateLastFailure: true diff --git a/config/testdata/upgrade-fail-retry/install.yaml b/config/testdata/upgrade-fail-retry/install.yaml index bb76d9305..50b6fa453 100644 --- a/config/testdata/upgrade-fail-retry/install.yaml +++ b/config/testdata/upgrade-fail-retry/install.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-fail-retry/upgrade.yaml b/config/testdata/upgrade-fail-retry/upgrade.yaml index 6e07f3dbe..cd6849685 100644 --- a/config/testdata/upgrade-fail-retry/upgrade.yaml +++ b/config/testdata/upgrade-fail-retry/upgrade.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m upgrade: remediation: retries: 1 diff --git a/config/testdata/upgrade-fail/install.yaml b/config/testdata/upgrade-fail/install.yaml index 03b05b46b..a00d2453d 100644 --- a/config/testdata/upgrade-fail/install.yaml +++ b/config/testdata/upgrade-fail/install.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-fail/upgrade.yaml b/config/testdata/upgrade-fail/upgrade.yaml index 785bc58c6..1ed7ba1bb 100644 --- a/config/testdata/upgrade-fail/upgrade.yaml +++ b/config/testdata/upgrade-fail/upgrade.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-test-fail/install.yaml b/config/testdata/upgrade-test-fail/install.yaml index 9115a16f7..fe9b5ea1f 100644 --- a/config/testdata/upgrade-test-fail/install.yaml +++ b/config/testdata/upgrade-test-fail/install.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m values: resources: requests: diff --git a/config/testdata/upgrade-test-fail/upgrade.yaml b/config/testdata/upgrade-test-fail/upgrade.yaml index 19aea060e..f7c21b33c 100644 --- a/config/testdata/upgrade-test-fail/upgrade.yaml +++ b/config/testdata/upgrade-test-fail/upgrade.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m test: enable: true values: diff --git a/config/testdata/valuesfrom/helmrelease.yaml b/config/testdata/valuesfrom/helmrelease.yaml index 97ee9ee9b..9015132d3 100644 --- a/config/testdata/valuesfrom/helmrelease.yaml +++ b/config/testdata/valuesfrom/helmrelease.yaml @@ -5,12 +5,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: valuesfrom - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: valuesfrom + interval: 1m valuesFrom: - kind: ConfigMap name: valuesfrom-config diff --git a/controllers/helmrelease_controller.go b/controllers/helmrelease_controller.go index 0e987531a..9f64f20cc 100644 --- a/controllers/helmrelease_controller.go +++ b/controllers/helmrelease_controller.go @@ -598,10 +598,11 @@ func helmChartFromTemplate(hr v2.HelmRelease) *sourcev1.HelmChart { Namespace: hr.Spec.Chart.GetNamespace(hr.Namespace), }, Spec: sourcev1.HelmChartSpec{ - Name: template.Name, - Version: template.Version, - HelmRepositoryRef: corev1.LocalObjectReference{ - Name: template.SourceRef.Name, + Chart: template.Spec.Chart, + Version: template.Spec.Version, + SourceRef: sourcev1.LocalHelmChartSourceReference{ + Name: template.Spec.SourceRef.Name, + Kind: template.Spec.SourceRef.Kind, }, Interval: template.GetInterval(hr.Spec.Interval), }, @@ -611,11 +612,13 @@ func helmChartFromTemplate(hr v2.HelmRelease) *sourcev1.HelmChart { func helmChartRequiresUpdate(hr v2.HelmRelease, chart sourcev1.HelmChart) bool { template := hr.Spec.Chart switch { - case template.Name != chart.Spec.Name: + case template.Spec.Chart != chart.Spec.Chart: return true - case template.Version != chart.Spec.Version: + case template.Spec.Version != chart.Spec.Version: return true - case template.SourceRef.Name != chart.Spec.HelmRepositoryRef.Name: + case template.Spec.SourceRef.Name != chart.Spec.SourceRef.Name: + return true + case template.Spec.SourceRef.Kind != chart.Spec.SourceRef.Kind: return true case template.GetInterval(hr.Spec.Interval) != chart.Spec.Interval: return true diff --git a/docs/api/helmrelease.md b/docs/api/helmrelease.md index cbdaf827c..a9a32d8b4 100644 --- a/docs/api/helmrelease.md +++ b/docs/api/helmrelease.md @@ -78,7 +78,8 @@ HelmChartTemplate -

Chart defines the Helm chart name, version and repository.

+

Chart defines the template of the v1alpha1.HelmChart that should be created +for this HelmRelease.

@@ -381,7 +382,7 @@ transition, complementing reason.

(Appears on: -HelmChartTemplate) +HelmChartTemplateSpec)

CrossNamespaceObjectReference contains enough information to let you locate the typed referenced object at cluster level.

@@ -454,8 +455,8 @@ string (Appears on: HelmReleaseSpec)

-

HelmChartTemplate defines the template from which the controller -will generate a HelmChart object in the same namespace as the HelmRepository.

+

HelmChartTemplate defines the template from which the controller will generate a +v1alpha1.HelmChart object in the same namespace as the referenced v1alpha1.Source.

@@ -468,13 +469,101 @@ will generate a HelmChart object in the same namespace as the HelmRepository.

+ + + +
-name
+spec
+ + +HelmChartTemplateSpec + + +
+
+
+ + + + + + + + + + + + + + + + + +
+chart
+ +string + +
+

The name or path the Helm chart is available at in the SourceRef.

+
+version
+ +string + +
+(Optional) +

Version semver expression, ignored for charts from GitRepository sources. +Defaults to latest when omitted.

+
+sourceRef
+ + +CrossNamespaceObjectReference + + +
+

The name and namespace of the v1alpha1.Source the chart is available at.

+
+interval
+ + +Kubernetes meta/v1.Duration + + +
+(Optional) +

Interval at which to check the v1alpha1.Source for updates. +Defaults to ‘HelmReleaseSpec.Interval’.

+
+
+
+
+

HelmChartTemplateSpec +

+

+(Appears on: +HelmChartTemplate) +

+
+
+ + + + + + + + + + @@ -486,7 +575,8 @@ string @@ -499,7 +589,7 @@ CrossNamespaceObjectReference @@ -513,7 +603,7 @@ Kubernetes meta/v1.Duration @@ -548,7 +638,8 @@ HelmChartTemplate diff --git a/docs/spec/v2alpha1/helmreleases.md b/docs/spec/v2alpha1/helmreleases.md index 24ada4d95..33e109423 100644 --- a/docs/spec/v2alpha1/helmreleases.md +++ b/docs/spec/v2alpha1/helmreleases.md @@ -494,8 +494,9 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' sourceRef: kind: HelmRepository name: podinfo @@ -519,8 +520,9 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' sourceRef: kind: HelmRepository name: podinfo @@ -555,12 +557,13 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' - sourceRef: - kind: HelmRepository - name: podinfo - interval: 1m + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m rollback: enable: true values: @@ -597,8 +600,9 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' sourceRef: kind: HelmRepository name: podinfo @@ -636,8 +640,9 @@ metadata: spec: interval: 5m chart: - name: podinfo - version: '^4.0.0' + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' sourceRef: kind: HelmRepository name: podinfo diff --git a/go.mod b/go.mod index e8f1c201e..4f547aff6 100644 --- a/go.mod +++ b/go.mod @@ -8,16 +8,16 @@ require ( github.com/fluxcd/helm-controller/api v0.0.5 github.com/fluxcd/pkg/lockedfile v0.0.5 github.com/fluxcd/pkg/recorder v0.0.5 - github.com/fluxcd/source-controller/api v0.0.9 + github.com/fluxcd/source-controller/api v0.0.13 github.com/go-logr/logr v0.1.0 github.com/onsi/ginkgo v1.12.1 github.com/onsi/gomega v1.10.1 go.uber.org/zap v1.13.0 helm.sh/helm/v3 v3.3.0 - k8s.io/api v0.18.4 - k8s.io/apimachinery v0.18.4 + k8s.io/api v0.18.8 + k8s.io/apimachinery v0.18.8 k8s.io/cli-runtime v0.18.4 - k8s.io/client-go v0.18.4 + k8s.io/client-go v0.18.6 rsc.io/letsencrypt v0.0.3 // indirect - sigs.k8s.io/controller-runtime v0.6.1 + sigs.k8s.io/controller-runtime v0.6.2 ) diff --git a/go.sum b/go.sum index 7843e0522..227434cb0 100644 --- a/go.sum +++ b/go.sum @@ -182,6 +182,7 @@ github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/evanphx/json-patch v0.0.0-20200808040245-162e5629780b/go.mod h1:NAJj0yf/KaRKURN6nyi7A9IZydMivZEm9oQLWNjfKDc= github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M= github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= @@ -194,8 +195,8 @@ github.com/fluxcd/pkg/lockedfile v0.0.5 h1:C3T8wfdff1UY1bvplmCkGOLrdMWJHO8Q8+tdl github.com/fluxcd/pkg/lockedfile v0.0.5/go.mod h1:uAtPUBId6a2RqO84MTH5HKGX0SbM1kNW3Wr/FhYyDVA= github.com/fluxcd/pkg/recorder v0.0.5 h1:D8qfupahIvh6ncCMn2yTHsrzG91S05sp4zdpsbKWeaU= github.com/fluxcd/pkg/recorder v0.0.5/go.mod h1:2UG6EroZ6ZbqmqoL8k/cQMe09e6A36WyH4t4UDUGyuU= -github.com/fluxcd/source-controller/api v0.0.9 h1:LDaC6JMWmxRMOhb+Q60OQZU2iiwvw2rNPHqxxfebKyI= -github.com/fluxcd/source-controller/api v0.0.9/go.mod h1:Q0bjU4/O1C4FoQT/O2YgGtJnoRWtrw4R/MowywCaDNg= +github.com/fluxcd/source-controller/api v0.0.13 h1:rf0uZ20OAN+yJVs0uHJUhw3n3ci9ZyjaLqt5Jt/5K9A= +github.com/fluxcd/source-controller/api v0.0.13/go.mod h1:PUe+EYQ/s+KPnz2iOCgdf+L6clM0SWkyvdXIpbfpkQE= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -397,6 +398,7 @@ github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -927,18 +929,32 @@ honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXe honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= k8s.io/api v0.18.4 h1:8x49nBRxuXGUlDlwlWd3RMY1SayZrzFfxea3UZSkFw4= k8s.io/api v0.18.4/go.mod h1:lOIQAKYgai1+vz9J7YcDZwC26Z0zQewYOGWdyIPUUQ4= +k8s.io/api v0.18.6/go.mod h1:eeyxr+cwCjMdLAmr2W3RyDI0VvTawSg/3RFFBEnmZGI= +k8s.io/api v0.18.8 h1:aIKUzJPb96f3fKec2lxtY7acZC9gQNDLVhfSGpxBAC4= +k8s.io/api v0.18.8/go.mod h1:d/CXqwWv+Z2XEG1LgceeDmHQwpUJhROPx16SlxJgERY= k8s.io/apiextensions-apiserver v0.18.4 h1:Y3HGERmS8t9u12YNUFoOISqefaoGRuTc43AYCLzWmWE= k8s.io/apiextensions-apiserver v0.18.4/go.mod h1:NYeyeYq4SIpFlPxSAB6jHPIdvu3hL0pc36wuRChybio= +k8s.io/apiextensions-apiserver v0.18.6 h1:vDlk7cyFsDyfwn2rNAO2DbmUbvXy5yT5GE3rrqOzaMo= +k8s.io/apiextensions-apiserver v0.18.6/go.mod h1:lv89S7fUysXjLZO7ke783xOwVTm6lKizADfvUM/SS/M= k8s.io/apimachinery v0.18.4 h1:ST2beySjhqwJoIFk6p7Hp5v5O0hYY6Gngq/gUYXTPIA= k8s.io/apimachinery v0.18.4/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko= +k8s.io/apimachinery v0.18.6/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko= +k8s.io/apimachinery v0.18.8 h1:jimPrycCqgx2QPearX3to1JePz7wSbVLq+7PdBTTwQ0= +k8s.io/apimachinery v0.18.8/go.mod h1:6sQd+iHEqmOtALqOFjSWp2KZ9F0wlU/nWm0ZgsYWMig= k8s.io/apiserver v0.18.4/go.mod h1:q+zoFct5ABNnYkGIaGQ3bcbUNdmPyOCoEBcg51LChY8= +k8s.io/apiserver v0.18.6/go.mod h1:Zt2XvTHuaZjBz6EFYzpp+X4hTmgWGy8AthNVnTdm3Wg= k8s.io/cli-runtime v0.18.4 h1:IUx7quIOb4gbQ4M+B1ksF/PTBovQuL5tXWzplX3t+FM= k8s.io/cli-runtime v0.18.4/go.mod h1:9/hS/Cuf7NVzWR5F/5tyS6xsnclxoPLVtwhnkJG1Y4g= k8s.io/client-go v0.18.4 h1:un55V1Q/B3JO3A76eS0kUSywgGK/WR3BQ8fHQjNa6Zc= k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g= +k8s.io/client-go v0.18.6 h1:I+oWqJbibLSGsZj8Xs8F0aWVXJVIoUHWaaJV3kUN/Zw= +k8s.io/client-go v0.18.6/go.mod h1:/fwtGLjYMS1MaM5oi+eXhKwG+1UHidUEXRh6cNsdO0Q= k8s.io/code-generator v0.18.4/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= +k8s.io/code-generator v0.18.6/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= k8s.io/component-base v0.18.4 h1:Kr53Fp1iCGNsl9Uv4VcRvLy7YyIqi9oaJOQ7SXtKI98= k8s.io/component-base v0.18.4/go.mod h1:7jr/Ef5PGmKwQhyAz/pjByxJbC58mhKAhiaDu0vXfPk= +k8s.io/component-base v0.18.6 h1:Wd6cHGwJN2qpufnirVOB3oMhyhbioGsKEi5HeDBsV+s= +k8s.io/component-base v0.18.6/go.mod h1:knSVsibPR5K6EW2XOjEHik6sdU5nCvKMrzMt2D4In14= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= @@ -961,6 +977,8 @@ rsc.io/letsencrypt v0.0.3/go.mod h1:buyQKZ6IXrRnB7TdkHP0RyEybLx18HHyOSoTyoOLqNY= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.7/go.mod h1:PHgbrJT7lCHcxMU+mDHEm+nx46H4zuuHZkDP6icnhu0= sigs.k8s.io/controller-runtime v0.6.1 h1:LcK2+nk0kmaOnKGN+vBcWHqY5WDJNJNB/c5pW+sU8fc= sigs.k8s.io/controller-runtime v0.6.1/go.mod h1:XRYBPdbf5XJu9kpS84VJiZ7h/u1hF3gEORz0efEja7A= +sigs.k8s.io/controller-runtime v0.6.2 h1:jkAnfdTYBpFwlmBn3pS5HFO06SfxvnTZ1p5PeEF/zAA= +sigs.k8s.io/controller-runtime v0.6.2/go.mod h1:vhcq/rlnENJ09SIRp3EveTaZ0yqH526hjf9iJdbUJ/E= sigs.k8s.io/kustomize v2.0.3+incompatible h1:JUufWFNlI44MdtnjUqVnvh29rR37PQFzPbLXqhyOyX0= sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
FieldDescription
+chart
string
-

Name of the Helm chart, as made available by the referenced Helm repository.

+

The name or path the Helm chart is available at in the SourceRef.

(Optional) -

Version semver expression, defaults to latest when omitted.

+

Version semver expression, ignored for charts from GitRepository sources. +Defaults to latest when omitted.

-

The name and namespace of the source HelmRepository the chart is available at.

+

The name and namespace of the v1alpha1.Source the chart is available at.

(Optional) -

Interval at which to check the Helm repository for chart updates. +

Interval at which to check the v1alpha1.Source for updates. Defaults to ‘HelmReleaseSpec.Interval’.

-

Chart defines the Helm chart name, version and repository.

+

Chart defines the template of the v1alpha1.HelmChart that should be created +for this HelmRelease.