Skip to content

Commit

Permalink
Typo fix + use log
Browse files Browse the repository at this point in the history
Due to code-review
  • Loading branch information
razo7 committed May 4, 2023
1 parent 0497740 commit 0d9572b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
9 changes: 5 additions & 4 deletions pkg/utils/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,41 @@ 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"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// GetFenceAgentsRemediationPod fetches the FAR pod based on FAR's label and namespace
func GetFenceAgentsRemediationPod(r client.Reader) (*corev1.Pod, error) {
logger := ctrl.Log.WithName("utils-pods")
pods := &corev1.PodList{}
selector := labels.NewSelector()
requirement, _ := labels.NewRequirement("app", selection.Equals, []string{"fence-agents-remediation-operator"})
selector = selector.Add(*requirement)
var podNamespace string
podNamespace, err := GetDeploymentNamespace()
if err != nil {
fmt.Printf("failed fetching FAR namespace\n")
logger.Error(err, "failed fetching FAR namespace")
}
err = r.List(context.Background(), pods, &client.ListOptions{LabelSelector: selector, Namespace: podNamespace})
if err != nil {
fmt.Printf("failed fetching FAR pod\n")
logger.Error(err, "failed fetching FAR pod")
return nil, err
}
if len(pods.Items) == 0 {
fmt.Printf("No Fence Agent pods were found\n")
podNotFoundErr := &apiErrors.StatusError{ErrStatus: metav1.Status{
Status: metav1.StatusFailure,
Code: http.StatusNotFound,
Reason: metav1.StatusReasonNotFound,
}}
logger.Error(podNotFoundErr, "No Fence Agent pods were found")
return nil, podNotFoundErr
}

Expand Down
6 changes: 4 additions & 2 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
const operatorInstalledNamespcae = "OPERATOR_NS"

var (
log logr.Logger
clientSet *kubernetes.Clientset
Expand All @@ -48,8 +50,8 @@ 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")
operatorNsName = os.Getenv(operatorInstalledNamespcae)
Expect(operatorNsName).ToNot(BeEmpty(), operatorInstalledNamespcae+" env var not set, can't start e2e test")

// +kubebuilder:scaffold:scheme

Expand Down
37 changes: 18 additions & 19 deletions test/e2e/far_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
fenceAgentIPMI = "fence_ipmilan"
fenceAgentAction = "status"
nodeIndex = 0
suceessStatusMessage = "ON"
succeesStatusMessage = "ON"
containerName = "manager"

// eventually parameters
Expand All @@ -35,19 +35,17 @@ const (

var _ = Describe("FAR E2e", func() {
var (
far *v1alpha1.FenceAgentsRemediation
fenceAgent string
clusterPlatformType string
clusterPlatform *configv1.Infrastructure
err error
far *v1alpha1.FenceAgentsRemediation
fenceAgent string
clusterPlatform *configv1.Infrastructure
err error
)
BeforeEach(func() {
clusterPlatform, err = farE2eUtils.GetClusterInfo(configClient)
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)
fmt.Printf("\ncluster name: %s and PlatformType: %s \n", string(clusterPlatform.Name), string(clusterPlatform.Status.PlatformStatus.Type))
})

Context("fence agent - dummy", func() {
Expand Down Expand Up @@ -84,21 +82,22 @@ var _ = Describe("FAR E2e", func() {
testNodeName = nodeObj.Name
log.Info("Testing Node", "Node name", testNodeName)

if clusterPlatformType == "AWS" {
switch clusterPlatform.Status.PlatformStatus.Type {
case configv1.AWSPlatformType:
fenceAgent = fenceAgentAWS
By("running fence_aws")
} else if clusterPlatformType == "BareMetal" {
case configv1.BareMetalPlatformType:
fenceAgent = fenceAgentIPMI
By("running fence_ipmilan")
} else {
default:
Skip("FAR haven't been tested on this kind of cluster (non AWS or BareMetal)")
}

testShareParam, err := buildSharedParameters(clusterPlatform, fenceAgentAction)
if err != nil {
Fail("can't get shared information")
}
testNodeParam, err := buildNodeParameters(clusterPlatformType)
testNodeParam, err := buildNodeParameters(clusterPlatform.Status.PlatformStatus.Type)
if err != nil {
Fail("can't get node information")
}
Expand All @@ -117,7 +116,7 @@ var _ = Describe("FAR E2e", func() {
Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(far), testFarCR)).To(Succeed(), "failed to get FAR CR")

By("checking the command has been executed successfully")
checkFarLogs(suceessStatusMessage)
checkFarLogs(succeesStatusMessage)
})
})
})
Expand Down Expand Up @@ -165,8 +164,8 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri
var testShareParam map[v1alpha1.ParameterName]string

// oc get Infrastructure.config.openshift.io/cluster -o jsonpath='{.status.platformStatus.type}'
clusterPlatformType := string(clusterPlatform.Status.PlatformStatus.Type)
if clusterPlatformType == "AWS" {
clusterPlatformType := clusterPlatform.Status.PlatformStatus.Type
if clusterPlatformType == configv1.AWSPlatformType {
accessKey, secretKey, err := farE2eUtils.GetCredentials(clientSet, secretAWS, secretKeyAWS, secretValAWS)
if err != nil {
fmt.Printf("can't get AWS credentials\n")
Expand All @@ -183,7 +182,7 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri
"--action": action,
// "--verbose": "", // for verbose result
}
} else if clusterPlatformType == "BareMetal" {
} else if clusterPlatformType == configv1.BareMetalPlatformType {
// TODO : get ip from GetCredientals
// oc get bmh -n openshift-machine-api ostest-master-0 -o jsonpath='{.spec.bmc.address}'
// then parse ip
Expand All @@ -204,23 +203,23 @@ func buildSharedParameters(clusterPlatform *configv1.Infrastructure, action stri
}

// buildNodeParameters returns a map key-value of node parameters based on cluster platform type if it finds the node info list, otherwise an error
func buildNodeParameters(clusterPlatformType string) (map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string, error) {
func buildNodeParameters(clusterPlatformType configv1.PlatformType) (map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string, error) {
var (
testNodeParam map[v1alpha1.ParameterName]map[v1alpha1.NodeName]string
nodeListParam map[v1alpha1.NodeName]string
nodeIdentifier v1alpha1.ParameterName
err error
)

if clusterPlatformType == "AWS" {
if clusterPlatformType == configv1.AWSPlatformType {
nodeListParam, err = farE2eUtils.GetAWSNodeInfoList(machineClient)
if err != nil {
fmt.Printf("can't get nodes' information - AWS instance ID\n")
return nil, err
}
nodeIdentifier = v1alpha1.ParameterName("--plug")

} else if clusterPlatformType == "BareMetal" {
} else if clusterPlatformType == configv1.BareMetalPlatformType {
nodeListParam, err = farE2eUtils.GetBMHNodeInfoList(machineClient)
if err != nil {
fmt.Printf("can't get nodes' information - ports\n")
Expand Down

0 comments on commit 0d9572b

Please sign in to comment.