Skip to content
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

Json validation error in new version #3319

Open
editcriteria opened this issue Apr 15, 2024 · 5 comments
Open

Json validation error in new version #3319

editcriteria opened this issue Apr 15, 2024 · 5 comments

Comments

@editcriteria
Copy link

Describe the bug
While trying to read the nodes of a server I got the following error:

java.lang.IllegalArgumentException: Expected the field `names` to be an array in the JSON string but got `null`

The line that throws the exception is V1ContainerImage.java:193 and in debug I noticed that in my case jsonObj.get("names") is JsonNull so the first condition of line 192 fails because it checks for null and the second fails because it is not an array.
I tried the same call in versions 19.0.0 and even 20.0.1-legacy and I can read the nodes

Client Version
20.0.1

Kubernetes Version
1.29.1

Java Version
Java 17

To Reproduce
It happens on an internal server only when reading nodes

Expected behavior
The Json response is parsed correctly

KubeConfig
//

Server (please complete the following information):

  • OS: Linux
  • Environment container
  • Cloud /
@brendandburns
Copy link
Contributor

Can you provide the body of the response that you got? You should be able to get it with ApiException.getResponseBody()

@brendandburns
Copy link
Contributor

brendandburns commented Apr 15, 2024

fwiw, I believe that this is either a bug in the openai spec or the kube api server.

If you look at the spec:

https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json

If you search for ContainerImage you'll see that it is described as an array of string. In JSON null is not the same as []

I believe it needs to be either specified as a oneof(array, null) in that schema or the API server should never return null

@editcriteria
Copy link
Author

Here is the part of the body that I think causes the error:

"images": [
    {
        "names": null,
        "sizeBytes": 974400966
    },
    ...
]

We are contacting a k0s server but the same call works with the legacy version of the client.

As a side note, the exception does not throw an ApiException, is it supposed to?

@brendandburns
Copy link
Contributor

Thanks for the additional details. I would have thought that it would throw ApiException, but I guess there's no corresponding try/catch block.

With 20.0.0 we moved to a different code generator which is why there is a difference here.

For now, using legacy is probably the right thing to do. We need a reproduction in upstream k8s, not k0s to determine if this is really a bug.

@pigstomach
Copy link

I found the same error, which I can confirm is a bug, and the error message is as follows:
java.lang.IllegalArgumentException: Expected the field namesto be an array in the JSON string but gotnull`

at io.kubernetes.client.openapi.models.V1ContainerImage.validateJsonObject(V1ContainerImage.java:193)
at io.kubernetes.client.openapi.models.V1NodeStatus.validateJsonObject(V1NodeStatus.java:547)
at io.kubernetes.client.openapi.models.V1Node.validateJsonObject(V1Node.java:284)`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants