diff --git a/cmd/kubedrainer/main.go b/cmd/kubedrainer/main.go index 6bffef9..da3e55d 100644 --- a/cmd/kubedrainer/main.go +++ b/cmd/kubedrainer/main.go @@ -112,6 +112,7 @@ func drainerFlags(options *drainer.Options) *pflag.FlagSet { flags.Duration("timeout", options.Timeout, "The length of time to wait before giving up, zero means infinite") flags.StringP("selector", "l", options.Selector, "Selector (label query) to filter on") flags.StringP("pod-selector", "", options.PodSelector, "Label selector to filter pods on the node") + flags.String("drain-delay", options.DrainDelay.String(), "For how long to wait before draining a node") return flags } diff --git a/cmd/kubedrainer/serve.go b/cmd/kubedrainer/serve.go index 30d4ebc..f90fa32 100644 --- a/cmd/kubedrainer/serve.go +++ b/cmd/kubedrainer/serve.go @@ -45,6 +45,7 @@ func serveCmd() *cobra.Command { Timeout: 60 * time.Second, DeleteLocalData: true, IgnoreAllDaemonSets: true, + DrainDelay: 0 * time.Second, }, AWS: &autoscaling.Options{ LoopSleepTime: 10 * time.Second, diff --git a/pkg/drainer/drainer.go b/pkg/drainer/drainer.go index ded317f..8c8570a 100644 --- a/pkg/drainer/drainer.go +++ b/pkg/drainer/drainer.go @@ -39,6 +39,7 @@ type Options struct { DeleteLocalData bool Selector string PodSelector string + DrainDelay time.Duration `mapstructure:"drain-delay"` } func (o *Options) String() string { @@ -72,6 +73,7 @@ func New(client kubernetes.Interface, options *Options) Drainer { ErrOut: errOut, Out: out, }, + drainDelay: options.DrainDelay, drainer: &drain.Helper{ Client: client, ErrOut: errOut, @@ -142,6 +144,9 @@ func (o *drainCmdOptions) Drain(nodeName string) error { _ = printObj(n, o.Out) } + log.Info().Msgf("Sleep for %v before starting to evict", o.drainDelay.String()) + time.Sleep(o.drainDelay) + return o.deleteOrEvictPodsSimple(nodeName) } @@ -151,6 +156,8 @@ type drainCmdOptions struct { PrintFlags *genericclioptions.PrintFlags ToPrinter func(string) (printers.ResourcePrinterFunc, error) + drainDelay time.Duration + drainer *drain.Helper nodes *node.Node