python icon indicating copy to clipboard operation
python copied to clipboard

kubernetes.client.AuthenticationV1TokenRequest() fails

Open jhourque opened this issue 1 year ago • 2 comments

What happened (please include outputs or screenshots): In documentation, the example given for api create_namespaced_service_account is not working due to: body = kubernetes.client.V1ServiceAccount()

Traceback (most recent call last): File "t.py", line 87, in body = kubernetes.client.AuthenticationV1TokenRequest() # AuthenticationV1TokenRequest | File "/usr/local/lib/python3.7/site-packages/kubernetes/client/models/authentication_v1_token_request.py", line 70, in init self.spec = spec File "/usr/local/lib/python3.7/site-packages/kubernetes/client/models/authentication_v1_token_request.py", line 160, in spec raise ValueError("Invalid value for spec, must not be None") # noqa: E501 ValueError: Invalid value for spec, must not be None

(Nota: code indentation id wrong, but the issue is still there even while fixing it)

What you expected to happen: The call to create_namespaced_service_account should work but the example is stuck before this call

How to reproduce it (as minimally and precisely as possible): Copy paste example given : https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#create_namespaced_service_account_token (adapt code to be connect to your cluster)

Anything else we need to know?: I made a test with api list_namespace and list_namespaced_service_account they don't require call to AuthenticationV1TokenRequest and they are working well.

I presume that spec parameter should be set but I don't know what to set without a good example.

Environment:

  • Kubernetes version (kubectl version): 1.29
  • OS (e.g., MacOS 10.13.6): Linux (amazon linux EC2)
  • Python version (python --version) 3.7
  • Python client version (pip list | grep kubernetes) 26.1.0

jhourque avatar Jun 24 '24 14:06 jhourque

I found the solution. We need to add body with audience and expiration_seconds: spec = kube.client.V1TokenRequestSpec(audiences=['https://kubernetes.default.svc'], bound_object_ref=None, expiration_seconds=<expiration in seconds>) body = kube.client.AuthenticationV1TokenRequest(spec=spec) response = api_instance.create_namespaced_service_account_token(name=name, namespace=ns, body=body)

It also would be nice to explain that name is the service account name.

jhourque avatar Jun 25 '24 08:06 jhourque

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Sep 23 '24 09:09 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle rotten
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Oct 23 '24 09:10 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Nov 22 '24 10:11 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

k8s-ci-robot avatar Nov 22 '24 10:11 k8s-ci-robot