Skip to content

Commit

Permalink
make CRD storage version update always retry
Browse files Browse the repository at this point in the history
  • Loading branch information
roycaihw committed Feb 18, 2021
1 parent 6ddc1eb commit 100aa3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,6 @@ func (m *manager) updateCRDStorageVersion(ctx context.Context, crd *apiextension
gr,
encodingVersion,
decodableVersions,
appendOwnerRefFunc)
appendOwnerRefFunc,
true)
}
2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiserver/pkg/storageversion/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *defaultManager) UpdateStorageVersions(kubeAPIServerClientConfig *rest.C
if len(gr.Group) == 0 {
gr.Group = "core"
}
if err := UpdateStorageVersionFor(context.TODO(), sc, serverID, gr, r.EncodingVersion, dv, nil); err != nil {
if err := UpdateStorageVersionFor(context.TODO(), sc, serverID, gr, r.EncodingVersion, dv, nil, false); err != nil {
utilruntime.HandleError(fmt.Errorf("failed to update storage version for %v: %v", r.GroupResource, err))
s.recordStatusFailure(&r, err)
hasFailure = true
Expand Down
7 changes: 5 additions & 2 deletions staging/src/k8s.io/apiserver/pkg/storageversion/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func setStatusCondition(conditions *[]v1alpha1.StorageVersionCondition, newCondi
// calulation is finished, and before the client sends the create/update request.
// It allows the caller to customizes the storage version object, e.g. setting
// an owner reference.
func UpdateStorageVersionFor(ctx context.Context, c Client, apiserverID string, gr schema.GroupResource, encodingVersion string, decodableVersions []string, postProcessFunc processStorageVersionFunc) error {
func UpdateStorageVersionFor(ctx context.Context, c Client, apiserverID string, gr schema.GroupResource, encodingVersion string, decodableVersions []string, postProcessFunc processStorageVersionFunc, alwaysRetry bool) error {
retries := 3
var retry int
var err error
for retry < retries {
for {
select {
case <-ctx.Done():
return ctx.Err()
Expand All @@ -153,6 +153,9 @@ func UpdateStorageVersionFor(ctx context.Context, c Client, apiserverID string,
retry++
time.Sleep(1 * time.Second)
}
if !alwaysRetry && retry >= retries {
break
}
}
return err
}
Expand Down

0 comments on commit 100aa3b

Please sign in to comment.