From 5dc3682a6235ab0208003fbf38aee77722f2e397 Mon Sep 17 00:00:00 2001 From: Kumar Mallikarjuna Date: Wed, 8 Jan 2025 23:13:48 +0530 Subject: [PATCH] Add `disableTakeOwnership` to Helm install/upgrade actions This change adds a new field called `disableTakeOwnership` to `.spec.install` and `.spec.upgrade`. The flag allows users to disable ignoring helm annotations and labels before taking ownership of existing resources during install and upgrade. Signed-off-by: Kumar Mallikarjuna --- api/v2/helmrelease_types.go | 10 ++++++++++ .../crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml | 10 ++++++++++ internal/action/install.go | 2 +- internal/action/upgrade.go | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/v2/helmrelease_types.go b/api/v2/helmrelease_types.go index b10ae6277..9e5ceddd1 100644 --- a/api/v2/helmrelease_types.go +++ b/api/v2/helmrelease_types.go @@ -435,6 +435,11 @@ type Install struct { // +optional Remediation *InstallRemediation `json:"remediation,omitempty"` + // DisableTakeOwnership disables ignoring the check for helm labels and annotations before taking + // ownership of the existing resources during the Helm install action. Defaults to false. + // +optional + DisableTakeOwnership bool `json:"disableTakeOwnership,omitempty"` + // DisableWait disables the waiting for resources to be ready after a Helm // install has been performed. // +optional @@ -613,6 +618,11 @@ type Upgrade struct { // +optional Remediation *UpgradeRemediation `json:"remediation,omitempty"` + // DisableTakeOwnership disables ignoring the check for helm labels and annotations before taking + // ownership of the existing resources during the Helm upgrade action. Defaults to false. + // +optional + DisableTakeOwnership bool `json:"disableTakeOwnership,omitempty"` + // DisableWait disables the waiting for resources to be ready after a Helm // upgrade has been performed. // +optional diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index c15433935..830984c15 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -370,6 +370,11 @@ spec: DisableSchemaValidation prevents the Helm install action from validating the values against the JSON Schema. type: boolean + disableTakeOwnership: + description: |- + DisableTakeOwnership disables ignoring the check for helm labels and annotations before taking + ownership of the existing resources during the Helm install action. Defaults to false. + type: boolean disableWait: description: |- DisableWait disables the waiting for resources to be ready after a Helm @@ -784,6 +789,11 @@ spec: DisableSchemaValidation prevents the Helm upgrade action from validating the values against the JSON Schema. type: boolean + disableTakeOwnership: + description: |- + DisableTakeOwnership disables ignoring the check for helm labels and annotations before taking + ownership of the existing resources during the Helm upgrade action. Defaults to false. + type: boolean disableWait: description: |- DisableWait disables the waiting for resources to be ready after a Helm diff --git a/internal/action/install.go b/internal/action/install.go index da093c688..826afc27e 100644 --- a/internal/action/install.go +++ b/internal/action/install.go @@ -68,6 +68,7 @@ func newInstall(config *helmaction.Configuration, obj *v2.HelmRelease, opts []In install.ReleaseName = release.ShortenName(obj.GetReleaseName()) install.Namespace = obj.GetReleaseNamespace() install.Timeout = obj.GetInstall().GetTimeout(obj.GetTimeout()).Duration + install.TakeOwnership = !obj.GetInstall().DisableTakeOwnership install.Wait = !obj.GetInstall().DisableWait install.WaitForJobs = !obj.GetInstall().DisableWaitForJobs install.DisableHooks = obj.GetInstall().DisableHooks @@ -76,7 +77,6 @@ func newInstall(config *helmaction.Configuration, obj *v2.HelmRelease, opts []In install.Replace = obj.GetInstall().Replace install.Devel = true install.SkipCRDs = true - install.TakeOwnership = true if obj.Spec.TargetNamespace != "" { install.CreateNamespace = obj.GetInstall().CreateNamespace diff --git a/internal/action/upgrade.go b/internal/action/upgrade.go index 079a1336a..94e14477b 100644 --- a/internal/action/upgrade.go +++ b/internal/action/upgrade.go @@ -69,6 +69,7 @@ func newUpgrade(config *helmaction.Configuration, obj *v2.HelmRelease, opts []Up upgrade.ReuseValues = obj.GetUpgrade().PreserveValues upgrade.MaxHistory = obj.GetMaxHistory() upgrade.Timeout = obj.GetUpgrade().GetTimeout(obj.GetTimeout()).Duration + upgrade.TakeOwnership = !obj.GetUpgrade().DisableTakeOwnership upgrade.Wait = !obj.GetUpgrade().DisableWait upgrade.WaitForJobs = !obj.GetUpgrade().DisableWaitForJobs upgrade.DisableHooks = obj.GetUpgrade().DisableHooks @@ -77,7 +78,6 @@ func newUpgrade(config *helmaction.Configuration, obj *v2.HelmRelease, opts []Up upgrade.Force = obj.GetUpgrade().Force upgrade.CleanupOnFail = obj.GetUpgrade().CleanupOnFail upgrade.Devel = true - upgrade.TakeOwnership = true // If the user opted-in to allow DNS lookups, enable it. if allowDNS, _ := features.Enabled(features.AllowDNSLookups); allowDNS {