From 1f16ebd699aab3dbaec4f6fde3f260840e9b7bfd Mon Sep 17 00:00:00 2001 From: Max Jonas Werner Date: Wed, 7 Jul 2021 17:33:45 +0200 Subject: [PATCH] feat: set default observedGeneration to -1 on HelmReleases This resolves an issue with kustomize-controller marking a Kustomization as healthy even when the helm-controller hasn't even looked at the HelmRelease targeted by the Kustomization's healthChecks, yet. Setting `observedGeneration` to -1 by default will cause kstatus to report a status of `InProgress` instead of `Ready`. see https://github.com/fluxcd/kustomize-controller/issues/387 for details on the issues this is solving. Signed-off-by: Max Jonas Werner --- .github/workflows/e2e.yaml | 11 +++++++++++ api/v2beta1/helmrelease_types.go | 1 + .../bases/helm.toolkit.fluxcd.io_helmreleases.yaml | 2 ++ config/testdata/status-defaults/helmrelease.yaml | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 config/testdata/status-defaults/helmrelease.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index a05b833..8712ac8 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -54,6 +54,17 @@ jobs: KUBEBUILDER_ASSETS: ${{ github.workspace }}/kubebuilder/bin - name: Load test image run: kind load docker-image test/helm-controller:latest + - name: Install CRDs + run: make install + - name: Run default status test + run: | + kubectl apply -f config/testdata/status-defaults + RESULT=$(kubectl get helmrelease status-defaults -o jsonpath={.status}) + EXPECTED='{"observedGeneration":-1}' + if [ "${RESULT}" != "${EXPECTED}" ] ; then + echo -e "${RESULT}\n\ndoes not equal\n\n${EXPECTED}" + exit 1 + fi - name: Deploy controllers run: | make dev-deploy IMG=test/helm-controller:latest diff --git a/api/v2beta1/helmrelease_types.go b/api/v2beta1/helmrelease_types.go index 27b1b0f..2167fc4 100644 --- a/api/v2beta1/helmrelease_types.go +++ b/api/v2beta1/helmrelease_types.go @@ -882,6 +882,7 @@ type HelmRelease struct { metav1.ObjectMeta `json:"metadata,omitempty"` Spec HelmReleaseSpec `json:"spec,omitempty"` + // +kubebuilder:default:={"observedGeneration":-1} Status HelmReleaseStatus `json:"status,omitempty"` } diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index 05add81..c25dc27 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -447,6 +447,8 @@ spec: - interval type: object status: + default: + observedGeneration: -1 description: HelmReleaseStatus defines the observed state of a HelmRelease. properties: conditions: diff --git a/config/testdata/status-defaults/helmrelease.yaml b/config/testdata/status-defaults/helmrelease.yaml new file mode 100644 index 0000000..5bb2eae --- /dev/null +++ b/config/testdata/status-defaults/helmrelease.yaml @@ -0,0 +1,14 @@ +apiVersion: helm.toolkit.fluxcd.io/v2beta1 +kind: HelmRelease +metadata: + name: status-defaults +spec: + interval: 5m + chart: + spec: + chart: podinfo + version: '>=4.0.0 <5.0.0' + sourceRef: + kind: HelmRepository + name: podinfo + interval: 1m