From ccb88fe1612b2649f134c2c7340979b581e472dc Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Wed, 4 Dec 2024 16:15:53 +0100 Subject: [PATCH] csiaddons: allow deleting of the CR The pod is set as the owner of the csiaddons node object, and when the owner pod is deleted the csiaddons need to be deleted as well, When the delete Reconciles happens we cannot get the pod deletails to resolve the endpoint and we dont need that as well when we are deleting the CR. Signed-off-by: Madhu Rajanna --- internal/controller/csiaddons/csiaddonsnode_controller.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controller/csiaddons/csiaddonsnode_controller.go b/internal/controller/csiaddons/csiaddonsnode_controller.go index 266c19458..eaae16f96 100644 --- a/internal/controller/csiaddons/csiaddonsnode_controller.go +++ b/internal/controller/csiaddons/csiaddonsnode_controller.go @@ -98,7 +98,8 @@ func (r *CSIAddonsNodeReconciler) Reconcile(ctx context.Context, req ctrl.Reques logger = logger.WithValues("NodeID", nodeID, "DriverName", driverName) podName, endPoint, err := r.resolveEndpoint(ctx, csiAddonsNode.Spec.Driver.EndPoint) - if err != nil { + // Incase of CR is marked for deletion, we dont need the connection to be established. + if err != nil && podName == "" && csiAddonsNode.DeletionTimestamp.IsZero() { logger.Error(err, "Failed to resolve endpoint") return ctrl.Result{}, fmt.Errorf("failed to resolve endpoint %q: %w", csiAddonsNode.Spec.Driver.EndPoint, err) } @@ -340,9 +341,9 @@ func (r *CSIAddonsNodeReconciler) resolveEndpoint(ctx context.Context, rawURL st Name: podname, }, pod) if err != nil { - return "", "", fmt.Errorf("failed to get pod %s/%s: %w", namespace, podname, err) + return podname, "", fmt.Errorf("failed to get pod %s/%s: %w", namespace, podname, err) } else if pod.Status.PodIP == "" { - return "", "", fmt.Errorf("pod %s/%s does not have an IP-address", namespace, podname) + return podname, "", fmt.Errorf("pod %s/%s does not have an IP-address", namespace, podname) } return podname, fmt.Sprintf("%s:%s", pod.Status.PodIP, port), nil