Skip to content

Commit d0e4789

Browse files
Merge pull request #1092 from perdasilva/plugin-e2e-stability-fix
NO-ISSUE: make downstream csv namespace labeler plugin e2e more resilient to race conditions
2 parents 3af8ef7 + ea4354d commit d0e4789

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

staging/operator-lifecycle-manager/test/e2e/downstream_csv_namespace_labeler_plugin_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package e2e
22

33
import (
44
"context"
5-
65
"github.com/blang/semver/v4"
76
. "github.com/onsi/ginkgo/v2"
87
. "github.com/onsi/gomega"
@@ -88,11 +87,18 @@ var _ = Describe("CSV Namespace Labeler Plugin", func() {
8887
}).Should(HaveKeyWithValue(plugins.NamespaceLabelSyncerLabelKey, "true"))
8988

9089
// delete label
91-
ns := &v1.Namespace{}
92-
Expect(determinedE2eClient.Get(context.Background(), k8scontrollerclient.ObjectKeyFromObject(&testNamespace), ns)).To(Succeed())
93-
nsCopy := ns.DeepCopy()
94-
delete(nsCopy.Annotations, plugins.NamespaceLabelSyncerLabelKey)
95-
Expect(determinedE2eClient.Update(context.Background(), nsCopy)).To(Succeed())
90+
// NOTE: not using the determined client here because it shouldn't be used for update operations due to
91+
// race conditions (the updated resource could change b/w 'get' and 'update' operations
92+
c := ctx.Ctx().E2EClient()
93+
Eventually(func() error {
94+
ns := &v1.Namespace{}
95+
if err := c.Get(context.Background(), k8scontrollerclient.ObjectKeyFromObject(&testNamespace), ns); err != nil {
96+
return err
97+
}
98+
nsCopy := ns.DeepCopy()
99+
delete(nsCopy.Annotations, plugins.NamespaceLabelSyncerLabelKey)
100+
return c.Update(context.Background(), nsCopy)
101+
}).Should(BeNil())
96102

97103
// namespace should be labeled
98104
Eventually(func() (map[string]string, error) {

staging/operator-lifecycle-manager/test/e2e/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ func HaveMessage(goal string) gtypes.GomegaMatcher {
10681068
func SetupGeneratedTestNamespaceWithOperatorGroup(name string, og operatorsv1.OperatorGroup) corev1.Namespace {
10691069
ns := corev1.Namespace{
10701070
ObjectMeta: metav1.ObjectMeta{
1071-
Name: name,
1071+
Name: name,
10721072
Labels: map[string]string{},
10731073
},
10741074
}

staging/operator-lifecycle-manager/test/e2e/util/e2e_determined_client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func (m *DeterminedE2EClient) Create(context context.Context, obj k8scontrollerc
2828
return nil
2929
}
3030

31+
// Update retries update operation until success or timeout
32+
//
33+
// Deprecation: do not use this method as it's not resilient to the case where the resource has changed out of band
34+
// it will conflict until it times out.
35+
// There's no priority to fix this client implementation - please use regular client instead
3136
func (m *DeterminedE2EClient) Update(context context.Context, obj k8scontrollerclient.Object, options ...k8scontrollerclient.UpdateOption) error {
3237
m.keepTrying(func() error {
3338
return m.E2EKubeClient.Update(context, obj, options...)

0 commit comments

Comments
 (0)