2 Copyright 2016 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
22 "k8s.io/apimachinery/pkg/api/errors"
23 "k8s.io/apimachinery/pkg/util/wait"
26 // DefaultRetry is the recommended retry for a conflict where multiple clients
27 // are making changes to the same resource.
28 var DefaultRetry = wait.Backoff{
30 Duration: 10 * time.Millisecond,
35 // DefaultBackoff is the recommended backoff for a conflict where a client
36 // may be attempting to make an unrelated modification to a resource under
37 // active management by one or more controllers.
38 var DefaultBackoff = wait.Backoff{
40 Duration: 10 * time.Millisecond,
45 // RetryConflict executes the provided function repeatedly, retrying if the server returns a conflicting
46 // write. Callers should preserve previous executions if they wish to retry changes. It performs an
47 // exponential backoff.
50 // err := RetryOnConflict(DefaultBackoff, func() (err error) {
51 // pod, err = c.Pods("mynamespace").UpdateStatus(podStatus)
55 // // may be conflict if max retries were hit
60 // TODO: Make Backoff an interface?
61 func RetryOnConflict(backoff wait.Backoff, fn func() error) error {
62 var lastConflictErr error
63 err := wait.ExponentialBackoff(backoff, func() (bool, error) {
68 case errors.IsConflict(err):
75 if err == wait.ErrWaitTimeout {