Skip to content

Commit

Permalink
Prevent spurious upgrades from happening
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Aug 21, 2020
1 parent dcb5c9a commit 8a5a975
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,25 @@ func (r *HelmReleaseReconciler) release(log logr.Logger, hr v2.HelmRelease, sour
var remediation v2.Remediation
var deployAction string
switch {
// Install retries exhausted, retain status from prior attempt.
case hr.Spec.Install.Remediation.RetriesExhausted(hr):
return hr, fmt.Errorf("install retries exhausted")
// Upgrade retries exhausted, retain status from prior attempt.
case hr.Spec.Upgrade.Remediation.RetriesExhausted(hr):
return hr, fmt.Errorf("upgrade retries exhausted")
// Install the release as there is none.
case rel == nil:
remediation = hr.Spec.Install.Remediation
deployAction = "install"
if !remediation.RetriesExhausted(hr) {
rel, err = install(cfg, loadedChart, hr, values)
err = r.handleHelmActionResult(&hr, revision, err, deployAction, v2.InstalledCondition, v2.InstallSucceededReason, v2.InstallFailedReason)
}
rel, err = install(cfg, loadedChart, hr, values)
err = r.handleHelmActionResult(&hr, revision, err, "install", v2.InstalledCondition, v2.InstallSucceededReason, v2.InstallFailedReason)
// Upgrade, but only if the state changed.
default:
remediation = hr.Spec.Upgrade.Remediation
deployAction = "upgrade"
if !hr.Spec.Install.Remediation.RetriesExhausted(hr) && !remediation.RetriesExhausted(hr) {
if len(hr.Status.Conditions) == 0 {
rel, err = upgrade(cfg, loadedChart, hr, values)
err = r.handleHelmActionResult(&hr, revision, err, deployAction, v2.UpgradedCondition, v2.UpgradeSucceededReason, v2.UpgradeFailedReason)
err = r.handleHelmActionResult(&hr, revision, err, "upgrade", v2.UpgradedCondition, v2.UpgradeSucceededReason, v2.UpgradeFailedReason)
}
}

Expand All @@ -373,8 +379,7 @@ func (r *HelmReleaseReconciler) release(log logr.Logger, hr v2.HelmRelease, sour
if err != nil {
// Increment failure count for deployment action.
remediation.IncrementFailureCount(&hr)
switch {
case !remediation.RetriesExhausted(hr) || remediation.GetRemediateLastFailure():
if !remediation.RetriesExhausted(hr) || remediation.GetRemediateLastFailure() {
switch remediation.GetStrategy() {
case v2.RollbackRemediationStrategy:
// Only rollback upgrade if new revision was actually created.
Expand All @@ -391,11 +396,11 @@ func (r *HelmReleaseReconciler) release(log logr.Logger, hr v2.HelmRelease, sour
if uninstallConditionErr != nil {
err = uninstallConditionErr
}
default:
// Retries exhausted, retain status from prior attempt.
err = fmt.Errorf("%s retries exhausted", deployAction)
return hr, err
}
default:
// Retries exhausted, retain status from prior attempt.
err = fmt.Errorf("%s retries exhausted", deployAction)
return hr, err
}
}

Expand Down

0 comments on commit 8a5a975

Please sign in to comment.