From 5b6969db601270961d8bccec79313e21b298a13d Mon Sep 17 00:00:00 2001 From: Vincent Marguerie Date: Fri, 21 May 2021 15:23:20 +0200 Subject: [PATCH] set poll interval configurable and set default value to 5s --- README.md | 2 +- main.go | 5 ++++- pkg/drainer/drainer.go | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55b9e7e..75acdac 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,9 @@ The node-drainer container takes as argument the parameters below. | count | The number of nodes to drain. | `1` | | max-unscheduled-pods | The maximum number of unscheduled pods on the cluster beyond which the drain will fail. | `0` | | eviction-timeout | The timeout in seconds for pods eviction during node drain. | `300` | +| poll-interval | The poll interval in seconds to check pods deletion on drain. | `5` | | dev | Enable dev mode for logging. | `false` | | v | Logs verbosity. 0 => panic, 1 => error, 2 => warning, 3 => info, 4 => debug | 3 | -| asg-poll-interval | AutoScaling Groups polling interval (used to generate custom metrics about ASGs). | 30 | ## Supervision diff --git a/main.go b/main.go index 4c0bcbe..b16dafb 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ func main() { fSelector map[string]string fEvictionGlobalTimeout int fOlderThan time.Duration + fPollInterval int fCount int fMaxUnscheduledPods int fKubeConfig string @@ -33,10 +34,11 @@ func main() { flag.BoolVar(&fEnableDevLogs, "dev", false, "Enable dev mode for logging.") flag.IntVar(&fLogVerbosity, "v", 3, "Logs verbosity. 0 => panic, 1 => error, 2 => warning, 3 => info, 4 => debug") flag.Var(cliflag.NewMapStringString(&fSelector), "l", "Selector to list the nodes to drain on labels separated by commas (e.g. `-l foo=bar,bar=baz`).") - flag.IntVar(&fEvictionGlobalTimeout, "eviction-timeout", 300, "The timeout in seconds for pods eviction during node drain.") flag.DurationVar(&fOlderThan, "older-than", time.Hour*8, "The minimum lifespan that a node must have to be drained.") flag.IntVar(&fCount, "count", 1, "The number of nodes to drain.") flag.IntVar(&fMaxUnscheduledPods, "max-unscheduled-pods", 0, "The maximum number of unscheduled pods on the cluster beyond which the drain will fail.") + flag.IntVar(&fEvictionGlobalTimeout, "eviction-timeout", 300, "The timeout in seconds for pods eviction during node drain.") + flag.IntVar(&fPollInterval, "poll-interval", 5, "The poll interval in seconds to check pods deletion on drain.") flag.StringVar(&fKubeConfig, "kubeconfig", "", "(optional) absolute path to the kubeconfig file") flag.Parse() @@ -73,6 +75,7 @@ func main() { // Perform node drains d := drainer.New(drainer.Configuration{ EvictionGlobalTimeout: fEvictionGlobalTimeout, + PollInterval: time.Second * time.Duration(fPollInterval), Cli: clientset, Log: log, }) diff --git a/pkg/drainer/drainer.go b/pkg/drainer/drainer.go index 1581df3..27d7b11 100644 --- a/pkg/drainer/drainer.go +++ b/pkg/drainer/drainer.go @@ -27,8 +27,6 @@ const ( evictionKind = "Eviction" // evictionSubresource represents the kind of evictions object as pod's subresource evictionSubresource = "pods/eviction" - // The delete pod polling interval - pollInterval = time.Second ) // ErrNoPodToEvict indicates that there's no pod to evict on the node. @@ -37,6 +35,7 @@ var ErrNoPodToEvict = errors.New("no pod to evict") // Configuration wraps Drainer configuration type Configuration struct { EvictionGlobalTimeout int + PollInterval time.Duration Cli *kubernetes.Clientset Log logr.Logger } @@ -379,7 +378,7 @@ func deleteTimeout(pods []corev1.Pod) time.Duration { // waitForDelete poll pods to check their deletion. // This code is largely inspired by kubectl cli source code. func (d *Drainer) waitForDelete(ctx context.Context, pods []corev1.Pod) ([]corev1.Pod, error) { - err := wait.PollImmediate(pollInterval, deleteTimeout(pods), func() (bool, error) { + err := wait.PollImmediate(d.PollInterval, deleteTimeout(pods), func() (bool, error) { pendingPods := []corev1.Pod{} for i, pod := range pods { p, err := d.Cli.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})