Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor release reconciliation #166

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
kubectl -n helm-system apply -f config/testdata/$test_name
echo -n ">>> Waiting for expected conditions"
count=0
until [ 'true' == "$( kubectl -n helm-system get helmrelease/$test_name -o json | jq '.status.conditions | map( { (.type): .status } ) | add | .Released=="False" and .TestSuccess=="False" and .Ready=="False"' )" ]; do
until [ 'true' == "$( kubectl -n helm-system get helmrelease/$test_name -o json | jq '.status.conditions | map( { (.type): .status } ) | add | .Released=="True" and .TestSuccess=="False" and .Ready=="False"' )" ]; do
echo -n '.'
sleep 5
count=$((count + 1))
Expand Down Expand Up @@ -301,7 +301,7 @@ jobs:
kubectl -n helm-system apply -f config/testdata/$test_name/upgrade.yaml
echo -n ">>> Waiting for expected conditions"
count=0
until [ 'true' == "$( kubectl -n helm-system get helmrelease/$test_name -o json | jq '.status.conditions | map( { (.type): .status } ) | add | .Released=="False" and .TestSuccess=="False" and .Ready=="False"' )" ]; do
until [ 'true' == "$( kubectl -n helm-system get helmrelease/$test_name -o json | jq '.status.conditions | map( { (.type): .status } ) | add | .Released=="True" and .TestSuccess=="False" and .Ready=="False"' )" ]; do
echo -n '.'
sleep 5
count=$((count + 1))
Expand Down
4 changes: 4 additions & 0 deletions api/v2beta1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ const (
// HelmRelease failed.
UninstallFailedReason string = "UninstallFailed"

// ArtifactNotReadyReason represents the fact that the artifact for the HelmChart
// is not available.
ArtifactNotReadyReason string = "ArtifactNotReady"

// ArtifactFailedReason represents the fact that the artifact download for the
// HelmRelease failed.
ArtifactFailedReason string = "ArtifactFailed"
Expand Down
46 changes: 24 additions & 22 deletions api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,14 @@ type HelmReleaseStatus struct {
// +optional
LastAttemptedValuesChecksum string `json:"lastAttemptedValuesChecksum,omitempty"`

// LastReleaseRevision is the revision of the last successful Helm release.
// LastReleaseRevision is the revision of the last performed Helm release.
// +optional
LastReleaseRevision int `json:"lastReleaseRevision,omitempty"`

// LastSuccessfulReleaseRevision is the revision of the last successful Helm release.
// +optional
LastSuccessfulReleaseRevision int `json:"lastSuccessfulReleaseRevision,omitempty"`
seaneagan marked this conversation as resolved.
Show resolved Hide resolved

// HelmChart is the namespaced name of the HelmChart resource created by
// the controller for the HelmRelease.
// +optional
Expand Down Expand Up @@ -696,41 +700,39 @@ func (in HelmReleaseStatus) GetHelmChart() (string, string) {
// HelmReleaseProgressing resets any failures and registers progress toward
// reconciling the given HelmRelease by setting the meta.ReadyCondition to
// 'Unknown' for meta.ProgressingReason.
func HelmReleaseProgressing(hr HelmRelease) HelmRelease {
func HelmReleaseProgressing(hr *HelmRelease) {
hr.Status.Conditions = []metav1.Condition{}
meta.SetResourceCondition(&hr, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason,
"Reconciliation in progress")
resetFailureCounts(&hr)
return hr
meta.SetResourceCondition(hr, meta.ReadyCondition, metav1.ConditionUnknown, meta.ProgressingReason,
"reconciliation in progress")
resetFailureCounts(hr)
}

// HelmReleaseNotReady registers a failed reconciliation of the given HelmRelease.
func HelmReleaseNotReady(hr HelmRelease, reason, message string) HelmRelease {
meta.SetResourceCondition(&hr, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
func HelmReleaseNotReady(hr *HelmRelease, reason, message string) {
meta.SetResourceCondition(hr, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
hr.Status.Failures++
return hr
}

// HelmReleaseReady registers a successful reconciliation of the given HelmRelease.
func HelmReleaseReady(hr HelmRelease) HelmRelease {
meta.SetResourceCondition(&hr, meta.ReadyCondition, metav1.ConditionTrue, meta.ReconciliationSucceededReason,
"Release reconciliation succeeded")
func HelmReleaseReady(hr *HelmRelease, message string) {
meta.SetResourceCondition(hr, meta.ReadyCondition, metav1.ConditionTrue, meta.ReconciliationSucceededReason, message)
hr.Status.LastAppliedRevision = hr.Status.LastAttemptedRevision
resetFailureCounts(&hr)
return hr
resetFailureCounts(hr)
}

// HelmReleaseAttempted registers an attempt of the given HelmRelease with the given state.
// and returns the modified HelmRelease and a boolean indicating a state change.
func HelmReleaseAttempted(hr HelmRelease, revision string, releaseRevision int, valuesChecksum string) (HelmRelease, bool) {
changed := hr.Status.LastAttemptedRevision != revision ||
hr.Status.LastReleaseRevision != releaseRevision ||
hr.Status.LastAttemptedValuesChecksum != valuesChecksum
// HelmReleaseAttempt registers a release attempt of the given HelmRelease.
func HelmReleaseAttempt(hr *HelmRelease, revision string, valuesChecksum string) {
hr.Status.LastAttemptedRevision = revision
hr.Status.LastReleaseRevision = releaseRevision
hr.Status.LastAttemptedValuesChecksum = valuesChecksum
}

return hr, changed
// StateChanged returns true if the given values differ from the values
// in the HelmRelease.
func StateChanged(hr *HelmRelease, revision string, releaseRevision int, valuesChecksum string) bool {
return hr.Status.LastAttemptedRevision != revision ||
hr.Status.LastReleaseRevision != releaseRevision ||
hr.Status.LastAttemptedValuesChecksum != valuesChecksum ||
hr.Status.ObservedGeneration != hr.Generation
}

func resetFailureCounts(hr *HelmRelease) {
Expand Down
6 changes: 5 additions & 1 deletion config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,13 @@ spec:
reconcile request value, so a change can be detected.
type: string
lastReleaseRevision:
description: LastReleaseRevision is the revision of the last successful
description: LastReleaseRevision is the revision of the last performed
Helm release.
type: integer
lastSuccessfulReleaseRevision:
description: LastSuccessfulReleaseRevision is the revision of the
last successful Helm release.
type: integer
observedGeneration:
description: ObservedGeneration is the last observed generation.
format: int64
Expand Down
Loading