Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Add drain delay flag
Browse files Browse the repository at this point in the history
This flag allows to specify a period of time for which drainer should
wait after cordoning a node. This ensure that for example after instance
refresh pods don't become 'Pending' for some period of time waiting for
the new node to come up.
  • Loading branch information
rtim75 authored and pawelprazak committed Feb 16, 2021
1 parent 84492c5 commit 2f4909b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/kubedrainer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions cmd/kubedrainer/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions pkg/drainer/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Options struct {
DeleteLocalData bool
Selector string
PodSelector string
DrainDelay time.Duration `mapstructure:"drain-delay"`
}

func (o *Options) String() string {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand All @@ -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

Expand Down

0 comments on commit 2f4909b

Please # to comment.