This repository was archived by the owner on Sep 18, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,22 @@ func NodeAnnotationCondition(selector fields.Selector) watch.ConditionFunc {
3535 }
3636}
3737
38+ // GetNodeRetry gets a node object, retrying up to DefaultBackoff number of times if it fails
39+ func GetNodeRetry (nc v1core.NodeInterface , node string ) (* v1api.Node , error ) {
40+ var apiNode * v1api.Node
41+ err := RetryOnError (DefaultBackoff , func () error {
42+ n , getErr := nc .Get (node , v1meta.GetOptions {})
43+ if getErr != nil {
44+ return fmt .Errorf ("failed to get node %q: %v" , node , getErr )
45+ }
46+
47+ apiNode = n
48+ return nil
49+ })
50+
51+ return apiNode , err
52+ }
53+
3854// UpdateNodeRetry calls f to update a node object in Kubernetes.
3955// It will attempt to update the node by applying f to it up to DefaultBackoff
4056// number of times.
Original file line number Diff line number Diff line change @@ -79,3 +79,21 @@ func RetryOnConflict(backoff wait.Backoff, fn func() error) error {
7979 }
8080 return err
8181}
82+
83+ // RetryOnError retries a function repeatedly with the specified backoff until it succeeds or times out
84+ func RetryOnError (backoff wait.Backoff , fn func () error ) error {
85+ var lastErr error
86+ err := wait .ExponentialBackoff (backoff , func () (bool , error ) {
87+ lastErr := fn ()
88+ if lastErr == nil {
89+ return true , nil
90+ }
91+
92+ return false , nil
93+ })
94+
95+ if err == wait .ErrWaitTimeout {
96+ err = lastErr
97+ }
98+ return err
99+ }
You can’t perform that action at this time.
0 commit comments