fix: upgrade using --force shoud not run patch logic (#8000)

fix helm/helm#7999

Signed-off-by: Liu Ming <hit_oak_tree@126.com>
(cherry picked from commit decab8ea2e)
release-3.2
小明同学 5 years ago committed by Matt Farina
parent a8f6ae5bd5
commit 4b91e16397
No known key found for this signature in database
GPG Key ID: 9436E80BFBA46909

@ -422,6 +422,15 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
kind = target.Mapping.GroupVersionKind.Kind kind = target.Mapping.GroupVersionKind.Kind
) )
// if --force is applied, attempt to replace the existing resource with the new object.
if force {
var err error
obj, err = helper.Replace(target.Namespace, target.Name, true, target.Object)
if err != nil {
return errors.Wrap(err, "failed to replace object")
}
c.Log("Replaced %q with kind %s for kind %s\n", target.Name, currentObj.GetObjectKind().GroupVersionKind().Kind, kind)
} else {
patch, patchType, err := createPatch(target, currentObj) patch, patchType, err := createPatch(target, currentObj)
if err != nil { if err != nil {
return errors.Wrap(err, "failed to create patch") return errors.Wrap(err, "failed to create patch")
@ -436,15 +445,6 @@ func updateResource(c *Client, target *resource.Info, currentObj runtime.Object,
} }
return nil return nil
} }
// if --force is applied, attempt to replace the existing resource with the new object.
if force {
obj, err = helper.Replace(target.Namespace, target.Name, true, target.Object)
if err != nil {
return errors.Wrap(err, "failed to replace object")
}
c.Log("Replaced %q with kind %s for kind %s\n", target.Name, currentObj.GetObjectKind().GroupVersionKind().Kind, kind)
} else {
// send patch to server // send patch to server
obj, err = helper.Patch(target.Namespace, target.Name, patchType, patch, nil) obj, err = helper.Patch(target.Namespace, target.Name, patchType, patch, nil)
if err != nil { if err != nil {

Loading…
Cancel
Save