From 3765416214d3fdafaa58f2d7bd70e87847cf15e9 Mon Sep 17 00:00:00 2001 From: Tamara Kaufler Date: Mon, 23 Apr 2018 13:01:24 +0100 Subject: [PATCH] Removes delete action from ihelm-operator manual release sync The original assumption was that user's cluster only contains Chart releases defined by FluxHelmReleases stored in git repo. As a result the provided implementation deleted any release not having a FHR counterpart. This resulted in unwanted deletions such as helm-operator deleting itself when deployed as a Chart etc --- integrations/helm/release/release.go | 1 - integrations/helm/releasesync/releasesync.go | 44 ++++++-------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/integrations/helm/release/release.go b/integrations/helm/release/release.go index 77475716c..a6645dc36 100644 --- a/integrations/helm/release/release.go +++ b/integrations/helm/release/release.go @@ -22,7 +22,6 @@ var ( type Action string const ( - DeleteAction Action = "DELETE" InstallAction Action = "CREATE" UpgradeAction Action = "UPDATE" ) diff --git a/integrations/helm/releasesync/releasesync.go b/integrations/helm/releasesync/releasesync.go index 4041d929c..1b2991572 100644 --- a/integrations/helm/releasesync/releasesync.go +++ b/integrations/helm/releasesync/releasesync.go @@ -154,40 +154,28 @@ func (rs *ReleaseChangeSync) addExistingReleasesToSync( chRels = relsToSync[ns] for relName := range nsRelsM { if customResources[ns] == nil { - chr := chartRelease{ - releaseName: relName, - action: chartrelease.DeleteAction, - desiredState: ifv1.FluxHelmRelease{}, - } - chRels = append(chRels, chr) continue } + // We are ignoring Charts that are not under flux/helm-operator control fhr, ok := customResources[ns][relName] if !ok { + continue + } + rel, err := rs.release.GetDeployedRelease(relName) + if err != nil { + return err + } + doUpgrade, err := rs.shouldUpgrade(rel, fhr) + if err != nil { + return err + } + if doUpgrade { chr := chartRelease{ releaseName: relName, - action: chartrelease.DeleteAction, + action: chartrelease.UpgradeAction, desiredState: fhr, } chRels = append(chRels, chr) - - } else { - rel, err := rs.release.GetDeployedRelease(relName) - if err != nil { - return err - } - doUpgrade, err := rs.shouldUpgrade(rel, fhr) - if err != nil { - return err - } - if doUpgrade { - chr := chartRelease{ - releaseName: relName, - action: chartrelease.UpgradeAction, - desiredState: fhr, - } - chRels = append(chRels, chr) - } } } if len(chRels) > 0 { @@ -282,12 +270,6 @@ func (rs *ReleaseChangeSync) sync(ctx context.Context, releases map[string][]cha relName := chr.releaseName switch chr.action { - case chartrelease.DeleteAction: - rs.logger.Log("info", fmt.Sprintf("Deleting manually installed Chart release %s (namespace %s)", relName, ns)) - err := rs.release.Delete(relName) - if err != nil { - return err - } case chartrelease.UpgradeAction: rs.logger.Log("info", fmt.Sprintf("Resyncing manually upgraded Chart release %s (namespace %s)", relName, ns)) _, err := rs.release.Install(checkout, relName, chr.desiredState, chartrelease.UpgradeAction, opts)