Skip to content

Instantly share code, notes, and snippets.

@SpComb
Created May 31, 2018 10:37
Show Gist options
  • Save SpComb/44c7663bd78b3d3ba61622d3d0dd399a to your computer and use it in GitHub Desktop.
Save SpComb/44c7663bd78b3d3ba61622d3d0dd399a to your computer and use it in GitHub Desktop.
util/retry RetryOnConflict returns nil err if fn returns wait.ErrWaitTimeout
$ go run main.go  
2018/05/31 13:37:05 watch.Util returned err=&errors.errorString{s:"timed out waiting for the condition"}
2018/05/31 13:37:05 RetryOnConflict returned err=<nil>
package main
import (
"log"
"time"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/util/retry"
)
func main() {
var watcher = watch.NewFake()
var timeout = 100 * time.Millisecond
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
if ev, err := watch.Until(timeout, watcher, func(event watch.Event) (bool, error) { return false, nil }); err != nil {
log.Printf("watch.Util returned err=%#v", err)
return err
} else {
log.Printf("watch.Until returned ev=%#v", ev)
return nil
}
})
log.Printf("RetryOnConflict returned err=%#v", err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment