Skip to content

Commit 6a05fce

Browse files
committed
fake: Add ServiceAccount Token subresource
1 parent 4381fa0 commit 6a05fce

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/client/fake/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
jsonpatch "gopkg.in/evanphx/json-patch.v4"
3434
appsv1 "k8s.io/api/apps/v1"
3535
autoscalingv1 "k8s.io/api/autoscaling/v1"
36+
authenticationv1 "k8s.io/api/authentication/v1"
3637
corev1 "k8s.io/api/core/v1"
3738
policyv1 "k8s.io/api/policy/v1"
3839
policyv1beta1 "k8s.io/api/policy/v1beta1"
@@ -1156,6 +1157,19 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
11561157
}
11571158

11581159
return sw.client.Delete(ctx, obj)
1160+
case "token":
1161+
tokenRequest, isTokenRequest := subResource.(*authenticationv1.TokenRequest)
1162+
if !isTokenRequest {
1163+
return apierrors.NewBadRequest(fmt.Sprintf("got invalid type %T, expected TokenRequest", subResource))
1164+
}
1165+
if _, isServiceAccount := obj.(*corev1.ServiceAccount); !isServiceAccount {
1166+
return apierrors.NewNotFound(schema.GroupResource{}, "")
1167+
}
1168+
1169+
tokenRequest.Status.Token = "fake-token"
1170+
tokenRequest.Status.ExpirationTimestamp = metav1.Date(6041, 1, 1, 0, 0, 0, 0, time.UTC)
1171+
1172+
return nil
11591173
default:
11601174
return fmt.Errorf("fakeSubResourceWriter does not support create for %s", sw.subResource)
11611175
}

0 commit comments

Comments
 (0)