kubernetes-client / javascript

Javascript client
Apache License 2.0
2.01k stars 513 forks source link

CustomObjectsApi.deleteCollectionNamespacedCustomObject does not support several OpenAPI query parameters #1778

Open rotty3000 opened 2 months ago

rotty3000 commented 2 months ago

Describe the bug The OpenAPI specification generated for CRDs declares verb delete on the path /apis/{group}/{version}/namespaces/{namespace}/{plural}.

However, the CustomObjectsApi.deleteCollectionNamespacedCustomObject does not support several of those query parameters; allowWatchBookmarks, continue, fieldSelector, labelSelector, limit, resourceVersion, resourceVersionMatch, timeoutSeconds & watch

Client Version 0.20.0 (although the same is still true in HEAD of the master branch)

Server Version e.g. 1.19.1

To Reproduce Use the API!

Expected behavior The missing parameters could be classified into groups:

Supporting the filtering parameters would be the minimal fix that I would expect.

brendandburns commented 2 months ago

That code is generated from the spec here:

https://github.com/kubernetes-client/gen/blob/master/openapi/custom_objects_spec.json

If you update that spec, we can regenerate the code and those fields should be added.

rotty3000 commented 2 months ago

Did you notice that for some reason the method in question didn't receive the labelSelector parameter? https://github.com/kubernetes-client/gen/blob/2658f902d35aed7fcf1823b442eb87b44d812ac1/openapi/custom_objects_spec.json#L513

Or maybe was this added since the last time the JavaScript client was last built?

rotty3000 commented 2 months ago

:(

I guess I don't understand why client API doesn't match up with the OpenAPI provided by the API server:

]$ k version
Client Version: v1.30.2
Server Version: v1.22.13+k3s1
]$ kubectl apply -f crds/
customresourcedefinition.apiextensions.k8s.io/liferayextensionprovisions.k8s.liferay.com created
]$ k proxy --port=8080&
]$ curl -s http://localhost:8080/openapi/v2 | jq  '.paths | to_entries[] | select(.key == "/apis/k8s.liferay.com/v1alpha1/namespaces/{namespace}/liferayextensionprovisions") | .value.delete.parameters'

result (descriptions redacted for brevity):

[
  {
    "uniqueItems": true,
    "type": "boolean",
    "description": "...",
    "name": "allowWatchBookmarks",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "string",
    "description": "...",
    "name": "continue",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "string",
    "description": "...",
    "name": "fieldSelector",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "string",
    "description": "...",
    "name": "labelSelector",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "integer",
    "description": "...",
    "name": "limit",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "string",
    "description": "...",
    "name": "resourceVersion",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "string",
    "description": "...",
    "name": "resourceVersionMatch",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "integer",
    "description": "...",
    "name": "timeoutSeconds",
    "in": "query"
  },
  {
    "uniqueItems": true,
    "type": "boolean",
    "description": "...",
    "name": "watch",
    "in": "query"
  }
]
brendandburns commented 2 months ago

@rotty3000 the custom object API is not dynamically generated from the OpenAPI spec for your CRD, it is statically generated from that static openAPI spec, which is intended to be generic for all CRDs.

If you want to generate a client from your CRDs OpenAPI Spec, you need to do something like the instructions for Java here:

https://github.com/kubernetes-client/java/blob/master/docs/generate-model-from-third-party-resources.md

The steps needed haven't been streamlined or documented for Javascript, but it shouldn't be too hard to adapt those instructions for javascript.

For the label selector, yes, the current javascript code generation has been complicated by the fact that we are migrating to a new code generator, while also trying to support an older code generator. We need to cherry-pick the PR with the labelSelector into the request based generator which is running at an older commit, similar to here:

https://github.com/kubernetes-client/javascript/blob/master/.github/workflows/generate-javascript.yml#L35

We'd be happy to take a PR for that also.

rotty3000 commented 2 months ago

@rotty3000 the custom object API is not dynamically generated from the OpenAPI spec for your CRD, it is statically generated from that static openAPI spec, which is intended to be generic for all CRDs.

This isn't news to me. I'm just shocked by how out of sync it seems to be. I wish I could find some time, I'd love to help improve things.

Thanks for your feedback.

brendandburns commented 2 months ago

wrt to being out of sync, there's nothing automatic to keep it in sync, so it requires people to notice and have the cycles to write a PR. It seems these parameters aren't being used much as you are the first to notice ;)

I'll tag this issue as a good first issue, in case someone else has cycles.

ArpanSolanki29 commented 2 months ago

/assign