Skip to content

Commit 16033b8

Browse files
Merge pull request #448 from kstrenkova/update-pod-exists-function
Update PodExists function to return pod
2 parents 6a9e990 + be04c93 commit 16033b8

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

internal/controller/common.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -598,17 +598,21 @@ func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (b
598598
return false, ErrFailedToDeleteLock
599599
}
600600

601-
// PodExists checks if a pod exists for the given instance and workflow step
602-
func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepIndex int) bool {
603-
pod := &corev1.Pod{}
601+
// GetPodIfExists returns the pod for the given instance and workflow step if it exists
602+
func (r *Reconciler) GetPodIfExists(
603+
ctx context.Context,
604+
instance client.Object,
605+
workflowStepIndex int,
606+
) (*corev1.Pod, error) {
604607
podName := r.GetPodName(instance, workflowStepIndex)
605-
objectKey := client.ObjectKey{Namespace: instance.GetNamespace(), Name: podName}
606-
err := r.Client.Get(ctx, objectKey, pod)
607-
if err != nil && k8s_errors.IsNotFound(err) {
608-
return false
608+
pod, err := r.GetPod(ctx, podName, instance.GetNamespace())
609+
if err != nil {
610+
if k8s_errors.IsNotFound(err) {
611+
return nil, nil
612+
}
613+
return nil, err
609614
}
610-
611-
return true
615+
return pod, nil
612616
}
613617

614618
// GetCommonRbacRules returns the common RBAC rules for test operations, with optional privileged permissions
@@ -690,8 +694,9 @@ func (r *Reconciler) VerifyNetworkAttachments(
690694
conditions *condition.Conditions,
691695
networkAttachmentStatus *map[string][]string,
692696
) (ctrl.Result, error) {
693-
if !r.PodExists(ctx, instance, workflowStepIndex) {
694-
return ctrl.Result{}, nil
697+
pod, err := r.GetPodIfExists(ctx, instance, workflowStepIndex)
698+
if pod == nil {
699+
return ctrl.Result{}, err
695700
}
696701

697702
networkReady, status, err := nad.VerifyNetworkStatusFromAnnotation(

0 commit comments

Comments
 (0)