Skip to content

Commit 28fa447

Browse files
committed
NOJIRA Increase retry delays in EvictPod
1 parent c2272fd commit 28fa447

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

internal/actions/evict_pod_handler.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"reflect"
8+
"time"
89

910
"github.com/sirupsen/logrus"
1011
v1 "k8s.io/api/core/v1"
@@ -22,14 +23,19 @@ import (
2223

2324
func NewEvictPodHandler(log logrus.FieldLogger, clientset kubernetes.Interface) ActionHandler {
2425
return &EvictPodHandler{
25-
log: log,
26-
clientset: clientset,
26+
log: log,
27+
clientset: clientset,
28+
podEvictRetryDelay: 5 * time.Second,
29+
podsTerminationWaitRetryDelay: 10 * time.Second,
2730
}
2831
}
2932

3033
type EvictPodHandler struct {
3134
log logrus.FieldLogger
3235
clientset kubernetes.Interface
36+
37+
podEvictRetryDelay time.Duration
38+
podsTerminationWaitRetryDelay time.Duration
3339
}
3440

3541
func (h *EvictPodHandler) Handle(ctx context.Context, action *castai.ClusterAction) error {
@@ -93,9 +99,10 @@ func (h *EvictPodHandler) evictPod(ctx context.Context, log logrus.FieldLogger,
9399
return fmt.Errorf("unsupported eviction version: %s", groupVersion.String())
94100
}
95101

102+
backoff := waitext.NewConstantBackoff(h.podEvictRetryDelay)
96103
return waitext.Retry(
97104
ctx,
98-
defaultBackoff(),
105+
backoff,
99106
waitext.Forever,
100107
func(ctx context.Context) (bool, error) {
101108
err := submit(ctx)
@@ -119,9 +126,10 @@ func (h *EvictPodHandler) evictPod(ctx context.Context, log logrus.FieldLogger,
119126
}
120127

121128
func (h *EvictPodHandler) waitForPodToBeDeleted(ctx context.Context, log logrus.FieldLogger, namespace, name string) error {
129+
backoff := waitext.NewConstantBackoff(h.podsTerminationWaitRetryDelay)
122130
return waitext.Retry(
123131
ctx, // controls how long we might wait at most.
124-
defaultBackoff(),
132+
backoff,
125133
waitext.Forever,
126134
func(ctx context.Context) (bool, error) {
127135
deleted, phase, err := h.isPodDeleted(ctx, namespace, name)
@@ -152,3 +160,11 @@ func (h *EvictPodHandler) isPodDeleted(ctx context.Context, namespace, name stri
152160
}
153161
return false, p.Status.Phase, nil
154162
}
163+
164+
func asAPIStatus(err error) (metav1.Status, bool) {
165+
var status apierrors.APIStatus
166+
if errors.As(err, &status) {
167+
return status.Status(), true
168+
}
169+
return metav1.Status{}, false
170+
}

0 commit comments

Comments
 (0)