Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Mar 14, 2024
1 parent b3e5ded commit e57c18f
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,11 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
// start to update mco status
StartStatusUpdate(r.Client, instance)

crdClient, err := operatorsutil.GetOrCreateCRDClient()
if err != nil {
return ctrl.Result{}, err
}

if _, ok := os.LookupEnv("UNIT_TEST"); !ok {
crdClient, err := operatorsutil.GetOrCreateCRDClient()
if err != nil {
return ctrl.Result{}, err
}
mcghCrdExists, err := operatorsutil.CheckCRDExist(crdClient, config.MCGHCrdName)
if err != nil {
return ctrl.Result{}, err
Expand Down
6 changes: 5 additions & 1 deletion tests/pkg/tests/observability-e2e-test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ var (
testOptionsContainer utils.TestOptionsContainer
testUITimeout time.Duration

testFailed = false
testFailed = false
hubMetricsCollectorNamespace = "open-cluster-management-observability"
hubManagedClusterName = "local-cluster"
namespace = MCO_ADDON_NAMESPACE
isHub = false
)

const (
Expand Down
3 changes: 3 additions & 0 deletions tests/pkg/tests/observability_addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var _ = Describe("Observability:", func() {
testOptions.HubCluster.ClusterServerURL,
testOptions.KubeConfig,
testOptions.HubCluster.KubeContext)
if utils.GetManagedClusterName(testOptions) == hubManagedClusterName {
Skip("Skip the case for local-cluster since no observability addon")
}
})

JustBeforeEach(func() {
Expand Down
21 changes: 14 additions & 7 deletions tests/pkg/tests/observability_certrenew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ var _ = Describe("Observability:", func() {
testOptions.HubCluster.ClusterServerURL,
testOptions.KubeConfig,
testOptions.HubCluster.KubeContext)
clusterName := utils.GetManagedClusterName(testOptions)
if clusterName == hubManagedClusterName {
namespace = hubMetricsCollectorNamespace
isHub = true
}
})

It("[P1][Sev1][observability][Integration] Should have metrics collector pod restart if cert secret re-generated (certrenew/g0)", func() {
Expand All @@ -39,7 +44,7 @@ var _ = Describe("Observability:", func() {
_, podList := utils.GetPodList(
testOptions,
false,
MCO_ADDON_NAMESPACE,
namespace,
"component=metrics-collector",
)
if podList != nil && len(podList.Items) > 0 {
Expand All @@ -51,7 +56,7 @@ var _ = Describe("Observability:", func() {
}
_, apiPodList := utils.GetPodList(
testOptions,
true,
isHub,
MCO_NAMESPACE,
"app.kubernetes.io/name=observatorium-api",
)
Expand Down Expand Up @@ -82,7 +87,7 @@ var _ = Describe("Observability:", func() {
Eventually(func() bool {
err1, appPodList := utils.GetPodList(
testOptions,
true,
isHub,
MCO_NAMESPACE,
"app.kubernetes.io/name=observatorium-api",
)
Expand Down Expand Up @@ -141,8 +146,8 @@ var _ = Describe("Observability:", func() {
Eventually(func() bool {
err, podList := utils.GetPodList(
testOptions,
false,
MCO_ADDON_NAMESPACE,
isHub,
namespace,
"component=metrics-collector",
)
if err == nil {
Expand All @@ -160,9 +165,9 @@ var _ = Describe("Observability:", func() {
// debug code to check label "cert/time-restarted"
deployment, err := utils.GetDeployment(
testOptions,
false,
isHub,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
if err == nil {
klog.V(1).Infof("labels: <%v>", deployment.Spec.Template.ObjectMeta.Labels)
Expand All @@ -182,5 +187,7 @@ var _ = Describe("Observability:", func() {
utils.PrintAllOBAPodsStatus(testOptions)
}
testFailed = testFailed || CurrentGinkgoTestDescription().Failed
namespace = MCO_ADDON_NAMESPACE
isHub = false
})
})
37 changes: 27 additions & 10 deletions tests/pkg/tests/observability_endpoint_preserve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package tests

import (
"fmt"
"os"

. "github.com/onsi/ginkgo"
Expand All @@ -28,21 +29,31 @@ var _ = Describe("Observability:", func() {
testOptions.HubCluster.ClusterServerURL,
testOptions.KubeConfig,
testOptions.HubCluster.KubeContext)
clusterName := utils.GetManagedClusterName(testOptions)
if clusterName == hubManagedClusterName {
namespace = hubMetricsCollectorNamespace
}
fmt.Printf("Coleen deleting metrics-collector deployment for namespace : %s cluster: %s\n", namespace, clusterName)
})

Context("[P2][Sev2][observability] Should revert any manual changes on metrics-collector deployment (endpoint_preserve/g0) -", func() {
newDep := &appv1.Deployment{}
It("[Stable] Deleting metrics-collector deployment", func() {
It("[Stable] Deleting metrics-collector deployment for cluster", func() {
if os.Getenv("IS_KIND_ENV") == trueStr {
Skip("Skip the case due to run in KinD")
}
var (
err error
dep *appv1.Deployment
)
clusterName := utils.GetManagedClusterName(testOptions)
fmt.Printf("Coleen deleting metrics-collector deployment for namespace : %s cluster: %s\n", namespace, clusterName)
Eventually(func() error {
dep, err = utils.GetDeployment(
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
return err
}, EventuallyTimeoutMinute*1, EventuallyIntervalSecond*1).Should(Succeed())
Expand All @@ -52,7 +63,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
return err
}, EventuallyTimeoutMinute*1, EventuallyIntervalSecond*1).Should(Succeed())
Expand All @@ -62,7 +73,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
if err == nil {
if dep.ObjectMeta.ResourceVersion != newDep.ObjectMeta.ResourceVersion {
Expand All @@ -73,13 +84,18 @@ var _ = Describe("Observability:", func() {
}, EventuallyTimeoutMinute*1, EventuallyIntervalSecond*1).Should(BeTrue())
})
It("[Stable] Updating metrics-collector deployment", func() {
if os.Getenv("IS_KIND_ENV") == trueStr {
Skip("Skip the case due to run in KinD")
}
clusterName := utils.GetManagedClusterName(testOptions)
fmt.Printf("Coleen deleting metrics-collector deployment for namespace : %s cluster: %s\n", namespace, clusterName)
updateSaName := "test-serviceaccount"
Eventually(func() error {
newDep, err = utils.GetDeployment(
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
if err != nil {
return err
Expand All @@ -89,7 +105,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
newDep,
)
return err
Expand All @@ -100,7 +116,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-deployment",
MCO_ADDON_NAMESPACE,
namespace,
)
if err == nil {
if revertDep.ObjectMeta.ResourceVersion != newDep.ObjectMeta.ResourceVersion &&
Expand Down Expand Up @@ -166,7 +182,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-serving-certs-ca-bundle",
MCO_ADDON_NAMESPACE,
namespace,
)
return err
}, EventuallyTimeoutMinute*1, EventuallyIntervalSecond*1).Should(Succeed())
Expand All @@ -175,7 +191,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-serving-certs-ca-bundle",
MCO_ADDON_NAMESPACE,
namespace,
)
return err
}, EventuallyTimeoutMinute*1, EventuallyIntervalSecond*1).Should(Succeed())
Expand All @@ -185,7 +201,7 @@ var _ = Describe("Observability:", func() {
testOptions,
false,
"metrics-collector-serving-certs-ca-bundle",
MCO_ADDON_NAMESPACE,
namespace,
)
if err == nil {
if cm.ObjectMeta.ResourceVersion != newCm.ObjectMeta.ResourceVersion {
Expand All @@ -206,6 +222,7 @@ var _ = Describe("Observability:", func() {
utils.PrintAllMCOPodsStatus(testOptions)
utils.PrintAllOBAPodsStatus(testOptions)
}
namespace = MCO_ADDON_NAMESPACE
testFailed = testFailed || CurrentGinkgoTestDescription().Failed
})
})
2 changes: 2 additions & 0 deletions tests/pkg/tests/observability_grafana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var _ = Describe("Observability:", func() {
})

It("@BVT - [P1][Sev1][observability][Stable] Should have metric data in grafana console (grafana/g0)", func() {
clusterName := utils.GetManagedClusterName(testOptions)
fmt.Printf("Coleen deleting metrics-collector deployment for namespace : %s cluster: %s\n", namespace, clusterName)
Eventually(func() error {
clusters, err := utils.ListManagedClusters(testOptions)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion tests/pkg/tests/observability_manifestwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ var _ = Describe("Observability:", func() {
testOptions.HubCluster.ClusterServerURL,
testOptions.KubeConfig,
testOptions.HubCluster.KubeContext)
if utils.GetManagedClusterName(testOptions) == hubManagedClusterName {
Skip("Skip the case for local-cluster since no observability addon")
}
})

Context("[P2][Sev2][observability][Stable] Should be automatically created within 1 minute when delete manifestwork (manifestwork/g0) -", func() {
manifestWorkName := "endpoint-observability-work"
clientDynamic := utils.GetKubeClientDynamic(testOptions, true)
clusterName := utils.GetManagedClusterName(testOptions)
if clusterName != "" {
if clusterName != "" && clusterName != "local-cluster" {
// ACM 8509 : Special case for local-cluster
// We do not create manifestwork for local-cluster
oldManifestWorkResourceVersion := ""
oldCollectorPodName := ""
_, podList := utils.GetPodList(testOptions, false, MCO_ADDON_NAMESPACE, "component=metrics-collector")
Expand Down
2 changes: 2 additions & 0 deletions tests/pkg/tests/observability_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var _ = Describe("Observability:", func() {
})

It("[P2][Sev2][observability][Integration] Should have metrics which defined in custom metrics allowlist (metrics/g0)", func() {
clusterName := utils.GetManagedClusterName(testOptions)
fmt.Printf("Coleen deleting metrics-collector deployment for namespace : %s cluster: %s\n", namespace, clusterName)
By("Adding custom metrics allowlist configmap")
yamlB, err := kustomize.Render(kustomize.Options{KustomizationPath: "../../../examples/metrics/allowlist"})
Expect(err).ToNot(HaveOccurred())
Expand Down
10 changes: 9 additions & 1 deletion tests/pkg/utils/mco_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ func GetAllOBAPods(opt TestOptions) ([]corev1.Pod, error) {
}

func PrintAllOBAPodsStatus(opt TestOptions) {
if GetManagedClusterName(opt) == "local-cluster" {
klog.V(1).Infof("Skip printing OBA pods status for local-cluster")
return
}
podList, err := GetAllOBAPods(opt)
if err != nil {
klog.Errorf("Failed to get all OBA pods: %v", err)
Expand Down Expand Up @@ -349,7 +353,11 @@ func CheckAllPodsAffinity(opt TestOptions) error {
}

for _, pod := range podList {

if pod.Labels["name"] == "endpoint-observability-operator" || pod.Labels["component"] == "metrics-collector" ||
pod.Labels["component"] == "uwl-metrics-collector" {
// No affinity set for endpoint-operator and metrics-collector
continue
}
if pod.Spec.Affinity == nil {
return fmt.Errorf("Failed to check affinity for pod: %v" + pod.GetName())
}
Expand Down
3 changes: 2 additions & 1 deletion tests/pkg/utils/mco_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
func GetPodList(opt TestOptions, isHub bool, namespace string, labelSelector string) (error, *v1.PodList) {
clientKube := getKubeClient(opt, isHub)
listOption := metav1.ListOptions{}
klog.Info("Get pod list in namespace ", namespace, " using labelselector ", labelSelector)
if labelSelector != "" {
listOption.LabelSelector = labelSelector
}
Expand All @@ -31,7 +32,7 @@ func GetPodList(opt TestOptions, isHub bool, namespace string, labelSelector str
return err, podList
}
if podList != nil && len(podList.Items) == 0 {
klog.V(1).Infof("No pod found for labelselector %s", labelSelector)
klog.V(1).Infof("No pod found for labelselector %s namespace %s", labelSelector, namespace)
}
return nil, podList
}
Expand Down

0 comments on commit e57c18f

Please sign in to comment.