Skip to content

Interaction with Custom Resource Objects failing #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sujeetkp opened this issue Apr 5, 2025 · 2 comments
Open

Interaction with Custom Resource Objects failing #2380

sujeetkp opened this issue Apr 5, 2025 · 2 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.

Comments

@sujeetkp
Copy link

sujeetkp commented Apr 5, 2025

What happened (please include outputs or screenshots):

I have create a CRD and a Custom Object. When I try to pull the Custom Resource Status or try to patch the Custom Resource status, the request fails with unable to find the resource.

What you expected to happen:

The request should find the Custom Requests and patch it.

How to reproduce it (as minimally and precisely as possible):

    import kubernetes
    import os

    def main():
    
        print("Loading kube config...")
        kubernetes.config.load_kube_config()
        proxy_url = os.environ.get("HTTP_PROXY", os.environ.get("http_proxy", None))
        kubernetes.client.Configuration._default.proxy = proxy_url
        api_instance = kubernetes.client.CustomObjectsApi()
        namespace = "default"
        
        # Works
        custom_api_response = api_instance.get_namespaced_custom_object(
            group="example.com",
            version="v1alpha1",
            namespace=namespace,
            plural="podrequests",
            name="test-req",
        )
    
        print("Custom resource found: %s", custom_api_response)
        
        # Fails
        custom_api_response = api_instance.get_namespaced_custom_object_status(
            group="example.com",
            version="v1alpha1",
            namespace=namespace,
            plural="podrequests",
            name="test-req",
        )
    
        patch = {"status": {"status": "complete"}}
         
        # Fails
        response = api_instance.patch_namespaced_custom_object_status(
            group="example.com",
            version="v1alpha1",
            namespace=namespace,
            plural="podrequests",
            name="test-req",
            body=patch
        )
    
        
    if __name__ == "__main__":
        main()
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: podrequests.example.com
spec:
  group: example.com
  names:
    kind: PodRequest
    plural: podrequests
    singular: podrequest
    shortNames:
      - podr
  scope: Namespaced
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                podSpec:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                  description: "Full Kubernetes pod specification for machine creation"
                count:
                  type: integer
                  description: "Number of machines to provision"
            status:
              type: object
              properties:
                status:
                  type: string
                  enum: [running, complete, complete_with_error]
                  description: "Overall request status"
                message:
                  type: string
                  description: "Additional status information"
apiVersion: example.com/v1alpha1
kind: PodRequest
metadata:
  name: "test-req"
spec:
  podSpec:
    apiVersion: v1
    kind: Pod
    metadata:
    spec:
      containers:
        - name: hello
          image: xxxxxxxxxxxx:2025-02-01-02-04
          command: ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep infinity']
  count: 1
status:
  status: running
  message: "Request is being processed"

Loading kube config...
Custom resource found: %s {'apiVersion': 'example.com/v1alpha1', 'kind': 'PodRequest', 'metadata': {'annotations': {'kubectl.kubernetes.io/last-applied-configuration': '{"apiVersion":"example.com/v1alpha1","kind":"PodRequest","metadata":{"annotations":{},"name":"test-req","namespace":"default"},"spec":{"count":1,"podSpec":{"apiVersion":"v1","kind":"Pod","metadata":null,"spec":{"containers":[{"command":["sh","-c","echo \\"Hello, Kubernetes!\\" \\u0026\\u0026 sleep infinity"],"image":"xxxxxxxxxxxx:2025-02-01-02-04","name":"hello"}]}}},"status":{"message":"Request is being processed","status":"running"}}\n'}, 'creationTimestamp': '2025-04-05T11:33:53Z', 'generation': 1, 'managedFields': [{'apiVersion': 'example.com/v1alpha1', 'fieldsType': 'FieldsV1', 'fieldsV1': {'f:metadata': {'f:annotations': {'.': {}, 'f:kubectl.kubernetes.io/last-applied-configuration': {}}}, 'f:spec': {'.': {}, 'f:count': {}, 'f:podSpec': {'.': {}, 'f:apiVersion': {}, 'f:kind': {}, 'f:spec': {'.': {}, 'f:containers': {}}}}, 'f:status': {'.': {}, 'f:message': {}, 'f:status': {}}}, 'manager': 'kubectl-client-side-apply', 'operation': 'Update', 'time': '2025-04-05T11:33:53Z'}], 'name': 'test-req', 'namespace': 'default', 'resourceVersion': '4505753', 'uid': 'fc01f9f7-a216-4378-9364-7af71423cbf7'}, 'spec': {'count': 1, 'podSpec': {'apiVersion': 'v1', 'kind': 'Pod', 'spec': {'containers': [{'command': ['sh', '-c', 'echo "Hello, Kubernetes!" && sleep infinity'], 'image': 'xxxxxxxxxxxx:2025-02-01-02-04', 'name': 'hello'}]}}}, 'status': {'message': 'Request is being processed', 'status': 'running'}}
Traceback (most recent call last):
  File "xxxxxxxxxxxxxxxxxxxxxxxxx/test_crd.py", line 36, in <module>
    main()
  File "xxxxxxxxxxxxxxxxxxxxxxxxx/test_crd.py", line 25, in main
    response = api_instance.patch_namespaced_custom_object_status(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/api/custom_objects_api.py", line 3530, in patch_namespaced_custom_object_status
    return self.patch_namespaced_custom_object_status_with_http_info(group, version, namespace, plural, name, body, **kwargs)  # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/api/custom_objects_api.py", line 3665, in patch_namespaced_custom_object_status_with_http_info
    return self.api_client.call_api(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 348, in call_api
    return self.__call_api(resource_path, method,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 180, in __call_api
    response_data = self.request(
                    ^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/api_client.py", line 407, in request
    return self.rest_client.PATCH(url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/rest.py", line 299, in PATCH
    return self.request("PATCH", url,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/venv/lib/python3.12/site-packages/kubernetes/client/rest.py", line 238, in request
    raise ApiException(http_resp=r)
kubernetes.client.exceptions.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Audit-Id': '22068da1-ed18-498b-9a72-07847f0b2318', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': 'c813a998-781a-4491-81e4-b4efd3dfb7dc', 'X-Kubernetes-Pf-Prioritylevel-Uid': '660d6ee5-e61e-4378-b46a-30a880e6213b', 'Date': 'Sat, 05 Apr 2025 11:43:10 GMT', 'Content-Length': '232'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"podrequests.example.com \"test-req\" not found","reason":"NotFound","details":{"name":"test-req","group":"example.com","kind":"podrequests"},"code":404}

Anything else we need to know?:

Environment:

  • Kubernetes version (kubectl version):
Client Version: v1.31.2
Kustomize Version: v5.4.2
Server Version: v1.31.6-eks-bc803b4
  • OS (e.g., MacOS 10.13.6):
    Red Hat Enterprise Linux release 8.10

  • Python version (python --version)
    Python 3.12.7

  • Python client version (pip list | grep kubernetes)
    kubernetes 32.0.1

@sujeetkp sujeetkp added the kind/bug Categorizes issue or PR as related to a bug. label Apr 5, 2025
@yliaog
Copy link
Contributor

yliaog commented Apr 9, 2025

/help

@k8s-ci-robot
Copy link
Contributor

@yliaog:
This request has been marked as needing help from a contributor.

Guidelines

Please ensure that the issue body includes answers to the following questions:

  • Why are we solving this issue?
  • To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points?
  • Does this issue have zero to low barrier of entry?
  • How can the assignee reach out to you for help?

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed
by commenting with the /remove-help command.

In response to this:

/help

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 k8s-ci-robot added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants