@@ -29,6 +29,7 @@ import (
2929 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030 "k8s.io/apimachinery/pkg/fields"
3131 "k8s.io/apimachinery/pkg/util/errors"
32+ "k8s.io/apimachinery/pkg/util/wait"
3233 k8sretry "k8s.io/client-go/util/retry"
3334 "k8s.io/kubernetes/pkg/kubelet/events"
3435 "k8s.io/kubernetes/test/e2e/framework"
@@ -1186,17 +1187,30 @@ func waitUntilRoleIsAssumableEKS[Input any, Output any](
11861187 })
11871188}
11881189
1190+ // Retries CreateToken for up to ~15s to handle transient API server errors
1191+ // (e.g. gRPC connection closing during token signing).
1192+ func createServiceAccountToken (ctx context.Context , f * framework.Framework , sa * v1.ServiceAccount , tokenRequest * authenticationv1.TokenRequest ) * authenticationv1.TokenRequest {
1193+ saClient := f .ClientSet .CoreV1 ().ServiceAccounts (sa .Namespace )
1194+ var serviceAccountToken * authenticationv1.TokenRequest
1195+ backoff := wait.Backoff {Steps : 5 , Duration : 500 * time .Millisecond , Factor : 2.0 , Jitter : 0.1 }
1196+ err := k8sretry .OnError (backoff , apierrors .IsInternalError , func () error {
1197+ var err error
1198+ serviceAccountToken , err = saClient .CreateToken (ctx , sa .Name , tokenRequest , metav1.CreateOptions {})
1199+ return err
1200+ })
1201+ framework .ExpectNoError (err )
1202+ return serviceAccountToken
1203+ }
1204+
11891205func waitUntilRoleIsAssumableWithWebIdentity (ctx context.Context , f * framework.Framework , sa * v1.ServiceAccount ) {
11901206 roleARN := sa .Annotations [roleARNAnnotation ]
11911207 framework .Logf ("Waiting until IAM role %s for ServiceAccount %s is assumable with web identity" , roleARN , sa .Name )
11921208
1193- saClient := f .ClientSet .CoreV1 ().ServiceAccounts (sa .Namespace )
1194- serviceAccountToken , err := saClient .CreateToken (ctx , sa .Name , & authenticationv1.TokenRequest {
1209+ serviceAccountToken := createServiceAccountToken (ctx , f , sa , & authenticationv1.TokenRequest {
11951210 Spec : authenticationv1.TokenRequestSpec {
11961211 Audiences : []string {serviceAccountTokenAudienceSTS },
11971212 },
1198- }, metav1.CreateOptions {})
1199- framework .ExpectNoError (err )
1213+ })
12001214
12011215 client := sts .NewFromConfig (awsConfig (ctx ))
12021216 waitUntilRoleIsAssumableSTS (ctx , client .AssumeRoleWithWebIdentity , & sts.AssumeRoleWithWebIdentityInput {
@@ -1214,8 +1228,7 @@ func waitUntilRoleIsAssumableWithEKS(ctx context.Context, f *framework.Framework
12141228
12151229 framework .Logf ("Waiting until IAM role for ServiceAccount %s is assumable for EKS Pod Identity (%s, %s, %s)" , sa .Name , pod .Name , pod .UID , pod .Namespace )
12161230
1217- saClient := f .ClientSet .CoreV1 ().ServiceAccounts (sa .Namespace )
1218- serviceAccountToken , err := saClient .CreateToken (ctx , sa .Name , & authenticationv1.TokenRequest {
1231+ serviceAccountToken := createServiceAccountToken (ctx , f , sa , & authenticationv1.TokenRequest {
12191232 ObjectMeta : metav1.ObjectMeta {
12201233 Namespace : pod .Namespace ,
12211234 },
@@ -1228,8 +1241,7 @@ func waitUntilRoleIsAssumableWithEKS(ctx context.Context, f *framework.Framework
12281241 UID : pod .UID ,
12291242 },
12301243 },
1231- }, metav1.CreateOptions {})
1232- framework .ExpectNoError (err )
1244+ })
12331245
12341246 client := eksauth .NewFromConfig (awsConfig (ctx ))
12351247 waitUntilRoleIsAssumableEKS (ctx , client .AssumeRoleForPodIdentity , & eksauth.AssumeRoleForPodIdentityInput {
0 commit comments