Skip to content

Commit

Permalink
Add test cases for Summarize() and DetermineReleaseState()
Browse files Browse the repository at this point in the history
Signed-off-by: Soule BA <[email protected]>
  • Loading branch information
souleb committed May 7, 2024
1 parent 4069ad4 commit f47ddad
Show file tree
Hide file tree
Showing 12 changed files with 548 additions and 345 deletions.
2 changes: 1 addition & 1 deletion api/v2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ type HelmReleaseStatus struct {
// ObservedPostRenderersDigest is the digest for the post-renderers of
// the last successful reconciliation attempt.
// +optional
ObservedPostRenderersDigest string `json:"ObservedPostRenderersDigest,omitempty"`
ObservedPostRenderersDigest string `json:"observedPostRenderersDigest,omitempty"`

// LastAttemptedGeneration is the last generation the controller attempted
// to reconcile.
Expand Down
2 changes: 1 addition & 1 deletion api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ type HelmReleaseStatus struct {
// ObservedPostRenderersDigest is the digest for the post-renderers of
// the last successful reconciliation attempt.
// +optional
ObservedPostRenderersDigest string `json:"ObservedPostRenderersDigest,omitempty"`
ObservedPostRenderersDigest string `json:"observedPostRenderersDigest,omitempty"`

meta.ReconcileRequestStatus `json:",inline"`

Expand Down
2 changes: 1 addition & 1 deletion api/v2beta2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ type HelmReleaseStatus struct {
// ObservedPostRenderersDigest is the digest for the post-renderers of
// the last successful reconciliation attempt.
// +optional
ObservedPostRenderersDigest string `json:"ObservedPostRenderersDigest,omitempty"`
ObservedPostRenderersDigest string `json:"observedPostRenderersDigest,omitempty"`

// LastAttemptedGeneration is the last generation the controller attempted
// to reconcile.
Expand Down
30 changes: 15 additions & 15 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -906,11 +906,6 @@ spec:
observedGeneration: -1
description: HelmReleaseStatus defines the observed state of a HelmRelease.
properties:
ObservedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
conditions:
description: Conditions holds the conditions for the HelmRelease.
items:
Expand Down Expand Up @@ -1165,6 +1160,11 @@ spec:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
observedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
storageNamespace:
description: |-
StorageNamespace is the namespace of the Helm release storage for the
Expand Down Expand Up @@ -2129,11 +2129,6 @@ spec:
observedGeneration: -1
description: HelmReleaseStatus defines the observed state of a HelmRelease.
properties:
ObservedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
conditions:
description: Conditions holds the conditions for the HelmRelease.
items:
Expand Down Expand Up @@ -2404,6 +2399,11 @@ spec:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
observedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
storageNamespace:
description: |-
StorageNamespace is the namespace of the Helm release storage for the
Expand Down Expand Up @@ -3427,11 +3427,6 @@ spec:
observedGeneration: -1
description: HelmReleaseStatus defines the observed state of a HelmRelease.
properties:
ObservedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
conditions:
description: Conditions holds the conditions for the HelmRelease.
items:
Expand Down Expand Up @@ -3692,6 +3687,11 @@ spec:
description: ObservedGeneration is the last observed generation.
format: int64
type: integer
observedPostRenderersDigest:
description: |-
ObservedPostRenderersDigest is the digest for the post-renderers of
the last successful reconciliation attempt.
type: string
storageNamespace:
description: |-
StorageNamespace is the namespace of the Helm release storage for the
Expand Down
2 changes: 1 addition & 1 deletion docs/api/v2/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ int64
</tr>
<tr>
<td>
<code>ObservedPostRenderersDigest</code><br>
<code>observedPostRenderersDigest</code><br>
<em>
string
</em>
Expand Down
7 changes: 3 additions & 4 deletions docs/spec/v2/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -1666,14 +1666,14 @@ The helm-controller reports an observed generation in the HelmRelease's
`.metadata.generation` which resulted in either a [ready state](#ready-helmrelease),
or stalled due to error it can not recover from without human intervention.

### Oberved Post Renderers Digest
### Observed Post Renderers Digest

The helm-controller reports the digest for the [post renderers](#post-renderers)
it last rendered the Helm chart with in the for a successful Helm install or
upgrade in the `.status.ObervedPostRenderersDigest` field.
upgrade in the `.status.observedPostRenderersDigest` field.

This field is used by the controller to determine if a deployed Helm release
is in sync with the HelmRelease `spec.PostRenderers` configuration and whether
is in sync with the HelmRelease `spec.postRenderers` configuration and whether
it should trigger a Helm upgrade.

### Last Attempted Config Digest
Expand All @@ -1685,7 +1685,6 @@ attempted to perform a Helm install or upgrade with in the
The digest is used to determine if the controller should reset the
[failure counters](#failure-counters) due to a change in the values.


### Last Attempted Revision

The helm-controller reports the revision of the Helm chart it last attempted
Expand Down
10 changes: 6 additions & 4 deletions internal/controller/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,13 @@ func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context, patchHelpe
conditions.MarkUnknown(obj, meta.ReadyCondition, meta.ProgressingReason, "reconciliation in progress")
}

// Attempt to adopt "legacy" v2beta1 release state on a best-effort basis.
// If this fails, the controller will fall back to performing an upgrade
// to settle on the desired state.
// TODO(hidde): remove this in a future release.
// Keep feature flagged code paths separate from the main reconciliation
// logic to ensure easy removal when the feature flag is removed.
if ok, _ := features.Enabled(features.AdoptLegacyReleases); ok {
// Attempt to adopt "legacy" v2beta1 release state on a best-effort basis.
// If this fails, the controller will fall back to performing an upgrade
// to settle on the desired state.
// TODO(hidde): remove this in a future release.
if err := r.adoptLegacyRelease(ctx, getter, obj); err != nil {
log.Error(err, "failed to adopt v2beta1 release state")
}
Expand Down
3 changes: 0 additions & 3 deletions internal/controller/helmrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,6 @@ func TestHelmReleaseReconciler_reconcileReleaseFromHelmChartSource(t *testing.T)
chartMock := testutil.BuildChart()
chartArtifact, err := testutil.SaveChartAsArtifact(chartMock, digest.SHA256, testServer.URL(), testServer.Root())
g.Expect(err).ToNot(HaveOccurred())
// copy the artifact to mutate the revision
ociArtifact := chartArtifact.DeepCopy()
ociArtifact.Revision += "@" + chartArtifact.Digest

ns, err := testEnv.CreateNamespace(context.TODO(), "mock")
g.Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion internal/postrender/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package postrender
import (
"encoding/json"

"github.com/opencontainers/go-digest"
helmpostrender "helm.sh/helm/v3/pkg/postrender"

v2 "github.com/fluxcd/helm-controller/api/v2"
"github.com/opencontainers/go-digest"
)

// BuildPostRenderers creates the post-renderer instances from a HelmRelease
Expand Down
10 changes: 6 additions & 4 deletions internal/reconcile/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,12 @@ func summarize(req *Request) {
})

// remove stale post-renderers digest
req.Object.Status.ObservedPostRenderersDigest = ""
if req.Object.Spec.PostRenderers != nil {
// Update the post-renderers digest if the post-renderers exist.
req.Object.Status.ObservedPostRenderersDigest = postrender.Digest(digest.Canonical, req.Object.Spec.PostRenderers).String()
if conditions.Get(req.Object, meta.ReadyCondition).Status == metav1.ConditionTrue {
req.Object.Status.ObservedPostRenderersDigest = ""
if req.Object.Spec.PostRenderers != nil {
// Update the post-renderers digest if the post-renderers exist.
req.Object.Status.ObservedPostRenderersDigest = postrender.Digest(digest.Canonical, req.Object.Spec.PostRenderers).String()
}
}
}

Expand Down
Loading

0 comments on commit f47ddad

Please sign in to comment.