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 4f00367
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,26 @@ func (r *HelmReleaseReconciler) release(log logr.Logger, hr v2.HelmRelease, sour

// Determine and execute deployment action.
var remediation v2.Remediation
var deployAction string
switch {
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)
deployAction := "install"
if remediation.RetriesExhausted(hr) {
// Retries exhausted, retain status from prior attempt.
err = fmt.Errorf("%s retries exhausted", deployAction)
return hr, err
}
rel, err = install(cfg, loadedChart, hr, values)
err = r.handleHelmActionResult(&hr, revision, err, deployAction, v2.InstalledCondition, v2.InstallSucceededReason, v2.InstallFailedReason)
default:
remediation = hr.Spec.Upgrade.Remediation
deployAction = "upgrade"
if !hr.Spec.Install.Remediation.RetriesExhausted(hr) && !remediation.RetriesExhausted(hr) {
deployAction := "upgrade"
if hr.Spec.Install.Remediation.RetriesExhausted(hr) || remediation.RetriesExhausted(hr) {
// Retries exhausted, retain status from prior attempt.
err = fmt.Errorf("%s retries exhausted", deployAction)
return hr, err
}
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)
}
Expand All @@ -373,8 +380,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 @@ -392,10 +398,6 @@ func (r *HelmReleaseReconciler) release(log logr.Logger, hr v2.HelmRelease, sour
err = uninstallConditionErr
}
}
default:
// Retries exhausted, retain status from prior attempt.
err = fmt.Errorf("%s retries exhausted", deployAction)
return hr, err
}
}

Expand Down

0 comments on commit 4f00367

Please sign in to comment.