e2e: fix flakiness: "CA Injector should update data when the certificate changes"

The error:

    Operation cannot be fulfilled on certificates.cert-manager.io "serving-certs"

has appeared in 162 different prow builds in the past.

Signed-off-by: Maël Valais <mael@vls.dev>
This commit is contained in:
Maël Valais 2022-03-06 11:22:36 +01:00
parent 14904306de
commit 6620f4b024
2 changed files with 16 additions and 3 deletions

View File

@ -19,6 +19,7 @@ go_library(
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/runtime:go_default_library",
"@io_k8s_apimachinery//pkg/types:go_default_library",
"@io_k8s_client_go//util/retry:go_default_library",
"@io_k8s_kube_aggregator//pkg/apis/apiregistration/v1:go_default_library",
"@io_k8s_sigs_controller_runtime//pkg/client:go_default_library",
],

View File

@ -29,6 +29,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
apireg "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
certmanager "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
@ -152,9 +153,20 @@ var _ = framework.CertManagerDescribe("CA Injector", func() {
injectable, cert := generalSetup(test.makeInjectable("changed"))
By("changing the name of the corresponding secret in the cert")
cert = cert.DeepCopy() // DeepCopy before updating
cert.Spec.DNSNames = append(cert.Spec.DNSNames, "something.com")
Expect(f.CRClient.Update(context.Background(), cert)).To(Succeed())
retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := f.CRClient.Get(context.Background(), types.NamespacedName{Name: cert.Name, Namespace: cert.Namespace}, cert)
if err != nil {
return err
}
cert.Spec.DNSNames = append(cert.Spec.DNSNames, "something.com")
err = f.CRClient.Update(context.Background(), cert)
if err != nil {
return err
}
return nil
})
cert, err := f.Helper().WaitForCertificateReadyAndDoneIssuing(cert, time.Second*30)
Expect(err).NotTo(HaveOccurred(), "failed to wait for Certificate to become updated")