Merge pull request #63416 from smarterclayton/retry_approve

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Retry certificate approval on conflict errors

We already check preconditions. We were seeing a non-trivial number of conflicts when using the command from automation.

Fixes openshift/origin#19430

@mikedanese @mfojtik
pull/8/head
Kubernetes Submit Queue 2018-05-16 10:21:44 -07:00 committed by GitHub
commit 44dd0c2431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 8 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"io"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api/legacyscheme"
@ -220,15 +221,24 @@ func (options *CertificateOptions) modifyCertificateCondition(builder *resource.
if err != nil {
return err
}
csr := info.Object.(*certificates.CertificateSigningRequest)
csr, hasCondition := modify(csr)
if !hasCondition || force {
csr, err = clientSet.Certificates().
CertificateSigningRequests().
UpdateApproval(csr)
if err != nil {
return err
for i := 0; ; i++ {
csr := info.Object.(*certificates.CertificateSigningRequest)
csr, hasCondition := modify(csr)
if !hasCondition || force {
csr, err = clientSet.Certificates().
CertificateSigningRequests().
UpdateApproval(csr)
if errors.IsConflict(err) && i < 10 {
if err := info.Get(); err != nil {
return err
}
continue
}
if err != nil {
return err
}
}
break
}
found++