From 91969cf7f73e64e1f67d3c2cdd07ec54c60ed2ef Mon Sep 17 00:00:00 2001 From: razo7 Date: Thu, 1 Jun 2023 11:30:24 +0300 Subject: [PATCH 1/4] Validate CR/node name from the node names in the cluster We want to validate that CR has been created correctly. Also UT functionality --- .../fenceagentsremediation_controller.go | 9 +-- .../fenceagentsremediation_controller_test.go | 55 ++++++++++++++----- pkg/utils/error.go | 36 ++++++++++++ pkg/utils/nodes.go | 24 ++++++++ pkg/utils/pods.go | 12 +--- 5 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 pkg/utils/error.go create mode 100644 pkg/utils/nodes.go diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 0c81f68a..67dc2125 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -79,7 +79,11 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct r.Log.Error(err, "failed to get FAR CR") return emptyResult, err } - // TODO: Validate FAR CR name to nodeName. Run isNodeNameValid + // Validate FAR CR name to match a nodeName from the cluster + if err := farUtils.CheckNodeName(r.Client, req.Name); err != nil { + return emptyResult, err + } + // Fetch the FAR's pod r.Log.Info("Fetch FAR's pod") pod, err := farUtils.GetFenceAgentsRemediationPod(r.Client) @@ -99,7 +103,6 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct //TODO: better seperation between errors from wrong shared parameters values and wrong node parameters values return emptyResult, err } - return emptyResult, nil } @@ -131,5 +134,3 @@ func appendParamToSlice(fenceAgentParams []string, paramName v1alpha1.ParameterN } return fenceAgentParams } - -// TODO: Add isNodeNameValid function which call listNodeNames to validate the FAR's name with the cluster node names diff --git a/controllers/fenceagentsremediation_controller_test.go b/controllers/fenceagentsremediation_controller_test.go index 5674bffb..c6c51a4c 100644 --- a/controllers/fenceagentsremediation_controller_test.go +++ b/controllers/fenceagentsremediation_controller_test.go @@ -27,10 +27,12 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" "github.com/medik8s/fence-agents-remediation/api/v1alpha1" + farUtils "github.com/medik8s/fence-agents-remediation/pkg/utils" ) const ( @@ -47,6 +49,7 @@ var ( var _ = Describe("FAR Controller", func() { var ( underTestFAR *v1alpha1.FenceAgentsRemediation + node *v1.Node ) testShareParam := map[v1alpha1.ParameterName]string{ @@ -69,13 +72,15 @@ var _ = Describe("FAR Controller", func() { underTestFAR = newFenceAgentsRemediation(validNodeName, fenceAgentIPMI, testShareParam, testNodeParam) Context("Functionality", func() { - Context("buildFenceAgentParams", func() { - When("FAR's name isn't a node name", func() { + Context("buildFenceAgentParams - check CR name", func() { + When("FAR's name doesn't match a node name", func() { It("should fail", func() { underTestFAR.ObjectMeta.Name = dummyNodeName _, err := buildFenceAgentParams(underTestFAR) Expect(err).To(HaveOccurred()) }) + }) + When("FAR's name does match a node name", func() { It("should succeed", func() { underTestFAR.ObjectMeta.Name = validNodeName _, err := buildFenceAgentParams(underTestFAR) @@ -83,25 +88,37 @@ var _ = Describe("FAR Controller", func() { }) }) }) - When("creating a resource", func() { - It("should fail when FAR pod is missing", func() { - //Test getFenceAgentsPod func + + Context("CheckNodeName - check node object", func() { + BeforeEach(func() { + node = getNode(validNodeName) + DeferCleanup(k8sClient.Delete, context.Background(), node) + Expect(k8sClient.Create(context.Background(), node)).To(Succeed()) + }) + When("FAR's name doesn't match to an existing node name", func() { + It("should fail", func() { + Expect(farUtils.CheckNodeName(k8sClient, dummyNodeName)).To(HaveOccurred()) + }) + }) + When("FAR's name does match to an existing node name", func() { + It("should succeed", func() { + Expect(farUtils.CheckNodeName(k8sClient, validNodeName)).To(Succeed()) + }) }) }) }) Context("Reconcile", func() { //Scenarios - BeforeEach(func() { fenceAgentsPod = buildFarPod() - // Create fenceAgentsPod and FAR - Expect(k8sClient.Create(context.Background(), fenceAgentsPod)).NotTo(HaveOccurred()) - Expect(k8sClient.Create(context.Background(), underTestFAR)).NotTo(HaveOccurred()) - }) - - AfterEach(func() { - Expect(k8sClient.Delete(context.Background(), fenceAgentsPod)).NotTo(HaveOccurred()) - Expect(k8sClient.Delete(context.Background(), underTestFAR)).NotTo(HaveOccurred()) + node = getNode(validNodeName) + // DeferCleanUp and Create node, fenceAgentsPod and FAR CR + DeferCleanup(k8sClient.Delete, context.Background(), node) + DeferCleanup(k8sClient.Delete, context.Background(), fenceAgentsPod) + DeferCleanup(k8sClient.Delete, context.Background(), underTestFAR) + Expect(k8sClient.Create(context.Background(), node)).To(Succeed()) + Expect(k8sClient.Create(context.Background(), fenceAgentsPod)).To(Succeed()) + Expect(k8sClient.Create(context.Background(), underTestFAR)).To(Succeed()) }) When("creating FAR CR", func() { @@ -127,6 +144,16 @@ func newFenceAgentsRemediation(nodeName string, agent string, sharedparameters m } } +// used for making new node object for test and have a unique resourceVersion +// getNode returns a node object with the name nodeName +func getNode(nodeName string) *corev1.Node { + return &corev1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Name: nodeName, + }, + } +} + // buildFarPod builds a dummy pod with FAR label and namespace func buildFarPod() *corev1.Pod { fenceAgentsPod := &corev1.Pod{} diff --git a/pkg/utils/error.go b/pkg/utils/error.go new file mode 100644 index 00000000..0873fdf6 --- /dev/null +++ b/pkg/utils/error.go @@ -0,0 +1,36 @@ +package utils + +import ( + "fmt" + "net/http" + + apiErrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// buildApiError returns new error with updated status +func buildApiError(err error, msg string) error { + var buildError error + switch { + case apiErrors.IsNotFound(err): + // Handle "Not Found" error + buildError = &apiErrors.StatusError{ErrStatus: metav1.Status{ + Status: metav1.StatusFailure, + Code: http.StatusNotFound, + Message: msg, + Reason: metav1.StatusReasonNotFound, + }} + case apiErrors.IsForbidden(err): + // Handle "Forbidden" error + buildError = &apiErrors.StatusError{ErrStatus: metav1.Status{ + Status: metav1.StatusFailure, + Code: http.StatusForbidden, + Message: msg, + Reason: metav1.StatusReasonForbidden, + }} + default: + // Handle other error types + buildError = fmt.Errorf("error %w does not match the following http error codes: %d, %d", err, http.StatusNotFound, http.StatusForbidden) + } + return buildError +} diff --git a/pkg/utils/nodes.go b/pkg/utils/nodes.go new file mode 100644 index 00000000..e89ef889 --- /dev/null +++ b/pkg/utils/nodes.go @@ -0,0 +1,24 @@ +package utils + +import ( + "context" + "fmt" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// CheckNodeName returns an error if nodeName doesn't match any node name int the cluster, otherwise a nil +func CheckNodeName(r client.Reader, nodeName string) error { + node := &corev1.Node{} + objNodeName := types.NamespacedName{Name: nodeName} + err := r.Get(context.Background(), objNodeName, node) + if err != nil { + // no match between CR name and the cluster nodes + msg := fmt.Sprintf("node %s is invalid", nodeName) + err = buildApiError(err, msg) + return fmt.Errorf("CR's name doesn't match any node name in the cluster - %w", err) + } + return nil +} diff --git a/pkg/utils/pods.go b/pkg/utils/pods.go index 79b82dc8..71f6a1da 100644 --- a/pkg/utils/pods.go +++ b/pkg/utils/pods.go @@ -3,11 +3,8 @@ package utils import ( "context" "fmt" - "net/http" corev1 "k8s.io/api/core/v1" - apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" "sigs.k8s.io/controller-runtime/pkg/client" @@ -26,15 +23,12 @@ func GetFenceAgentsRemediationPod(r client.Reader) (*corev1.Pod, error) { } err = r.List(context.Background(), pods, &client.ListOptions{LabelSelector: selector, Namespace: podNamespace}) if err != nil { + // Build pod not found error + err = buildApiError(err, "not found a pod that match the label") return nil, fmt.Errorf("failed fetching FAR pod - %w", err) } if len(pods.Items) == 0 { - podNotFoundErr := &apiErrors.StatusError{ErrStatus: metav1.Status{ - Status: metav1.StatusFailure, - Code: http.StatusNotFound, - Reason: metav1.StatusReasonNotFound, - }} - return nil, fmt.Errorf("no Fence Agent pods were found - %w", podNotFoundErr) + return nil, fmt.Errorf("no Fence Agent pods were found") } return &pods.Items[0], nil } From 5b00731c48f95abfe4a5ae6e6f4f84a2505f9e8d Mon Sep 17 00:00:00 2001 From: razo7 Date: Thu, 1 Jun 2023 11:39:07 +0300 Subject: [PATCH 2/4] Add verbs for nodes resources We need to add three new rbac, get, list and watch, for listing the cluster nodes --- .../fence-agents-remediation.clusterserviceversion.yaml | 8 ++++++++ config/rbac/role.yaml | 8 ++++++++ controllers/fenceagentsremediation_controller.go | 1 + 3 files changed, 17 insertions(+) diff --git a/bundle/manifests/fence-agents-remediation.clusterserviceversion.yaml b/bundle/manifests/fence-agents-remediation.clusterserviceversion.yaml index 0d44a857..4d7f66a6 100644 --- a/bundle/manifests/fence-agents-remediation.clusterserviceversion.yaml +++ b/bundle/manifests/fence-agents-remediation.clusterserviceversion.yaml @@ -120,6 +120,14 @@ spec: spec: clusterPermissions: - rules: + - apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch - apiGroups: - "" resources: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index b4f49382..98ed0799 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -5,6 +5,14 @@ metadata: creationTimestamp: null name: manager-role rules: +- apiGroups: + - "" + resources: + - nodes + verbs: + - get + - list + - watch - apiGroups: - "" resources: diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 67dc2125..44c4692f 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -50,6 +50,7 @@ func (r *FenceAgentsRemediationReconciler) SetupWithManager(mgr ctrl.Manager) er //+kubebuilder:rbac:groups=core,resources=pods/exec,verbs=create //+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch;update;delete;deletecollection +//+kubebuilder:rbac:groups="",resources=nodes,verbs=get;list;watch //+kubebuilder:rbac:groups=fence-agents-remediation.medik8s.io,resources=fenceagentsremediations,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=fence-agents-remediation.medik8s.io,resources=fenceagentsremediations/status,verbs=get;update;patch //+kubebuilder:rbac:groups=fence-agents-remediation.medik8s.io,resources=fenceagentsremediations/finalizers,verbs=update From eec5f74f1e3aecc0dd6573d0923a32d5dd691530 Mon Sep 17 00:00:00 2001 From: razo7 Date: Wed, 7 Jun 2023 10:51:07 +0300 Subject: [PATCH 3/4] Better error handeling for invalid node name Delete redundant error file, and returning bool with error for IsNodeNameValid function --- .../fenceagentsremediation_controller.go | 9 +++-- .../fenceagentsremediation_controller_test.go | 6 ++-- pkg/utils/error.go | 36 ------------------- pkg/utils/nodes.go | 18 +++++----- pkg/utils/pods.go | 2 -- 5 files changed, 20 insertions(+), 51 deletions(-) delete mode 100644 pkg/utils/error.go diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index 44c4692f..ba0cd96f 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -81,10 +81,15 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct return emptyResult, err } // Validate FAR CR name to match a nodeName from the cluster - if err := farUtils.CheckNodeName(r.Client, req.Name); err != nil { + r.Log.Info("Check FAR CR's name") + valid, err := farUtils.IsNodeNameValid(r.Client, req.Name) + if err != nil { return emptyResult, err } - + if !valid { + r.Log.Info("consider recreating the CR - invalid CR's name to the cluster node name", "FAR CR's Name", req.Name) + return emptyResult, nil + } // Fetch the FAR's pod r.Log.Info("Fetch FAR's pod") pod, err := farUtils.GetFenceAgentsRemediationPod(r.Client) diff --git a/controllers/fenceagentsremediation_controller_test.go b/controllers/fenceagentsremediation_controller_test.go index c6c51a4c..7d18b0a1 100644 --- a/controllers/fenceagentsremediation_controller_test.go +++ b/controllers/fenceagentsremediation_controller_test.go @@ -89,7 +89,7 @@ var _ = Describe("FAR Controller", func() { }) }) - Context("CheckNodeName - check node object", func() { + Context("IsNodeNameValid - check node object", func() { BeforeEach(func() { node = getNode(validNodeName) DeferCleanup(k8sClient.Delete, context.Background(), node) @@ -97,12 +97,12 @@ var _ = Describe("FAR Controller", func() { }) When("FAR's name doesn't match to an existing node name", func() { It("should fail", func() { - Expect(farUtils.CheckNodeName(k8sClient, dummyNodeName)).To(HaveOccurred()) + Expect(farUtils.IsNodeNameValid(k8sClient, dummyNodeName)).To(BeFalse()) }) }) When("FAR's name does match to an existing node name", func() { It("should succeed", func() { - Expect(farUtils.CheckNodeName(k8sClient, validNodeName)).To(Succeed()) + Expect(farUtils.IsNodeNameValid(k8sClient, validNodeName)).To(BeTrue()) }) }) }) diff --git a/pkg/utils/error.go b/pkg/utils/error.go deleted file mode 100644 index 0873fdf6..00000000 --- a/pkg/utils/error.go +++ /dev/null @@ -1,36 +0,0 @@ -package utils - -import ( - "fmt" - "net/http" - - apiErrors "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// buildApiError returns new error with updated status -func buildApiError(err error, msg string) error { - var buildError error - switch { - case apiErrors.IsNotFound(err): - // Handle "Not Found" error - buildError = &apiErrors.StatusError{ErrStatus: metav1.Status{ - Status: metav1.StatusFailure, - Code: http.StatusNotFound, - Message: msg, - Reason: metav1.StatusReasonNotFound, - }} - case apiErrors.IsForbidden(err): - // Handle "Forbidden" error - buildError = &apiErrors.StatusError{ErrStatus: metav1.Status{ - Status: metav1.StatusFailure, - Code: http.StatusForbidden, - Message: msg, - Reason: metav1.StatusReasonForbidden, - }} - default: - // Handle other error types - buildError = fmt.Errorf("error %w does not match the following http error codes: %d, %d", err, http.StatusNotFound, http.StatusForbidden) - } - return buildError -} diff --git a/pkg/utils/nodes.go b/pkg/utils/nodes.go index e89ef889..5e508927 100644 --- a/pkg/utils/nodes.go +++ b/pkg/utils/nodes.go @@ -2,23 +2,25 @@ package utils import ( "context" - "fmt" corev1 "k8s.io/api/core/v1" + apiErrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" ) -// CheckNodeName returns an error if nodeName doesn't match any node name int the cluster, otherwise a nil -func CheckNodeName(r client.Reader, nodeName string) error { +// IsNodeNameValid returns an error if nodeName doesn't match any node name int the cluster, otherwise a nil +func IsNodeNameValid(r client.Reader, nodeName string) (bool, error) { node := &corev1.Node{} objNodeName := types.NamespacedName{Name: nodeName} err := r.Get(context.Background(), objNodeName, node) if err != nil { - // no match between CR name and the cluster nodes - msg := fmt.Sprintf("node %s is invalid", nodeName) - err = buildApiError(err, msg) - return fmt.Errorf("CR's name doesn't match any node name in the cluster - %w", err) + if apiErrors.IsNotFound(err) { + // In case of notFound API error we don't return error, since it is valid result + return false, nil + } else { + return false, err + } } - return nil + return true, nil } diff --git a/pkg/utils/pods.go b/pkg/utils/pods.go index 71f6a1da..7c0273f3 100644 --- a/pkg/utils/pods.go +++ b/pkg/utils/pods.go @@ -23,8 +23,6 @@ func GetFenceAgentsRemediationPod(r client.Reader) (*corev1.Pod, error) { } err = r.List(context.Background(), pods, &client.ListOptions{LabelSelector: selector, Namespace: podNamespace}) if err != nil { - // Build pod not found error - err = buildApiError(err, "not found a pod that match the label") return nil, fmt.Errorf("failed fetching FAR pod - %w", err) } if len(pods.Items) == 0 { From 97e101d01f1cafc15ab79ed13254b127161ad468 Mon Sep 17 00:00:00 2001 From: razo7 Date: Thu, 8 Jun 2023 13:48:57 +0300 Subject: [PATCH 4/4] Fix typos and check error message Updating import names, and check error message of 1 UT --- .../fenceagentsremediation_controller.go | 14 ++++++++----- .../fenceagentsremediation_controller_test.go | 20 +++++++++---------- test/e2e/far_e2e_test.go | 18 ++++++++--------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/controllers/fenceagentsremediation_controller.go b/controllers/fenceagentsremediation_controller.go index ba0cd96f..af8c9184 100644 --- a/controllers/fenceagentsremediation_controller.go +++ b/controllers/fenceagentsremediation_controller.go @@ -30,7 +30,11 @@ import ( "github.com/medik8s/fence-agents-remediation/api/v1alpha1" "github.com/medik8s/fence-agents-remediation/pkg/cli" - farUtils "github.com/medik8s/fence-agents-remediation/pkg/utils" + "github.com/medik8s/fence-agents-remediation/pkg/utils" +) + +const ( + errorBuildingFAParams = "node parameter is required, and cannot be empty" ) // FenceAgentsRemediationReconciler reconciles a FenceAgentsRemediation object @@ -82,17 +86,17 @@ func (r *FenceAgentsRemediationReconciler) Reconcile(ctx context.Context, req ct } // Validate FAR CR name to match a nodeName from the cluster r.Log.Info("Check FAR CR's name") - valid, err := farUtils.IsNodeNameValid(r.Client, req.Name) + valid, err := utils.IsNodeNameValid(r.Client, req.Name) if err != nil { return emptyResult, err } if !valid { - r.Log.Info("consider recreating the CR - invalid CR's name to the cluster node name", "FAR CR's Name", req.Name) + r.Log.Info("didn't find a node matching the CR's name", "CR's Name", req.Name) return emptyResult, nil } // Fetch the FAR's pod r.Log.Info("Fetch FAR's pod") - pod, err := farUtils.GetFenceAgentsRemediationPod(r.Client) + pod, err := utils.GetFenceAgentsRemediationPod(r.Client) if err != nil { return emptyResult, err } @@ -124,7 +128,7 @@ func buildFenceAgentParams(far *v1alpha1.FenceAgentsRemediation) ([]string, erro if nodeVal, isFound := nodeMap[nodeName]; isFound { fenceAgentParams = appendParamToSlice(fenceAgentParams, paramName, nodeVal) } else { - err := errors.New("node parameter is required, and cannot be empty") + err := errors.New(errorBuildingFAParams) return nil, err } } diff --git a/controllers/fenceagentsremediation_controller_test.go b/controllers/fenceagentsremediation_controller_test.go index 7d18b0a1..874faff4 100644 --- a/controllers/fenceagentsremediation_controller_test.go +++ b/controllers/fenceagentsremediation_controller_test.go @@ -27,12 +27,11 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ctrl "sigs.k8s.io/controller-runtime" "github.com/medik8s/fence-agents-remediation/api/v1alpha1" - farUtils "github.com/medik8s/fence-agents-remediation/pkg/utils" + "github.com/medik8s/fence-agents-remediation/pkg/utils" ) const ( @@ -49,7 +48,7 @@ var ( var _ = Describe("FAR Controller", func() { var ( underTestFAR *v1alpha1.FenceAgentsRemediation - node *v1.Node + node *corev1.Node ) testShareParam := map[v1alpha1.ParameterName]string{ @@ -72,15 +71,16 @@ var _ = Describe("FAR Controller", func() { underTestFAR = newFenceAgentsRemediation(validNodeName, fenceAgentIPMI, testShareParam, testNodeParam) Context("Functionality", func() { - Context("buildFenceAgentParams - check CR name", func() { - When("FAR's name doesn't match a node name", func() { + Context("buildFenceAgentParams", func() { + When("FAR CR's name doesn't match a node name", func() { It("should fail", func() { underTestFAR.ObjectMeta.Name = dummyNodeName _, err := buildFenceAgentParams(underTestFAR) Expect(err).To(HaveOccurred()) + Expect(err).To(Equal(errors.New(errorBuildingFAParams))) }) }) - When("FAR's name does match a node name", func() { + When("FAR CR's name does match a node name", func() { It("should succeed", func() { underTestFAR.ObjectMeta.Name = validNodeName _, err := buildFenceAgentParams(underTestFAR) @@ -89,20 +89,20 @@ var _ = Describe("FAR Controller", func() { }) }) - Context("IsNodeNameValid - check node object", func() { + Context("IsNodeNameValid", func() { BeforeEach(func() { node = getNode(validNodeName) DeferCleanup(k8sClient.Delete, context.Background(), node) Expect(k8sClient.Create(context.Background(), node)).To(Succeed()) }) - When("FAR's name doesn't match to an existing node name", func() { + When("FAR CR's name doesn't match to an existing node name", func() { It("should fail", func() { - Expect(farUtils.IsNodeNameValid(k8sClient, dummyNodeName)).To(BeFalse()) + Expect(utils.IsNodeNameValid(k8sClient, dummyNodeName)).To(BeFalse()) }) }) When("FAR's name does match to an existing node name", func() { It("should succeed", func() { - Expect(farUtils.IsNodeNameValid(k8sClient, validNodeName)).To(BeTrue()) + Expect(utils.IsNodeNameValid(k8sClient, validNodeName)).To(BeTrue()) }) }) }) diff --git a/test/e2e/far_e2e_test.go b/test/e2e/far_e2e_test.go index 98cea473..028e1316 100644 --- a/test/e2e/far_e2e_test.go +++ b/test/e2e/far_e2e_test.go @@ -16,8 +16,8 @@ import ( configv1 "github.com/openshift/api/config/v1" "github.com/medik8s/fence-agents-remediation/api/v1alpha1" - farUtils "github.com/medik8s/fence-agents-remediation/pkg/utils" - farE2eUtils "github.com/medik8s/fence-agents-remediation/test/e2e/utils" + "github.com/medik8s/fence-agents-remediation/pkg/utils" + e2eUtils "github.com/medik8s/fence-agents-remediation/test/e2e/utils" ) const ( @@ -42,7 +42,7 @@ var _ = Describe("FAR E2e", func() { err error ) BeforeEach(func() { - clusterPlatform, err = farE2eUtils.GetClusterInfo(configClient) + clusterPlatform, err = e2eUtils.GetClusterInfo(configClient) if err != nil { Fail("can't identify the cluster platform") } @@ -167,7 +167,7 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri // oc get Infrastructure.config.openshift.io/cluster -o jsonpath='{.status.platformStatus.type}' clusterPlatformType := clusterPlatform.Status.PlatformStatus.Type if clusterPlatformType == configv1.AWSPlatformType { - accessKey, secretKey, err := farE2eUtils.GetCredentials(clientSet, secretAWS, secretKeyAWS, secretValAWS) + accessKey, secretKey, err := e2eUtils.GetCredentials(clientSet, secretAWS, secretKeyAWS, secretValAWS) if err != nil { fmt.Printf("can't get AWS credentials\n") return nil, err @@ -187,7 +187,7 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri // TODO : get ip from GetCredientals // oc get bmh -n openshift-machine-api ostest-master-0 -o jsonpath='{.spec.bmc.address}' // then parse ip - username, password, err := farE2eUtils.GetCredentials(clientSet, secretBMHExample, secretKeyBM, secretValBM) + username, password, err := e2eUtils.GetCredentials(clientSet, secretBMHExample, secretKeyBM, secretValBM) if err != nil { fmt.Printf("can't get BMH credentials\n") return nil, err @@ -213,7 +213,7 @@ func buildNodeParameters(clusterPlatformType configv1.PlatformType) (map[v1alpha ) if clusterPlatformType == configv1.AWSPlatformType { - nodeListParam, err = farE2eUtils.GetAWSNodeInfoList(machineClient) + nodeListParam, err = e2eUtils.GetAWSNodeInfoList(machineClient) if err != nil { fmt.Printf("can't get nodes' information - AWS instance ID\n") return nil, err @@ -221,7 +221,7 @@ func buildNodeParameters(clusterPlatformType configv1.PlatformType) (map[v1alpha nodeIdentifier = v1alpha1.ParameterName("--plug") } else if clusterPlatformType == configv1.BareMetalPlatformType { - nodeListParam, err = farE2eUtils.GetBMHNodeInfoList(machineClient) + nodeListParam, err = e2eUtils.GetBMHNodeInfoList(machineClient) if err != nil { fmt.Printf("can't get nodes' information - ports\n") return nil, err @@ -237,7 +237,7 @@ func checkFarLogs(logString string) { var pod *corev1.Pod var err error EventuallyWithOffset(1, func() *corev1.Pod { - pod, err = farUtils.GetFenceAgentsRemediationPod(k8sClient) + pod, err = utils.GetFenceAgentsRemediationPod(k8sClient) if err != nil { log.Error(err, "failed to get pod. Might try again") return nil @@ -246,7 +246,7 @@ func checkFarLogs(logString string) { }, timeoutLogs, pollInterval).ShouldNot(BeNil(), "can't find the pod after timeout") EventuallyWithOffset(1, func() string { - logs, err := farE2eUtils.GetLogs(clientSet, pod, containerName) + logs, err := e2eUtils.GetLogs(clientSet, pod, containerName) if err != nil { log.Error(err, "failed to get logs. Might try again") return ""