You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Mock Kubernetes client
k8sClient := fake.NewClientset()
// Mock service account
serviceAccountName := "test-service-account"
namespace := "test-namespace"
roleArn := "arn:aws:iam::123456789012:role/test-role"
tokenAudience := "sts.amazonaws.com"
// Create a mock service account object with annotations
mockSA := &corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceAccount",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: serviceAccountName,
Namespace: namespace,
Annotations: map[string]string{
roleARNAnnotation: roleArn,
audienceAnnotation: tokenAudience,
},
},
}
ctx := context.TODO()
// Create the mock service account
_, err := k8sClient.CoreV1().ServiceAccounts(namespace).Create(ctx, mockSA, metav1.CreateOptions{})
if err != nil {
t.Fatalf("failed to create mock service account: %v", err)
}
// Create the token for service account
token, err := k8sClient.CoreV1().ServiceAccounts(namespace).CreateToken(ctx, serviceAccountName, &authv1.TokenRequest{
Spec: authv1.TokenRequestSpec{
Audiences: []string{tokenAudience},
},
}, metav1.CreateOptions{})
if err != nil {
t.Fatalf("failed to create service account token: %v", err)
}
When I run this code, I get the error: failed to create service account token: serviceaccounts "" not found however, I can see that the serviceaccount is created properly by fake client. Not sure why the CreateToken call is refering to a blank serviceaccount. I tried figuring out the issue, but couldn't find the exact root cause.
Anybody experienced this issue before? Any help/suggestions would be appreciated.
The text was updated successfully, but these errors were encountered:
gdasson
changed the title
fake client gives error using CreateToken operation
fake client gives error using CreateToken operation for ServiceAccounts
Dec 23, 2024
I have the below code in a test function
When I run this code, I get the error:
failed to create service account token: serviceaccounts "" not found
however, I can see that the serviceaccount is created properly by fake client. Not sure why the CreateToken call is refering to a blank serviceaccount. I tried figuring out the issue, but couldn't find the exact root cause.Anybody experienced this issue before? Any help/suggestions would be appreciated.
The text was updated successfully, but these errors were encountered: