Skip to content

Commit

Permalink
Fetch the namespace the operator is installed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
razo7 committed May 2, 2023
1 parent b4a57dc commit 93772c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion controllers/fenceagentsremediation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"fmt"
"os"
"testing"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions test/e2e/far_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

const (
fenceAgentDummyName = "echo"
testNamespace = "far-install"
fenceAgentAWS = "fence_aws"
fenceAgentIPMI = "fence_ipmilan"
fenceAgentAction = "status"
Expand All @@ -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)
})

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/utils/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 93772c3

Please sign in to comment.