Add ability to adopt unmanaged resources

(cherry picked from commit 93bf18c7aabc3bfbd494fd2503b08a1e77ac71e8)
pull/13350/head
Darren Shepherd 6 years ago committed by Krunal Hingu
parent 5a5449dc42
commit 7ab0caea7a

@ -71,6 +71,7 @@ type Install struct {
ClientOnly bool
Force bool
ForceAdopt bool
CreateNamespace bool
DryRun bool
DryRunOption string
@ -350,7 +351,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)
toBeAdopted, err = existingResourceConflict(resources, rel.Name, rel.Namespace, i.ForceAdopt)
}
if err != nil {
return nil, errors.Wrap(err, "Unable to continue with install")

@ -46,6 +46,7 @@ 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
@ -347,7 +348,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)
toBeUpdated, err = existingResourceConflict(toBeCreated, upgradedRelease.Name, upgradedRelease.Namespace, u.Adopt)
}
if err != nil {
return nil, errors.Wrap(err, "Unable to continue with update")

@ -62,7 +62,7 @@ func requireAdoption(resources kube.ResourceList) (kube.ResourceList, error) {
return requireUpdate, err
}
func existingResourceConflict(resources kube.ResourceList, releaseName, releaseNamespace string) (kube.ResourceList, error) {
func existingResourceConflict(resources kube.ResourceList, releaseName, releaseNamespace string, forceAdopt bool) (kube.ResourceList, error) {
var requireUpdate kube.ResourceList
err := resources.Visit(func(info *resource.Info, err error) error {
@ -79,10 +79,12 @@ func existingResourceConflict(resources kube.ResourceList, releaseName, releaseN
return errors.Wrapf(err, "could not get information about the resource %s", resourceString(info))
}
if !forceAdopt {
// 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)
}
}
requireUpdate.Append(info)
return nil

Loading…
Cancel
Save