Skip to content

Commit b6f5bc9

Browse files
controller: do not increment the retry counter if IP is missing
This patch modifies the `resolveEndpoint` in `CSIAddonsNode` controller to return a custom error if the pod does not have an IP and is in Pending/Running state. During the reconcile, if we get the custom error, we just requeue without incrementing the retry counter. Signed-off-by: Niraj Yadav <niryadav@redhat.com>
1 parent bf49f69 commit b6f5bc9

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

internal/controller/csiaddons/csiaddonsnode_controller.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const (
5757

5858
var (
5959
csiAddonsNodeFinalizer = csiaddonsv1alpha1.GroupVersion.Group + "/csiaddonsnode"
60+
61+
// errPodNotReady indicates the pod exists but is not ready yet
62+
// This is a transient condition that should not count toward the retry limit.
63+
errPodNotReady = errors.New("pod is not ready yet")
6064
)
6165

6266
// CSIAddonsNodeReconciler reconciles a CSIAddonsNode object
@@ -115,6 +119,11 @@ func (r *CSIAddonsNodeReconciler) Reconcile(ctx context.Context, req ctrl.Reques
115119
podName, endPoint, err := r.resolveEndpoint(ctx, csiAddonsNode.Spec.Driver.EndPoint)
116120
// Only requeue if the resource is not being deleted
117121
if err != nil && csiAddonsNode.DeletionTimestamp.IsZero() {
122+
if errors.Is(err, errPodNotReady) {
123+
logger.Info("Pod is not ready yet, requeuing", "reason", err.Error())
124+
return ctrl.Result{RequeueAfter: r.BaseRetryDelay}, nil
125+
}
126+
118127
logger.Error(err, "Failed to resolve endpoint")
119128

120129
// We will either:
@@ -363,7 +372,12 @@ func (r *CSIAddonsNodeReconciler) resolveEndpoint(ctx context.Context, rawURL st
363372
// a connection from the connection pool during cleanup.
364373
return podname, "", fmt.Errorf("failed to get pod %s/%s: %w", namespace, podname, err)
365374
} else if pod.Status.PodIP == "" {
366-
return podname, "", fmt.Errorf("pod %s/%s does not have an IP-address", namespace, podname)
375+
// The pod might still be starting up or waiting for IP assignment
376+
// Wrap the custom error so that we do not increment the retry counter in reconcile()
377+
if pod.Status.Phase == corev1.PodPending || pod.Status.Phase == corev1.PodRunning {
378+
return podname, "", fmt.Errorf("pod %s/%s in phase %s does not have an IP-address yet: %w", namespace, podname, pod.Status.Phase, errPodNotReady)
379+
}
380+
return podname, "", fmt.Errorf("pod %s/%s in phase %s does not have an IP-address", namespace, podname, pod.Status.Phase)
367381
}
368382

369383
ip := pod.Status.PodIP

0 commit comments

Comments
 (0)