Skip to content

Commit 2dc763a

Browse files
authored
test(e2e): wait for webhook to work after disruption (cloudnative-pg#7184)
Disruption tests could end with the webhook not yet able to reply. Wait until we know it can validate requests. Closes cloudnative-pg#7182 Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
1 parent 8e1861e commit 2dc763a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/e2e/operator_unavailable_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ package e2e
1818

1919
import (
2020
"sync"
21+
"time"
2122

2223
corev1 "k8s.io/api/core/v1"
24+
"k8s.io/apimachinery/pkg/api/errors"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2326
"k8s.io/apimachinery/pkg/types"
2427
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
2528

29+
apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
2630
"github.com/cloudnative-pg/cloudnative-pg/pkg/specs"
2731
"github.com/cloudnative-pg/cloudnative-pg/pkg/utils"
2832
"github.com/cloudnative-pg/cloudnative-pg/tests"
@@ -224,6 +228,20 @@ var _ = Describe("Operator unavailable", Serial, Label(tests.LabelDisruptive, te
224228
}, timeout).Should(BeTrue())
225229
})
226230
AssertDataExpectedCount(env, tableLocator, 2)
231+
232+
// There is a chance that the webhook is not able to reach the new operator pod yet.
233+
// This could make following tests fail, so we need to wait for the webhook to be working again.
234+
By("verifying the webhook is working again", func() {
235+
invalidCluster := &apiv1.Cluster{
236+
ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: "invalid"},
237+
Spec: apiv1.ClusterSpec{Instances: 1},
238+
}
239+
Eventually(func(g Gomega) {
240+
err := env.Client.Create(env.Ctx, invalidCluster)
241+
g.Expect(errors.IsInvalid(err)).To(BeTrue())
242+
g.Expect(err).To(MatchError(ContainSubstring("spec.storage.size")))
243+
}).WithTimeout(10 * time.Second).Should(Succeed())
244+
})
227245
})
228246
})
229247
})

0 commit comments

Comments
 (0)