Skip to content

Commit

Permalink
add retries w/ exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
modulitos committed Nov 26, 2024
1 parent dba2b0d commit 1b19f6f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1b19f6f

Please sign in to comment.