Merge pull request #2382 from SomtochiAma/commit-sha

Use `client.Patch` for suspend/resume operations
pull/2389/head v0.26.1
Stefan Prodan 3 years ago committed by GitHub
commit 4b4e6b1be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -48,6 +48,7 @@ func init() {
type resumable interface { type resumable interface {
adapter adapter
copyable
statusable statusable
setUnsuspended() setUnsuspended()
successMessage() string successMessage() string
@ -97,10 +98,13 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
for i := 0; i < resume.list.len(); i++ { 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) logger.Actionf("resuming %s %s in %s namespace", resume.humanKind, resume.list.resumeItem(i).asClientObject().GetName(), *kubeconfigArgs.Namespace)
resume.list.resumeItem(i).setUnsuspended() obj := resume.list.resumeItem(i)
if err := kubeClient.Update(ctx, resume.list.resumeItem(i).asClientObject()); err != nil { patch := client.MergeFrom(obj.deepCopyClientObject())
obj.setUnsuspended()
if err := kubeClient.Patch(ctx, obj.asClientObject(), patch); err != nil {
return err return err
} }
logger.Successf("%s resumed", resume.humanKind) logger.Successf("%s resumed", resume.humanKind)
namespacedName := types.NamespacedName{ namespacedName := types.NamespacedName{

@ -46,6 +46,7 @@ func init() {
type suspendable interface { type suspendable interface {
adapter adapter
copyable
isSuspended() bool isSuspended() bool
setSuspended() setSuspended()
} }
@ -94,8 +95,11 @@ func (suspend suspendCommand) run(cmd *cobra.Command, args []string) error {
for i := 0; i < suspend.list.len(); i++ { 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) 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 return err
} }
logger.Successf("%s suspended", suspend.humanKind) logger.Successf("%s suspended", suspend.humanKind)

Loading…
Cancel
Save