From 18fb3dbb9dc7daf921d7d3c6cfe9aeea81d8ae92 Mon Sep 17 00:00:00 2001 From: Marek Schmidt Date: Tue, 27 Apr 2021 10:14:53 +0200 Subject: [PATCH] CreatePodOrFail retry on "No API token found" (#5313) --- test/lib/creation.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/lib/creation.go b/test/lib/creation.go index 4c057e01a1..574c5d3aff 100644 --- a/test/lib/creation.go +++ b/test/lib/creation.go @@ -26,6 +26,7 @@ import ( corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/api/errors" + apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/util/retry" @@ -583,11 +584,15 @@ func (c *Client) CreatePodOrFail(pod *corev1.Pod, options ...func(*corev1.Pod, * c.applyAdditionalEnv(&pod.Spec) - err := reconciler.RetryUpdateConflicts(func(attempts int) (err error) { + // the following retryable errors are expected when creating a blank Pod: + // - update conflicts + // - "No API token found for service account %q, + // retry after the token is automatically created and added to the service account" + err := reconciler.RetryErrors(func(attempts int) (err error) { c.T.Logf("Creating pod %+v", pod) _, e := c.Kube.CreatePod(context.Background(), pod) return e - }) + }, apierrs.IsConflict, apierrs.IsServerTimeout) if err != nil { c.T.Fatalf("Failed to create pod %q: %v", pod.Name, err) }