From 6b7262ba93c9d95a4a628abd28794190b6a1ef16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Valais?= Date: Sun, 6 Mar 2022 10:54:53 +0100 Subject: [PATCH] e2e: retry on conflict for the test "added an additional dnsName" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test: [Conformance] Certificates with issuer type ACME DNS01 Issuer should allow updating an existing certificate with a new dns name was flaky due to an update that was not properly retried on conflict. The error was: Operation cannot be fulfilled on certificates.cert-manager.io \"testcert\": the object has been modified This error appeared in 127 different prow jobs. Signed-off-by: Maƫl Valais --- .../suite/conformance/certificates/BUILD.bazel | 2 ++ .../suite/conformance/certificates/tests.go | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/test/e2e/suite/conformance/certificates/BUILD.bazel b/test/e2e/suite/conformance/certificates/BUILD.bazel index bd34d46fe..2854df0ca 100644 --- a/test/e2e/suite/conformance/certificates/BUILD.bazel +++ b/test/e2e/suite/conformance/certificates/BUILD.bazel @@ -26,6 +26,8 @@ go_library( "@io_k8s_api//networking/v1:go_default_library", "@io_k8s_api//networking/v1beta1:go_default_library", "@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library", + "@io_k8s_apimachinery//pkg/types:go_default_library", + "@io_k8s_client_go//util/retry:go_default_library", ], ) diff --git a/test/e2e/suite/conformance/certificates/tests.go b/test/e2e/suite/conformance/certificates/tests.go index 7400043ca..583d5f1fc 100644 --- a/test/e2e/suite/conformance/certificates/tests.go +++ b/test/e2e/suite/conformance/certificates/tests.go @@ -27,6 +27,8 @@ import ( networkingv1 "k8s.io/api/networking/v1" networkingv1beta1 "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/util/retry" "github.com/cert-manager/cert-manager/internal/controller/feature" cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" @@ -888,11 +890,21 @@ func (s *Suite) Define() { Expect(err).NotTo(HaveOccurred()) By("Updating the Certificate after having added an additional dnsName") - testCertificate = testCertificate.DeepCopy() // DeepCopy before updating newDNSName := e2eutil.RandomSubdomain(s.DomainSuffix) - testCertificate.Spec.DNSNames = append(testCertificate.Spec.DNSNames, newDNSName) + retry.RetryOnConflict(retry.DefaultRetry, func() error { + err = f.CRClient.Get(context.Background(), types.NamespacedName{Name: testCertificate.Name, Namespace: testCertificate.Namespace}, testCertificate) + if err != nil { + return err + } + + testCertificate.Spec.DNSNames = append(testCertificate.Spec.DNSNames, newDNSName) + err = f.CRClient.Update(context.Background(), testCertificate) + if err != nil { + return err + } + return nil + }) - err = f.CRClient.Update(context.TODO(), testCertificate) Expect(err).NotTo(HaveOccurred()) By("Waiting for the Certificate Ready condition to be updated")