Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move metrics e2e to one namespace per spec #2716

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 33 additions & 27 deletions test/e2e/metrics_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this BeforeEach that's nested in the first Context container (lines 53-55) still relevant now:

		BeforeEach(func() {
			By("using the default OperatorGroup created in BeforeSuite")
		})

})

Context("Given an OperatorGroup that supports all namespaces", func() {
Expand Down Expand Up @@ -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())
})

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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())
})
Expand Down Expand Up @@ -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())
})
Expand Down Expand Up @@ -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"))))
Expand Down Expand Up @@ -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{
{
Expand All @@ -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
Expand Down Expand Up @@ -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),
)),
))
Expand All @@ -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()),
)))))
})
})
Expand All @@ -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()
Expand All @@ -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),
)),
))
Expand All @@ -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),
)),
))
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down