From 2c1be3ca728b5e48d5a540df304b2a0d8c4ff8bf Mon Sep 17 00:00:00 2001 From: Daniel Malon Date: Tue, 14 Nov 2023 16:50:53 +0000 Subject: [PATCH] feat: add drain delay Signed-off-by: Daniel Malon --- cmd/kured/main.go | 8 ++++++++ kured-ds.yaml | 1 + 2 files changed, 9 insertions(+) diff --git a/cmd/kured/main.go b/cmd/kured/main.go index 09f9913af..7440d3f46 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -44,6 +44,7 @@ var ( // Command line flags forceReboot bool + drainDelay time.Duration drainTimeout time.Duration rebootDelay time.Duration period time.Duration @@ -139,6 +140,8 @@ func NewRootCommand() *cobra.Command { "only drain pods with labels matching the selector (default: '', all pods)") rootCmd.PersistentFlags().IntVar(&skipWaitForDeleteTimeoutSeconds, "skip-wait-for-delete-timeout", 0, "when seconds is greater than zero, skip waiting for the pods whose deletion timestamp is older than N seconds while draining a node") + rootCmd.PersistentFlags().DurationVar(&drainDelay, "drain-delay", 0, + "delay drain for this duration (default: 0, disabled)") rootCmd.PersistentFlags().DurationVar(&drainTimeout, "drain-timeout", 0, "timeout after which the drain is aborted (default: 0, infinite time)") rootCmd.PersistentFlags().DurationVar(&rebootDelay, "reboot-delay", 0, @@ -497,6 +500,11 @@ func drain(client *kubernetes.Clientset, node *v1.Node) error { updateNodeLabels(client, node, preRebootNodeLabels) } + if drainDelay > 0 { + log.Infof("Delaying drain for %v", drainDelay) + time.Sleep(drainDelay) + } + log.Infof("Draining node %s", nodename) if notifyURL != "" { diff --git a/kured-ds.yaml b/kured-ds.yaml index 1f03c2cf5..77bd67d0b 100644 --- a/kured-ds.yaml +++ b/kured-ds.yaml @@ -53,6 +53,7 @@ spec: # - --force-reboot=false # - --drain-grace-period=-1 # - --skip-wait-for-delete-timeout=0 +# - --drain-delay=0 # - --drain-timeout=0 # - --drain-pod-selector="" # - --period=1h