python icon indicating copy to clipboard operation
python copied to clipboard

list_namespaced_cron_job throws an error

Open poustchi opened this issue 1 year ago • 5 comments

Guys, Can someone please let me know why this code is not working and throws an error?

    contexts, active_context = config.list_kube_config_contexts()
    if not contexts:
        sys.exit(1)
    contexts = [context['name'] for context in contexts]
    active_index = contexts.index(active_context['name'])
    config.load_kube_config("~/.kube/config")

    v1 = client.CoreV1Api()
    BatchV1Api = client.BatchV1Api()

    ret = BatchV1Api.list_namespaced_cron_job(namespace="prod", pretty=True, watch=False)

Here is the error

Traceback (most recent call last):
  File "main.py", line 75, in <module>
    ret = BatchV1Api.list_namespaced_cron_job(namespace="prod", pretty=True, watch=False)
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/api/batch_v1_api.py", line 1437, in list_namespaced_cron_job
    return self.list_namespaced_cron_job_with_http_info(namespace, **kwargs)  # noqa: E501
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/api/batch_v1_api.py", line 1552, in list_namespaced_cron_job_with_http_info
    return self.api_client.call_api(
  File "/versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
    response_data = self.request(
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/api_client.py", line 373, in request
    return self.rest_client.GET(url,
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/rest.py", line 241, in GET
    return self.request("GET", url,
  File "versions/3.8.13/lib/python3.8/site-packages/kubernetes/client/rest.py", line 235, in request
    raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Audit-Id': '42fb29fa-4253-4689-989e-cd3ba4075939', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'Date': 'Wed, 07 Jun 2023 03:00:56 GMT', 'Content-Length': '222'})
HTTP response body: {
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "the server could not find the requested resource",
  "reason": "NotFound",
  "details": {
    
  },
  "code": 404
}

kubectl version   
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:23:52Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.10", GitCommit:"98d5dc5d36d34a7ee13368a7893dcb400ec4e566", GitTreeState:"clean", BuildDate:"2021-04-15T03:20:25Z", GoVersion:"go1.15.10", Compiler:"gc", Platform:"linux/amd64"}

Python: 3.8.13
OS: Mac13.4 
pip list | grep kubernetes 
kubernetes           26.1.0

poustchi avatar Jun 07 '23 03:06 poustchi

I had a couple of projects using a similar script that worked without issue and recently started return 404 errors as well.

mattgauntseo-sentry avatar Jul 21 '23 21:07 mattgauntseo-sentry

Could you verify if you can list the cronjobs with kubectl? Also could you try turning on the debug logging to see what request the client was sending?

roycaihw avatar Jul 31 '23 16:07 roycaihw

I ended up fixing this by updating the kubernetes library - seemed that the server was updated by GCP causing the change in behavior.

mattgauntseo-sentry avatar Jul 31 '23 18:07 mattgauntseo-sentry

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 Jan 25 '24 12:01 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 Feb 24 '24 13:02 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 Mar 25 '24 14:03 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/test-infra repository.

k8s-ci-robot avatar Mar 25 '24 14:03 k8s-ci-robot