From 93772c33a8511b667738e378b2adc4aef53347a6 Mon Sep 17 00:00:00 2001 From: razo7 Date: Tue, 2 May 2023 14:06:05 +0300 Subject: [PATCH] Fetch the namespace the operator is installed Instead of hard code the namespace of where the operator is installed just fetch the environment variable OPERATOR_NS so FAR CRs will be created on the same namespace that FAR operator has been installed --- controllers/fenceagentsremediation_controller_test.go | 2 +- test/e2e/e2e_suite_test.go | 7 +++++++ test/e2e/far_e2e_test.go | 9 ++++----- test/e2e/utils/cluster.go | 4 ++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/controllers/fenceagentsremediation_controller_test.go b/controllers/fenceagentsremediation_controller_test.go index d4995f5d..9b9a6371 100644 --- a/controllers/fenceagentsremediation_controller_test.go +++ b/controllers/fenceagentsremediation_controller_test.go @@ -113,7 +113,7 @@ var _ = Describe("FAR Controller", func() { }) }) -// newFenceAgentsRemediation assign the input to the FenceAgentsRemediation +// newFenceAgentsRemediation assigns the input to the FenceAgentsRemediation func newFenceAgentsRemediation(nodeName string, agent string, sharedparameters map[v1alpha1.ParameterName]string, nodeparameters map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string) *v1alpha1.FenceAgentsRemediation { return &v1alpha1.FenceAgentsRemediation{ ObjectMeta: metav1.ObjectMeta{Name: nodeName, Namespace: defaultNamespace}, diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index e243953f..e5f66d22 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -2,6 +2,7 @@ package e2e import ( "fmt" + "os" "testing" "github.com/go-logr/logr" @@ -29,6 +30,9 @@ var ( k8sClient ctrl.Client configClient configclient.Interface machineClient *machineclient.MachineV1beta1Client + + // The ns the operator is running in + operatorNsName string ) func TestE2e(t *testing.T) { @@ -44,6 +48,9 @@ var _ = BeforeSuite(func() { logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseFlagOptions(&opts))) log = logf.Log + operatorNsName = os.Getenv("OPERATOR_NS") + Expect(operatorNsName).ToNot(BeEmpty(), "OPERATOR_NS env var not set, can't start e2e test") + // +kubebuilder:scaffold:scheme // Load the Kubernetes configuration from the default location or from a specified kubeconfig file or simply die diff --git a/test/e2e/far_e2e_test.go b/test/e2e/far_e2e_test.go index 5b5e022b..c8d663e6 100644 --- a/test/e2e/far_e2e_test.go +++ b/test/e2e/far_e2e_test.go @@ -22,7 +22,6 @@ import ( const ( fenceAgentDummyName = "echo" - testNamespace = "far-install" fenceAgentAWS = "fence_aws" fenceAgentIPMI = "fence_ipmilan" fenceAgentAction = "status" @@ -44,10 +43,10 @@ var _ = Describe("FAR E2e", func() { ) BeforeEach(func() { clusterPlatform, err = farUtils.GetClusterInfo(configClient) - clusterPlatformType = string(clusterPlatform.Status.PlatformStatus.Type) if err != nil { Fail("can't identify the cluster platform") } + clusterPlatformType = string(clusterPlatform.Status.PlatformStatus.Type) fmt.Printf("\ncluster name: %s and PlatformType: %s \n", string(clusterPlatform.Name), clusterPlatformType) }) @@ -128,7 +127,7 @@ var _ = Describe("FAR E2e", func() { // createFAR assigns the input to FenceAgentsRemediation object, creates CR, and returns the CR object func createFAR(nodeName string, agent string, sharedParameters map[v1alpha1.ParameterName]string, nodeParameters map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string) *v1alpha1.FenceAgentsRemediation { far := &v1alpha1.FenceAgentsRemediation{ - ObjectMeta: metav1.ObjectMeta{Name: nodeName, Namespace: testNamespace}, + ObjectMeta: metav1.ObjectMeta{Name: nodeName, Namespace: operatorNsName}, Spec: v1alpha1.FenceAgentsRemediationSpec{ Agent: agent, SharedParameters: sharedParameters, @@ -169,7 +168,7 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri // oc get Infrastructure.config.openshift.io/cluster -o jsonpath='{.status.platformStatus.type}' clusterPlatformType := string(clusterPlatform.Status.PlatformStatus.Type) if clusterPlatformType == "AWS" { - accessKey, secretKey, err := farUtils.GetCredientals(clientSet, secretAWS, secretKeyAWS, secretValAWS) + accessKey, secretKey, err := farUtils.GetCredentials(clientSet, secretAWS, secretKeyAWS, secretValAWS) if err != nil { fmt.Printf("can't get AWS credentials") return nil, err @@ -189,7 +188,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 := farUtils.GetCredientals(clientSet, secretBMHExample, secretKeyBM, secretValBM) + username, password, err := farUtils.GetCredentials(clientSet, secretBMHExample, secretKeyBM, secretValBM) if err != nil { fmt.Printf("can't get BM credentials") return nil, err diff --git a/test/e2e/utils/cluster.go b/test/e2e/utils/cluster.go index 689d4cb5..c0b96aae 100644 --- a/test/e2e/utils/cluster.go +++ b/test/e2e/utils/cluster.go @@ -31,8 +31,8 @@ func GetClusterInfo(config configclient.Interface) (*configv1.Infrastructure, er return clusterInfra, nil } -// GetCredientals searches for AWS or BMH secret, and then returns it decoded -func GetCredientals(clientSet *kubernetes.Clientset, secretName, secretKey, secretVal string) (string, string, error) { +// GetCredentials searches for AWS or BMH secret, and then returns it decoded +func GetCredentials(clientSet *kubernetes.Clientset, secretName, secretKey, secretVal string) (string, string, error) { // oc get secrets -n openshift-machine-api aws-cloud-credentials -o jsonpath='{.data.aws_access_key_id}' | base64 -d // oc get secrets -n openshift-machine-api aws-cloud-credentials -o jsonpath='{.data.aws_secret_access_key}' | base64 -d