fixup! Add ability to adopt unmanaged resources

pull/13350/head
Mario Manno 2 years ago committed by Krunal Hingu
parent 7e6badf12b
commit 8d13747d8c

@ -71,7 +71,6 @@ type Install struct {
ClientOnly bool ClientOnly bool
Force bool Force bool
ForceAdopt bool
CreateNamespace bool CreateNamespace bool
DryRun bool DryRun bool
DryRunOption string DryRunOption string
@ -351,7 +350,7 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma
if i.TakeOwnership { if i.TakeOwnership {
toBeAdopted, err = requireAdoption(resources) toBeAdopted, err = requireAdoption(resources)
} else { } else {
toBeAdopted, err = existingResourceConflict(resources, rel.Name, rel.Namespace, i.ForceAdopt) toBeAdopted, err = existingResourceConflict(resources, rel.Name, rel.Namespace, i.TakeOwnership)
} }
if err != nil { if err != nil {
return nil, errors.Wrap(err, "Unable to continue with install") return nil, errors.Wrap(err, "Unable to continue with install")

@ -46,7 +46,6 @@ type Upgrade struct {
ChartPathOptions ChartPathOptions
Adopt bool
// Install is a purely informative flag that indicates whether this upgrade was done in "install" mode. // 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 // 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 { if u.TakeOwnership {
toBeUpdated, err = requireAdoption(toBeCreated) toBeUpdated, err = requireAdoption(toBeCreated)
} else { } else {
toBeUpdated, err = existingResourceConflict(toBeCreated, upgradedRelease.Name, upgradedRelease.Namespace, u.Adopt) toBeUpdated, err = existingResourceConflict(toBeCreated, upgradedRelease.Name, upgradedRelease.Namespace, u.TakeOwnership)
} }
if err != nil { if err != nil {
return nil, errors.Wrap(err, "Unable to continue with update") return nil, errors.Wrap(err, "Unable to continue with update")

@ -76,7 +76,7 @@ func requireAdoption(resources kube.ResourceList) (kube.ResourceList, error) {
return requireUpdate, err 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 var requireUpdate kube.ResourceList
err := resources.Visit(func(info *resource.Info, err error) error { 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)) 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. // 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 { 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) return fmt.Errorf("%s exists and cannot be imported into the current release: %s", resourceString(info), err)

Loading…
Cancel
Save