From 3f60c905e0053c643361da43ee9ec3756ab58b21 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Tue, 9 Apr 2019 16:12:24 +0200 Subject: [PATCH] Do not upgrade Helm release if spec has diverged This is a optimistic lock and prevents the operator from potentially releasing an old revision of a `HelmRelease`. As there is a (small) chance the spec is changed between the time we started preparing and calculating the upgrade, and the actual upgrade itself. --- integrations/helm/chartsync/chartsync.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/integrations/helm/chartsync/chartsync.go b/integrations/helm/chartsync/chartsync.go index d24a630da..8b3076d54 100644 --- a/integrations/helm/chartsync/chartsync.go +++ b/integrations/helm/chartsync/chartsync.go @@ -364,7 +364,16 @@ func (chs *ChartChangeSync) reconcileReleaseDef(fhr fluxv1beta1.HelmRelease) { return } if changed { - _, err := chs.release.Install(chartPath, releaseName, fhr, release.UpgradeAction, opts, &chs.kubeClient) + cFhr, err := chs.ifClient.FluxV1beta1().HelmReleases(fhr.Namespace).Get(fhr.Name, metav1.GetOptions{}) + if err != nil { + chs.logger.Log("warning", "Failed to retrieve HelmRelease scheduled for upgrade", "namespace", fhr.Namespace, "name", fhr.Name, "error", err) + return + } + if diff := cmp.Diff(fhr.Spec, cFhr.Spec); diff != "" { + chs.logger.Log("warning", "HelmRelease spec has diverged since we calculated if we should upgrade, skipping upgrade", "namespace", fhr.Namespace, "name", fhr.Name) + return + } + _, err = chs.release.Install(chartPath, releaseName, fhr, release.UpgradeAction, opts, &chs.kubeClient) if err != nil { chs.setCondition(&fhr, fluxv1beta1.HelmReleaseReleased, v1.ConditionFalse, ReasonUpgradeFailed, err.Error()) chs.logger.Log("warning", "Failed to upgrade chart", "namespace", fhr.Namespace, "name", fhr.Name, "error", err)