Skip to content

Commit

Permalink
CreatePodOrFail retry on "No API token found" (#5313)
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmid authored Apr 27, 2021
1 parent 504cae3 commit 18fb3db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/lib/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 18fb3db

Please sign in to comment.