From d3d271defe2926e67fa04c0c31303f839c803d16 Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Fri, 4 Feb 2022 12:05:02 +0100 Subject: [PATCH] use client.Patch for suspend/resume operations Signed-off-by: Somtochi Onyekwere --- cmd/flux/resume.go | 8 ++++++-- cmd/flux/suspend.go | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 163fbb90..9b570978 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -48,6 +48,7 @@ func init() { type resumable interface { adapter + copyable statusable setUnsuspended() successMessage() string @@ -97,10 +98,13 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error { for i := 0; i < resume.list.len(); i++ { logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, resume.list.resumeItem(i).asClientObject().GetName(), *kubeconfigArgs.Namespace) - resume.list.resumeItem(i).setUnsuspended() - if err := kubeClient.Update(ctx, resume.list.resumeItem(i).asClientObject()); err != nil { + obj := resume.list.resumeItem(i) + patch := client.MergeFrom(obj.deepCopyClientObject()) + obj.setUnsuspended() + if err := kubeClient.Patch(ctx, obj.asClientObject(), patch); err != nil { return err } + logger.Successf("%s resumed", resume.humanKind) namespacedName := types.NamespacedName{ diff --git a/cmd/flux/suspend.go b/cmd/flux/suspend.go index 02a44bd1..6b31f5c0 100644 --- a/cmd/flux/suspend.go +++ b/cmd/flux/suspend.go @@ -46,6 +46,7 @@ func init() { type suspendable interface { adapter + copyable isSuspended() bool setSuspended() } @@ -94,8 +95,11 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error { for i := 0; i < suspend.list.len(); i++ { logger.Actionf("suspending %s %s in %s namespace", suspend.humanKind, suspend.list.item(i).asClientObject().GetName(), *kubeconfigArgs.Namespace) - suspend.list.item(i).setSuspended() - if err := kubeClient.Update(ctx, suspend.list.item(i).asClientObject()); err != nil { + + obj := suspend.list.item(i) + patch := client.MergeFrom(obj.deepCopyClientObject()) + obj.setSuspended() + if err := kubeClient.Patch(ctx, obj.asClientObject(), patch); err != nil { return err } logger.Successf("%s suspended", suspend.humanKind)