If I create an object, how long do I wait before a get succeeds? I don't want to add a sleep with arbitrary values.
In the code below I try to create a service account and Secret. Then I try to fetch it immediately.
err := r.CreateSAandSecret()
if err != nil {
log.Info("Not able to create SA and secret ")
return "", err
}
// How long should the sleep be here ???
token, err := r.GetAuthorizationTokenfromSecret()
if err != nil {
log.Info("Not able to get token from secret")
}
If there is a better pattern, please advise.
There is no single answer. In theory it should always be read after write, but what you are asking about here is a derived object. That means you need to wait for the service account controller to see the new object and create the token secret. Controllers all use API watches which are driven from etcd watches. While it is generally fast, there is no way to guarantee any specific timing. Mostly it will slow down either under iops load for etcd or if you make 5 million service accounts at once, most controllers process one at a time. Also during Byzantine failures, it’s possible for watches to drop events meaning it would never happen (until you you manually restart the controller or otherwise trigger a reconcile).