From 1b19f6ffd150a7a21a74f222265b25e3f37c0e34 Mon Sep 17 00:00:00 2001 From: modulitos Date: Mon, 25 Nov 2024 17:31:36 -0800 Subject: [PATCH] add retries w/ exponential backoff --- pkg/cache/cache.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 37b5f929..8c8b1721 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -30,6 +30,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/wait" coreinformers "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" corev1 "k8s.io/client-go/kubernetes/typed/core/v1" @@ -370,7 +371,17 @@ func fetchFromAPI(getter corev1.ServiceAccountsGetter, req *Request) (*v1.Servic klog.V(5).Infof("fetching SA: %s", req.CacheKey()) - return getter.ServiceAccounts(req.Namespace).Get(ctx, req.Name, metav1.GetOptions{}) + var sa *v1.ServiceAccount + err := wait.ExponentialBackoffWithContext(ctx, wait.Backoff{Duration: 10 * time.Millisecond, Factor: 2.0, Steps: 3}, func(ctx context.Context) (bool, error) { + res, err := getter.ServiceAccounts(req.Namespace).Get(ctx, req.Name, metav1.GetOptions{}) + if err != nil { + return false, err + } + sa = res + return true, nil + }) + + return sa, err } func (c *serviceAccountCache) populateCacheFromCM(oldCM, newCM *v1.ConfigMap) error {