Skip to content

Commit 162cbc0

Browse files
committed
fix(e2e): make problematic test specs eventual
1 parent 5c4ee64 commit 162cbc0

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

test/e2e/catalog_e2e_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313

1414
"github.com/blang/semver"
1515
. "github.com/onsi/ginkgo"
16+
. "github.com/onsi/gomega"
1617
"github.com/stretchr/testify/require"
1718
appsv1 "k8s.io/api/apps/v1"
1819
corev1 "k8s.io/api/core/v1"
1920
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
21+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2022
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2123
"k8s.io/apimachinery/pkg/labels"
2224
"k8s.io/apimachinery/pkg/util/wait"
@@ -595,8 +597,13 @@ var _ = Describe("Catalog", func() {
595597
require.NoError(GinkgoT(), err)
596598

597599
// Delete the registry pod
598-
err = c.KubernetesInterface().CoreV1().Pods(testNamespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
599-
require.NoError(GinkgoT(), err)
600+
Eventually(func() error {
601+
err := c.KubernetesInterface().CoreV1().Pods(testNamespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
602+
if apierrors.IsNotFound(err) {
603+
err = nil
604+
}
605+
return err
606+
}).Should(Succeed())
600607

601608
// Wait for a new registry pod to be created
602609
notUID := func(pods *corev1.PodList) bool {

test/e2e/metrics_e2e_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,14 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
252252
func getPodWithLabel(client operatorclient.ClientInterface, label string) *corev1.Pod {
253253
listOptions := metav1.ListOptions{LabelSelector: label}
254254
var podList *corev1.PodList
255-
EventuallyWithOffset(1, func() (err error) {
255+
EventuallyWithOffset(1, func() (numPods int, err error) {
256256
podList, err = client.KubernetesInterface().CoreV1().Pods(operatorNamespace).List(context.TODO(), listOptions)
257+
if podList != nil {
258+
numPods = len(podList.Items)
259+
}
260+
257261
return
258-
}).Should(Succeed(), "Failed to list OLM pods")
259-
Expect(len(podList.Items)).To(Equal(1))
262+
}).Should(Equal(1), "number of pods never scaled to one")
260263

261264
return &podList.Items[0]
262265
}

test/e2e/util_test.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -784,24 +784,25 @@ const (
784784
func toggleCVO() {
785785
c := ctx.Ctx().KubeClient().KubernetesInterface().AppsV1().Deployments(cvoNamespace)
786786
clientCtx := context.Background()
787-
scale, err := c.GetScale(clientCtx, cvoDeploymentName, metav1.GetOptions{})
788-
if err != nil {
789-
if apierrors.IsNotFound(err) {
790-
// CVO is not enabled
791-
return
792-
}
793787

794-
Expect(err).ToNot(HaveOccurred())
795-
}
788+
Eventually(func() error {
789+
scale, err := c.GetScale(clientCtx, cvoDeploymentName, metav1.GetOptions{})
790+
if err != nil {
791+
if apierrors.IsNotFound(err) {
792+
// CVO is not enabled
793+
return nil
794+
}
796795

797-
if scale.Spec.Replicas > 0 {
798-
scale.Spec.Replicas = 0
799-
} else {
800-
scale.Spec.Replicas = 1
801-
}
796+
return err
797+
}
802798

803-
Eventually(func() error {
804-
_, err := c.UpdateScale(clientCtx, cvoDeploymentName, scale, metav1.UpdateOptions{})
799+
if scale.Spec.Replicas > 0 {
800+
scale.Spec.Replicas = 0
801+
} else {
802+
scale.Spec.Replicas = 1
803+
}
804+
805+
_, err = c.UpdateScale(clientCtx, cvoDeploymentName, scale, metav1.UpdateOptions{})
805806
return err
806807
}).Should(Succeed())
807808
}

test/e2e/webhook_e2e_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
v1 "github.com/operator-framework/api/pkg/operators/v1"
1818
"github.com/operator-framework/api/pkg/operators/v1alpha1"
19+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
1920
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
2021
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
2122
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
@@ -414,11 +415,13 @@ var _ = Describe("CSVs with a Webhook", func() {
414415
Expect(ok).Should(BeTrue())
415416

416417
// Induce a cert rotation
417-
now := metav1.Now()
418-
fetchedCSV.Status.CertsLastUpdated = &now
419-
fetchedCSV.Status.CertsRotateAt = &now
420-
fetchedCSV, err = crc.OperatorsV1alpha1().ClusterServiceVersions(namespace.Name).UpdateStatus(context.TODO(), fetchedCSV, metav1.UpdateOptions{})
421-
Expect(err).Should(BeNil())
418+
Eventually(Apply(fetchedCSV, func(csv *operatorsv1alpha1.ClusterServiceVersion) error {
419+
now := metav1.Now()
420+
csv.Status.CertsLastUpdated = &now
421+
csv.Status.CertsRotateAt = &now
422+
return nil
423+
})).Should(Succeed())
424+
422425
_, err = fetchCSV(crc, csv.Name, namespace.Name, func(csv *v1alpha1.ClusterServiceVersion) bool {
423426
// Should create deployment
424427
dep, err = c.GetDeployment(namespace.Name, csv.Spec.WebhookDefinitions[0].DeploymentName)

0 commit comments

Comments
 (0)