Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 31ba694

Browse files
authored
Merge pull request #6 from quortex/improve-poll-interval
set poll interval configurable and set default value to 5s
2 parents 72e2ca9 + 5b6969d commit 31ba694

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ The node-drainer container takes as argument the parameters below.
2323
| count | The number of nodes to drain. | `1` |
2424
| max-unscheduled-pods | The maximum number of unscheduled pods on the cluster beyond which the drain will fail. | `0` |
2525
| eviction-timeout | The timeout in seconds for pods eviction during node drain. | `300` |
26+
| poll-interval | The poll interval in seconds to check pods deletion on drain. | `5` |
2627
| dev | Enable dev mode for logging. | `false` |
2728
| v | Logs verbosity. 0 => panic, 1 => error, 2 => warning, 3 => info, 4 => debug | 3 |
28-
| asg-poll-interval | AutoScaling Groups polling interval (used to generate custom metrics about ASGs). | 30 |
2929

3030

3131
## Supervision

main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func main() {
2525
fSelector map[string]string
2626
fEvictionGlobalTimeout int
2727
fOlderThan time.Duration
28+
fPollInterval int
2829
fCount int
2930
fMaxUnscheduledPods int
3031
fKubeConfig string
@@ -33,10 +34,11 @@ func main() {
3334
flag.BoolVar(&fEnableDevLogs, "dev", false, "Enable dev mode for logging.")
3435
flag.IntVar(&fLogVerbosity, "v", 3, "Logs verbosity. 0 => panic, 1 => error, 2 => warning, 3 => info, 4 => debug")
3536
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`).")
36-
flag.IntVar(&fEvictionGlobalTimeout, "eviction-timeout", 300, "The timeout in seconds for pods eviction during node drain.")
3737
flag.DurationVar(&fOlderThan, "older-than", time.Hour*8, "The minimum lifespan that a node must have to be drained.")
3838
flag.IntVar(&fCount, "count", 1, "The number of nodes to drain.")
3939
flag.IntVar(&fMaxUnscheduledPods, "max-unscheduled-pods", 0, "The maximum number of unscheduled pods on the cluster beyond which the drain will fail.")
40+
flag.IntVar(&fEvictionGlobalTimeout, "eviction-timeout", 300, "The timeout in seconds for pods eviction during node drain.")
41+
flag.IntVar(&fPollInterval, "poll-interval", 5, "The poll interval in seconds to check pods deletion on drain.")
4042
flag.StringVar(&fKubeConfig, "kubeconfig", "", "(optional) absolute path to the kubeconfig file")
4143
flag.Parse()
4244

@@ -73,6 +75,7 @@ func main() {
7375
// Perform node drains
7476
d := drainer.New(drainer.Configuration{
7577
EvictionGlobalTimeout: fEvictionGlobalTimeout,
78+
PollInterval: time.Second * time.Duration(fPollInterval),
7679
Cli: clientset,
7780
Log: log,
7881
})

pkg/drainer/drainer.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const (
2727
evictionKind = "Eviction"
2828
// evictionSubresource represents the kind of evictions object as pod's subresource
2929
evictionSubresource = "pods/eviction"
30-
// The delete pod polling interval
31-
pollInterval = time.Second
3230
)
3331

3432
// ErrNoPodToEvict indicates that there's no pod to evict on the node.
@@ -37,6 +35,7 @@ var ErrNoPodToEvict = errors.New("no pod to evict")
3735
// Configuration wraps Drainer configuration
3836
type Configuration struct {
3937
EvictionGlobalTimeout int
38+
PollInterval time.Duration
4039
Cli *kubernetes.Clientset
4140
Log logr.Logger
4241
}
@@ -379,7 +378,7 @@ func deleteTimeout(pods []corev1.Pod) time.Duration {
379378
// waitForDelete poll pods to check their deletion.
380379
// This code is largely inspired by kubectl cli source code.
381380
func (d *Drainer) waitForDelete(ctx context.Context, pods []corev1.Pod) ([]corev1.Pod, error) {
382-
err := wait.PollImmediate(pollInterval, deleteTimeout(pods), func() (bool, error) {
381+
err := wait.PollImmediate(d.PollInterval, deleteTimeout(pods), func() (bool, error) {
383382
pendingPods := []corev1.Pod{}
384383
for i, pod := range pods {
385384
p, err := d.Cli.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})

0 commit comments

Comments
 (0)