diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 4f5aadf9..113321f2 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -82,7 +82,7 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct // TODO: Validate FAR CR name to nodeName. Run isNodeNameValid // Fetch the FAR's pod r.Log.Info("Fetch FAR's pod") - pod, err := utils.GetFenceAgentsRemediationPod(req.Name, r.Client) + pod, err := utils.GetFenceAgentsRemediationPod(r.Client) if err != nil { return emptyResult, err } diff --git a/pkg/utils/pods.go b/pkg/utils/pods.go index 8de8b219..0cc87bb9 100644 --- a/pkg/utils/pods.go +++ b/pkg/utils/pods.go @@ -14,7 +14,7 @@ import ( ) // GetFenceAgentsRemediationPod fetches the FAR pod based on FAR's label and namespace -func GetFenceAgentsRemediationPod(nodeName string, r client.Reader) (*corev1.Pod, error) { +func GetFenceAgentsRemediationPod(r client.Reader) (*corev1.Pod, error) { pods := &corev1.PodList{} selector := labels.NewSelector() diff --git a/test/e2e/far_e2e_test.go b/test/e2e/far_e2e_test.go index c8d663e6..2d697b2f 100644 --- a/test/e2e/far_e2e_test.go +++ b/test/e2e/far_e2e_test.go @@ -2,7 +2,6 @@ package e2e import ( "context" - "errors" "fmt" "time" @@ -11,7 +10,7 @@ import ( configv1 "github.com/openshift/api/config/v1" "github.com/medik8s/fence-agents-remediation/api/v1alpha1" - farController "github.com/medik8s/fence-agents-remediation/controllers" + "github.com/medik8s/fence-agents-remediation/pkg/utils" farUtils "github.com/medik8s/fence-agents-remediation/test/e2e/utils" corev1 "k8s.io/api/core/v1" @@ -240,7 +239,11 @@ func buildNodeParameters(clusterPlatformType string) (map[v1alpha1.ParameterName func checkFarLogs(logString string) { var pod *corev1.Pod EventuallyWithOffset(1, func() *corev1.Pod { - pod = getFenceAgentsPod() + pod, err := utils.GetFenceAgentsRemediationPod(k8sClient) + if err != nil { + log.Error(err, "failed to get pod. Might try again") + return nil + } return pod }, timeoutLogs, pollInterval).ShouldNot(BeNil(), "can't find the pod after timeout") @@ -253,22 +256,3 @@ func checkFarLogs(logString string) { return logs }, timeoutLogs, pollInterval).Should(ContainSubstring(logString)) } - -// getFenceAgentsPod fetches the FAR pod based on FAR's label and namespace -func getFenceAgentsPod() *corev1.Pod { - pods := new(corev1.PodList) - podLabelsSelector, _ := metav1.LabelSelectorAsSelector( - &metav1.LabelSelector{MatchLabels: farController.FaPodLabels}) - options := client.ListOptions{ - LabelSelector: podLabelsSelector, - } - if err := k8sClient.List(context.Background(), pods, &options); err != nil { - log.Error(err, "can't find the pod by it's labels") - return nil - } - if len(pods.Items) == 0 { - log.Error(errors.New("API error"), "Zero pods") - return nil - } - return &pods.Items[0] -}