From 28bd282e79214b71f3811fcdaf88351cfc36ad05 Mon Sep 17 00:00:00 2001 From: YZ775 Date: Fri, 20 Oct 2023 04:41:44 +0000 Subject: [PATCH] add reboot queue backoff reset command Signed-off-by: YZ775 --- pkg/ckecli/cmd/reboot_queue_backoff_reset.go | 44 ++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pkg/ckecli/cmd/reboot_queue_backoff_reset.go diff --git a/pkg/ckecli/cmd/reboot_queue_backoff_reset.go b/pkg/ckecli/cmd/reboot_queue_backoff_reset.go new file mode 100644 index 000000000..46061c12a --- /dev/null +++ b/pkg/ckecli/cmd/reboot_queue_backoff_reset.go @@ -0,0 +1,44 @@ +package cmd + +import ( + "context" + "time" + + "github.com/cybozu-go/cke" + "github.com/cybozu-go/well" + "github.com/spf13/cobra" +) + +var rebootQueueBackoffResetCmd = &cobra.Command{ + Use: "reset-backoff", + Short: "reset backoff", + Long: `reset backoff`, + RunE: func(cmd *cobra.Command, args []string) error { + well.Go(func(ctx context.Context) error { + entries, err := storage.GetRebootsEntries(ctx) + if err != nil { + return err + } + + for _, entry := range entries { + entry.DrainBackOffCount = 0 + entry.DrainBackOffExpire = time.Time{} + err := storage.UpdateRebootsEntry(ctx, entry) + if err == cke.ErrNotFound { + // The entry has just finished + continue + } + if err != nil { + return err + } + } + return nil + }) + well.Stop() + return well.Wait() + }, +} + +func init() { + rebootQueueCmd.AddCommand(rebootQueueBackoffResetCmd) +}