From 8d13747d8c1d7261aaeeeca9f616260e61760b0b Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Tue, 13 Feb 2024 12:29:13 +0100 Subject: [PATCH] fixup! Add ability to adopt unmanaged resources --- pkg/action/install.go | 3 +-- pkg/action/upgrade.go | 3 +-- pkg/action/validate.go | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index 853e249bd..2d3cfa7cb 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -71,7 +71,6 @@ type Install struct { ClientOnly bool Force bool - ForceAdopt bool CreateNamespace bool DryRun bool DryRunOption string @@ -351,7 +350,7 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma if i.TakeOwnership { toBeAdopted, err = requireAdoption(resources) } else { - toBeAdopted, err = existingResourceConflict(resources, rel.Name, rel.Namespace, i.ForceAdopt) + toBeAdopted, err = existingResourceConflict(resources, rel.Name, rel.Namespace, i.TakeOwnership) } if err != nil { return nil, errors.Wrap(err, "Unable to continue with install") diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index da6cfb57d..fae48a790 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -46,7 +46,6 @@ type Upgrade struct { ChartPathOptions - Adopt bool // Install is a purely informative flag that indicates whether this upgrade was done in "install" mode. // // Applications may use this to determine whether this Upgrade operation was done as part of a @@ -348,7 +347,7 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR if u.TakeOwnership { toBeUpdated, err = requireAdoption(toBeCreated) } else { - toBeUpdated, err = existingResourceConflict(toBeCreated, upgradedRelease.Name, upgradedRelease.Namespace, u.Adopt) + toBeUpdated, err = existingResourceConflict(toBeCreated, upgradedRelease.Name, upgradedRelease.Namespace, u.TakeOwnership) } if err != nil { return nil, errors.Wrap(err, "Unable to continue with update") diff --git a/pkg/action/validate.go b/pkg/action/validate.go index 5c8b91f70..1a8ca0ae4 100644 --- a/pkg/action/validate.go +++ b/pkg/action/validate.go @@ -76,7 +76,7 @@ func requireAdoption(resources kube.ResourceList) (kube.ResourceList, error) { return requireUpdate, err } -func existingResourceConflict(resources kube.ResourceList, releaseName, releaseNamespace string, forceAdopt bool) (kube.ResourceList, error) { +func existingResourceConflict(resources kube.ResourceList, releaseName, releaseNamespace string, takeOwnership bool) (kube.ResourceList, error) { var requireUpdate kube.ResourceList err := resources.Visit(func(info *resource.Info, err error) error { @@ -93,7 +93,7 @@ func existingResourceConflict(resources kube.ResourceList, releaseName, releaseN return errors.Wrapf(err, "could not get information about the resource %s", resourceString(info)) } - if !forceAdopt { + if !takeOwnership { // Allow adoption of the resource if it is managed by Helm and is annotated with correct release name and namespace. if err := checkOwnership(existing, releaseName, releaseNamespace); err != nil { return fmt.Errorf("%s exists and cannot be imported into the current release: %s", resourceString(info), err)