Skip to content

Commit

Permalink
Delete redundant function
Browse files Browse the repository at this point in the history
PR medik8s#42 add downward API which makes some code redundant
  • Loading branch information
razo7 committed May 2, 2023
1 parent 129ac60 commit f78fccd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion controllers/fenceagentsremediation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 6 additions & 22 deletions test/e2e/far_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2e

import (
"context"
"errors"
"fmt"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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")

Expand All @@ -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]
}

0 comments on commit f78fccd

Please sign in to comment.