Skip to content

Commit

Permalink
Add disableTakeOwnership to Helm install/upgrade actions
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kumar-mallikarjuna committed Jan 8, 2025
1 parent e898662 commit d684a7d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
10 changes: 10 additions & 0 deletions api/v2/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions docs/api/v2/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,19 @@ action for the HelmRelease fails. The default is to not perform any action.</p>
</tr>
<tr>
<td>
<code>disableTakeOwnership</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>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.</p>
</td>
</tr>
<tr>
<td>
<code>disableWait</code><br>
<em>
bool
Expand Down Expand Up @@ -2682,6 +2695,19 @@ action for the HelmRelease fails. The default is to not perform any action.</p>
</tr>
<tr>
<td>
<code>disableTakeOwnership</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>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.</p>
</td>
</tr>
<tr>
<td>
<code>disableWait</code><br>
<em>
bool
Expand Down
2 changes: 1 addition & 1 deletion internal/action/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit d684a7d

Please sign in to comment.