Skip to content

Commit 1b19f6f

Browse files
committed
add retries w/ exponential backoff
1 parent dba2b0d commit 1b19f6f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/cache/cache.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
v1 "k8s.io/api/core/v1"
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
33+
"k8s.io/apimachinery/pkg/util/wait"
3334
coreinformers "k8s.io/client-go/informers/core/v1"
3435
"k8s.io/client-go/kubernetes"
3536
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -370,7 +371,17 @@ func fetchFromAPI(getter corev1.ServiceAccountsGetter, req *Request) (*v1.Servic
370371

371372
klog.V(5).Infof("fetching SA: %s", req.CacheKey())
372373

373-
return getter.ServiceAccounts(req.Namespace).Get(ctx, req.Name, metav1.GetOptions{})
374+
var sa *v1.ServiceAccount
375+
err := wait.ExponentialBackoffWithContext(ctx, wait.Backoff{Duration: 10 * time.Millisecond, Factor: 2.0, Steps: 3}, func(ctx context.Context) (bool, error) {
376+
res, err := getter.ServiceAccounts(req.Namespace).Get(ctx, req.Name, metav1.GetOptions{})
377+
if err != nil {
378+
return false, err
379+
}
380+
sa = res
381+
return true, nil
382+
})
383+
384+
return sa, err
374385
}
375386

376387
func (c *serviceAccountCache) populateCacheFromCM(oldCM, newCM *v1.ConfigMap) error {

0 commit comments

Comments
 (0)