I was looking on how to retry a Post request in case it failed. I first used github.com/avast/retry-go:

import retry "github.com/avast/retry-go/v4"

err := retry.Do(
    func() error {
        resp, err := client.Post(url, payload)
        if err != nil {
            return errors.New("failed to POST, will retry")
        }
        return nil
    },
    retry.Delay(time.Second*1),
    retry.Attempts(4),
)

But then I saw kubernetes has a similar function, wait:

import "k8s.io/apimachinery/pkg/util/wait"

var retryCounter int
err = wait.PollImmediate(retryInterval, retryTimeout,
    func() (done bool, err error) {
           retryCounter++
           resp, err = client.Post(url, payload)
           if err != nil || resp.StatusCode != http.StatusAccepted {
               log.Printf("failed to POST due to: %v will retry\n", err)
               return false, nil
           }
           if retryCounter > 2 {
                   log.Printf("this took %v retries to succeed\n", retryCounter)
           }
           return true, nil
    })

Please notice you have wait.Poll and wait.PollImmediate, difference is if the function, the POST request in this case, is longer then the interval. in the case of Poll it will wait even if the POST took more than the interval.