From 97e3f8cc5e94674bc03325bfcb2cb3be848b9678 Mon Sep 17 00:00:00 2001 From: perdasilva Date: Sun, 27 Mar 2022 11:22:09 +0200 Subject: [PATCH] Move metrics e2e to one namespace per spec Signed-off-by: perdasilva --- test/e2e/metrics_e2e_test.go | 60 ++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/test/e2e/metrics_e2e_test.go b/test/e2e/metrics_e2e_test.go index f89bc2b7e1b..a625637f17a 100644 --- a/test/e2e/metrics_e2e_test.go +++ b/test/e2e/metrics_e2e_test.go @@ -33,14 +33,20 @@ import ( var _ = Describe("Metrics are generated for OLM managed resources", func() { var ( - c operatorclient.ClientInterface - crc versioned.Interface + c operatorclient.ClientInterface + crc versioned.Interface + generatedNamespace corev1.Namespace ) BeforeEach(func() { c = newKubeClient() crc = newCRClient() + namespaceName := genName("metrics-e2e-") + generatedNamespace = SetupGeneratedTestNamespace(namespaceName, namespaceName) + }) + AfterEach(func() { + TeardownNamespace(generatedNamespace.GetName()) }) Context("Given an OperatorGroup that supports all namespaces", func() { @@ -74,10 +80,10 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { } var err error - cleanupCSV, err = createCSV(c, crc, failingCSV, testNamespace, false, false) + cleanupCSV, err = createCSV(c, crc, failingCSV, generatedNamespace.GetName(), false, false) Expect(err).ToNot(HaveOccurred()) - _, err = fetchCSV(crc, failingCSV.Name, testNamespace, csvFailedChecker) + _, err = fetchCSV(crc, failingCSV.Name, generatedNamespace.GetName(), csvFailedChecker) Expect(err).ToNot(HaveOccurred()) }) @@ -127,12 +133,12 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { BeforeEach(func() { packageName := genName("csv-test-") packageStable := fmt.Sprintf("%s-stable", packageName) - csv = newCSV(packageStable, testNamespace, "", semver.MustParse("0.1.0"), nil, nil, nil) + csv = newCSV(packageStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), nil, nil, nil) var err error - _, err = createCSV(c, crc, csv, testNamespace, false, false) + _, err = createCSV(c, crc, csv, generatedNamespace.GetName(), false, false) Expect(err).ToNot(HaveOccurred()) - _, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker) + _, err = fetchCSV(crc, csv.Name, generatedNamespace.GetName(), csvSucceededChecker) Expect(err).ToNot(HaveOccurred()) }) AfterEach(func() { @@ -170,7 +176,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { When("A subscription object is created", func() { BeforeEach(func() { - subscriptionCleanup, _ = createSubscription(GinkgoT(), crc, testNamespace, "metric-subscription-for-create", testPackageName, stableChannel, v1alpha1.ApprovalManual) + subscriptionCleanup, _ = createSubscription(GinkgoT(), crc, generatedNamespace.GetName(), "metric-subscription-for-create", testPackageName, stableChannel, v1alpha1.ApprovalManual) }) AfterEach(func() { @@ -211,17 +217,17 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { When("A subscription object is updated after emitting metrics", func() { BeforeEach(func() { - subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, testNamespace, "metric-subscription-for-update", testPackageName, stableChannel, v1alpha1.ApprovalManual) + subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, generatedNamespace.GetName(), "metric-subscription-for-update", testPackageName, stableChannel, v1alpha1.ApprovalManual) Eventually(func() []Metric { return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator")) }).Should(ContainElement(LikeMetric(WithFamily("subscription_sync_total"), WithLabel("name", "metric-subscription-for-update")))) Eventually(func() error { - s, err := crc.OperatorsV1alpha1().Subscriptions(subscription.GetNamespace()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{}) + s, err := crc.OperatorsV1alpha1().Subscriptions(subscription.GetNamespace()).Get(context.Background(), subscription.GetName(), metav1.GetOptions{}) if err != nil { return err } s.Spec.Channel = betaChannel - _, err = crc.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Update(context.TODO(), s, metav1.UpdateOptions{}) + _, err = crc.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Update(context.Background(), s, metav1.UpdateOptions{}) return err }).Should(Succeed()) }) @@ -256,12 +262,12 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { BeforeEach(func() { Eventually(func() error { - s, err := crc.OperatorsV1alpha1().Subscriptions(subscription.GetNamespace()).Get(context.TODO(), subscription.GetName(), metav1.GetOptions{}) + s, err := crc.OperatorsV1alpha1().Subscriptions(subscription.GetNamespace()).Get(context.Background(), subscription.GetName(), metav1.GetOptions{}) if err != nil { return err } s.Spec.Channel = alphaChannel - _, err = crc.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Update(context.TODO(), s, metav1.UpdateOptions{}) + _, err = crc.OperatorsV1alpha1().Subscriptions(s.GetNamespace()).Update(context.Background(), s, metav1.UpdateOptions{}) return err }).Should(Succeed()) }) @@ -296,7 +302,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { When("A subscription object is deleted after emitting metrics", func() { BeforeEach(func() { - subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, testNamespace, "metric-subscription-for-delete", testPackageName, stableChannel, v1alpha1.ApprovalManual) + subscriptionCleanup, subscription = createSubscription(GinkgoT(), crc, generatedNamespace.GetName(), "metric-subscription-for-delete", testPackageName, stableChannel, v1alpha1.ApprovalManual) Eventually(func() []Metric { return getMetricsFromPod(c, getPodWithLabel(c, "app=catalog-operator")) }).Should(ContainElement(LikeMetric(WithFamily("subscription_sync_total"), WithLabel("name", "metric-subscription-for-delete")))) @@ -334,7 +340,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { stableChannel := "stable" mainCRD := newCRD(genName("ins-")) - mainCSV := newCSV(mainPackageStable, testNamespace, "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, nil) + mainCSV := newCSV(mainPackageStable, generatedNamespace.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, nil) mainManifests := []registry.PackageManifest{ { @@ -345,7 +351,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { DefaultChannelName: stableChannel, }, } - cs, cleanupAll := createInternalCatalogSource(c, crc, name, testNamespace, mainManifests, []apiextensions.CustomResourceDefinition{mainCRD}, []v1alpha1.ClusterServiceVersion{mainCSV}) + cs, cleanupAll := createInternalCatalogSource(c, crc, name, generatedNamespace.GetName(), mainManifests, []apiextensions.CustomResourceDefinition{mainCRD}, []v1alpha1.ClusterServiceVersion{mainCSV}) // Note(tflannag): Dependending on how ginkgo orders these test specs, and how bloated the cluster we're running // this test case against, we risk creating and then immediately deleting the catalogsource before the catalog // operator can generate all the requisite resources (e.g. the ServiceAccount), which can leave the underlying @@ -373,7 +379,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { ContainElement(LikeMetric( WithFamily("catalogsource_ready"), WithName(name), - WithNamespace(testNamespace), + WithNamespace(generatedNamespace.GetName()), WithValue(1), )), )) @@ -389,7 +395,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { Not(ContainElement(LikeMetric( WithFamily("catalogsource_ready"), WithName(name), - WithNamespace(testNamespace), + WithNamespace(generatedNamespace.GetName()), ))))) }) }) @@ -401,7 +407,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { cleanup func() ) BeforeEach(func() { - _, cleanup = createInvalidGRPCCatalogSource(crc, name, testNamespace) + _, cleanup = createInvalidGRPCCatalogSource(crc, name, generatedNamespace.GetName()) }) AfterEach(func() { cleanup() @@ -413,7 +419,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { ContainElement(LikeMetric( WithFamily("catalogsource_ready"), WithName(name), - WithNamespace(testNamespace), + WithNamespace(generatedNamespace.GetName()), WithValue(0), )), )) @@ -423,7 +429,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() { ContainElement(LikeMetric( WithFamily("catalogsource_ready"), WithName(name), - WithNamespace(testNamespace), + WithNamespace(generatedNamespace.GetName()), WithValue(0), )), )) @@ -436,7 +442,7 @@ func getPodWithLabel(client operatorclient.ClientInterface, label string) *corev listOptions := metav1.ListOptions{LabelSelector: label} var podList *corev1.PodList EventuallyWithOffset(1, func() (numPods int, err error) { - podList, err = client.KubernetesInterface().CoreV1().Pods(operatorNamespace).List(context.TODO(), listOptions) + podList, err = client.KubernetesInterface().CoreV1().Pods(operatorNamespace).List(context.Background(), listOptions) if podList != nil { numPods = len(podList.Items) } @@ -451,7 +457,7 @@ func getDeploymentWithLabel(client operatorclient.ClientInterface, label string) listOptions := metav1.ListOptions{LabelSelector: label} var deploymentList *appsv1.DeploymentList EventuallyWithOffset(1, func() (numDeps int, err error) { - deploymentList, err = client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).List(context.TODO(), listOptions) + deploymentList, err = client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).List(context.Background(), listOptions) if deploymentList != nil { numDeps = len(deploymentList.Items) } @@ -467,11 +473,11 @@ func restartDeploymentWithLabel(client operatorclient.ClientInterface, l string) z := int32(0) oldZ := *d.Spec.Replicas d.Spec.Replicas = &z - _, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Update(context.TODO(), d, metav1.UpdateOptions{}) + _, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Update(context.Background(), d, metav1.UpdateOptions{}) Expect(err).ToNot(HaveOccurred()) EventuallyWithOffset(1, func() (replicas int32, err error) { - deployment, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Get(context.TODO(), d.Name, metav1.GetOptions{}) + deployment, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Get(context.Background(), d.Name, metav1.GetOptions{}) if deployment != nil { replicas = deployment.Status.Replicas } @@ -480,11 +486,11 @@ func restartDeploymentWithLabel(client operatorclient.ClientInterface, l string) updated := getDeploymentWithLabel(client, l) updated.Spec.Replicas = &oldZ - _, err = client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Update(context.TODO(), updated, metav1.UpdateOptions{}) + _, err = client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Update(context.Background(), updated, metav1.UpdateOptions{}) Expect(err).ToNot(HaveOccurred()) EventuallyWithOffset(1, func() (replicas int32, err error) { - deployment, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Get(context.TODO(), d.Name, metav1.GetOptions{}) + deployment, err := client.KubernetesInterface().AppsV1().Deployments(operatorNamespace).Get(context.Background(), d.Name, metav1.GetOptions{}) if deployment != nil { replicas = deployment.Status.Replicas }