Skip to content

Commit

Permalink
fake: Add ServiceAccount Token subresource
Browse files Browse the repository at this point in the history
  • Loading branch information
glennpratt committed Oct 3, 2024
1 parent 4381fa0 commit 6a05fce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
jsonpatch "gopkg.in/evanphx/json-patch.v4"
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
authenticationv1 "k8s.io/api/authentication/v1"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
Expand Down Expand Up @@ -1156,6 +1157,19 @@ func (sw *fakeSubResourceClient) Create(ctx context.Context, obj client.Object,
}

return sw.client.Delete(ctx, obj)
case "token":
tokenRequest, isTokenRequest := subResource.(*authenticationv1.TokenRequest)
if !isTokenRequest {
return apierrors.NewBadRequest(fmt.Sprintf("got invalid type %T, expected TokenRequest", subResource))
}
if _, isServiceAccount := obj.(*corev1.ServiceAccount); !isServiceAccount {
return apierrors.NewNotFound(schema.GroupResource{}, "")
}

tokenRequest.Status.Token = "fake-token"
tokenRequest.Status.ExpirationTimestamp = metav1.Date(6041, 1, 1, 0, 0, 0, 0, time.UTC)

return nil
default:
return fmt.Errorf("fakeSubResourceWriter does not support create for %s", sw.subResource)
}
Expand Down

0 comments on commit 6a05fce

Please sign in to comment.