e2e: retry the certificate update due to optimistic locking

Signed-off-by: Maël Valais <mael@vls.dev>
This commit is contained in:
Maël Valais 2021-07-15 16:22:41 +02:00
parent e5436df521
commit 073fce8db5
2 changed files with 14 additions and 4 deletions

View File

@ -22,6 +22,8 @@ go_library(
"@com_github_onsi_gomega//:go_default_library",
"@io_k8s_api//core/v1: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",
],
)

View File

@ -24,6 +24,8 @@ import (
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
@ -798,12 +800,18 @@ func (s *Suite) Define() {
cert, err := f.Helper().CMClient.CertmanagerV1().Certificates(f.Namespace.Name).Get(context.TODO(), "testcert", metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
By("Adding an additional dnsName to the Certificate")
By("Updating the Certificate after having added an additional dnsName")
newDNSName := e2eutil.RandomSubdomain(s.DomainSuffix)
cert.Spec.DNSNames = append(cert.Spec.DNSNames, newDNSName)
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
err := f.CRClient.Get(context.Background(), types.NamespacedName{Namespace: f.Namespace.Name, Name: "testcert"}, cert)
if err != nil {
return err
}
By("Updating the Certificate in the apiserver")
err = f.CRClient.Update(context.TODO(), cert)
cert.Spec.DNSNames = append(cert.Spec.DNSNames, newDNSName)
return f.CRClient.Update(context.TODO(), cert)
})
Expect(err).NotTo(HaveOccurred())
By("Waiting for the Certificate Ready condition to be updated")