fix: rollback to release revision containing resource with keep-resource-policy annotation

When rollback to a previous release revision that contains a resource having the
annotaion `helm.sh/resource-policy=keep`, while the current release revision dosen't
have this resource, rollback option will give `Error: no XXX with the name "XXX" found`
error message.

We should not care about weather the resource with annotaion `helm.sh/resource-policy=keep`
exists in the current release revison or not.

fix #8228

Signed-off-by: Liu Ming <hit_oak_tree@126.com>
pull/8683/head
Liu Ming 5 years ago
parent 459dcd7f72
commit 68d0483890

@ -177,8 +177,11 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
return err return err
} }
kind := info.Mapping.GroupVersionKind.Kind
helper := resource.NewHelper(info.Client, info.Mapping) helper := resource.NewHelper(info.Client, info.Mapping)
if _, err := helper.Get(info.Namespace, info.Name, info.Export); err != nil { currentObject, err := helper.Get(info.Namespace, info.Name, info.Export)
if err != nil {
if !apierrors.IsNotFound(err) { if !apierrors.IsNotFound(err) {
return errors.Wrap(err, "could not get information about the resource") return errors.Wrap(err, "could not get information about the resource")
} }
@ -191,14 +194,25 @@ func (c *Client) Update(original, target ResourceList, force bool) (*Result, err
return errors.Wrap(err, "failed to create resource") return errors.Wrap(err, "failed to create resource")
} }
kind := info.Mapping.GroupVersionKind.Kind
c.Log("Created a new %s called %q in %s\n", kind, info.Name, info.Namespace) c.Log("Created a new %s called %q in %s\n", kind, info.Name, info.Namespace)
return nil return nil
} }
// Figure out whether this resource in the target release revision has
// annotation "helm.sh/resource-policy=keep", if yes, Helm should not
// manage this resource anymore.
annotations, err := metadataAccessor.Annotations(currentObject)
if err != nil {
return errors.Errorf("failed to get annotations of kind %s with the name %q", kind, info.Name)
}
if annotations != nil {
if val, exist := annotations[ResourcePolicyAnno]; exist && val == KeepPolicy {
return nil
}
}
originalInfo := original.Get(info) originalInfo := original.Get(info)
if originalInfo == nil { if originalInfo == nil {
kind := info.Mapping.GroupVersionKind.Kind
return errors.Errorf("no %s with the name %q found", kind, info.Name) return errors.Errorf("no %s with the name %q found", kind, info.Name)
} }

Loading…
Cancel
Save