You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to create a CRD with x-kubernetes-int-or-string, its being dropped causing the server to respond with The CustomResourceDefinition "middlewares.traefik.io" is invalid: spec.validation.openAPIV3Schema.properties[spec].properties[circuitBreaker].properties[checkPeriod].type: Required value: must not be empty for specified object fields.
This is what is actually being passed to the server. How do I know? I print it out before sending the request in the underlying node_module, node_modules/@kubernetes/client-node/dist/object.js
Client Version 1.0.0 to 1.3.0
Server Version 1.30.0 to 1.33.0
To Reproduce
Steps to reproduce the behavior:
First option
Use example code
Second option
kubectl apply -f [USE HERE BROKEN CRD YAML]
^^ These are the errors you get while using the first option
Expected behavior
The create call should not strip out x-kubernetes-int-or-string. In essence, it should replicate the behaviour of kubectl apply -f [USE HERE ORIGINAL CRD YAML] which successfully creates the resource
Have you tried outputting the spec in your sample code? You are using the yaml library which is not part of this library. My guess is that it is handling the x-... field name in some other way than the code expects. The code expects underscores instead of dashes, since dash syntax isn't legal in Javascript/Typescript.
x-kubernetes-int-or-string: true at path: .spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.circuitBreaker.properties.checkPeriod.x-kubernetes-int-or-string
Given these details, it seems like the behaviour should be predictable across the board? Either the serialization keeps all of the instances of x-kubernetes-int-or-string found or not.
Have you tried outputting the spec in your sample code? You are using the yaml library which is not part of this library. My guess is that it is handling the x-... field name in some other way than the code expects. The code expects underscores instead of dashes, since dash syntax isn't legal in Javascript/Typescript.
Also, 1.0.0 forked off of the 0.x branch and stayed forked for a while under development, so it is also possible that previous fixes/updates in the 0.x branch weren't properly picked up for the 1.0 series.
For x-kubernetes-int-or-string attribute (and similar x* attributes), name is x_kubernetes_int_or_string and baseName is x-kubernetes-int-or-string, and data contains the field x-kubernetes-int-or-string, not the other one.
There are a few other attributes in V1JSONSchemaProps with name different from baseName, and I'm not sure which one we should get in this case:
for the moment, there is no way from the library to "deserialize" a YAML manifest into a correct object with correct fields.
The ObjectSerializer.deserialize (from serializer.ts) seems to be the one method to use to get a correct object to pass to the client.create() method, with he help of KubernetesObjectApi.getSerializationType (from object.ts) to get the type of the object to deserialize.
to sum up, we would need to add such a function to the library:
function parseYamlManifest(manifest: string): KubernetesObject {
const yml = yaml.load(manifest) as KubernetesObject;
const type = getSerializationType(yml.apiVersion, yml.kind);
return ObjectSerializer.deserialize(yml, type) as KubernetesObject;
}
@feloy that looks fine to me, I'm open to replacing yaml.load(...) with that method if that seems better, assuming it is backward compatible (which I think it would be)
Activity
brendandburns commentedon Jun 9, 2025
So the field is definitely there:
https://github.com/kubernetes-client/javascript/blob/main/src/gen/models/V1JSONSchemaProps.ts#L83
Have you tried outputting the
specin your sample code? You are using theyamllibrary which is not part of this library. My guess is that it is handling thex-...field name in some other way than the code expects. The code expects underscores instead of dashes, since dash syntax isn't legal in Javascript/Typescript.sebastianserrano commentedon Jun 10, 2025
Thanks for you reply @brendandburns. Here is what I've gathered:
Have you tried outputting the spec in your sample code? You are using the yaml library which is not part of this library.yamlproduces, I can still see thex-kubernetes-int-or-string: truex-kubernetes-int-or-string: truestripped out.good.yaml
middlewares.traefik.io(broken)x-kubernetes-int-or-string: trueat path:.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.circuitBreaker.properties.checkPeriod.x-kubernetes-int-or-stringingressrouteudps.traefik.iox-kubernetes-int-or-string: trueat path:.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.routes.items.properties.services.items.properties.port.x-kubernetes-int-or-stringGiven these details, it seems like the behaviour should be predictable across the board? Either the serialization keeps all of the instances of
x-kubernetes-int-or-stringfound or not.Thoughts?
sebastianserrano commentedon Jun 10, 2025
Also, using
has the same effect as using the yaml package. It simply keeps
x-kubernetes-int-or-stringas issebastianserrano commentedon Jun 11, 2025
I can see the reason why this wasn't popping up before is because everything was getting serialized as a
KubernetesObject.Starting in
1.0.0that seemed to changebrendandburns commentedon Jun 19, 2025
1.0.0 introduced a new code generator, so changes/bugs are expected. We'd be happy to look at PRs to fix/improve things.
brendandburns commentedon Jun 19, 2025
Also, 1.0.0 forked off of the 0.x branch and stayed forked for a while under development, so it is also possible that previous fixes/updates in the 0.x branch weren't properly picked up for the 1.0 series.
gastoner commentedon Jun 19, 2025
From my observations, the issue has started appearing from 1.1.2 -> 1.2.0 in #2400
feloy commentedon Jun 20, 2025
In the serializer, there is a confusion between the
attributeType.nameandattributeType.baseName:https://github.com/kubernetes-client/javascript/blob/1.3.0/src/gen/models/ObjectSerializer.ts#L2256
For
x-kubernetes-int-or-stringattribute (and similar x* attributes),nameisx_kubernetes_int_or_stringand baseName isx-kubernetes-int-or-string, and data contains the fieldx-kubernetes-int-or-string, not the other one.There are a few other attributes in
V1JSONSchemaPropswith name different from baseName, and I'm not sure which one we should get in this case:feloy commentedon Jun 23, 2025
@schrodit I can see you have worked on serializers recently, do you have an idea on where this confusion between baseName and name may come from?
feloy commentedon Jun 23, 2025
After some research, I think I understand more clearly the situation:
x-kubernetes-*for example, because the serializer now expectsx_kubernetes_*, see https://github.com/kubernetes-client/javascript/blob/main/src/gen/ApiextensionsV1Api.mdThe
ObjectSerializer.deserialize(from serializer.ts) seems to be the one method to use to get a correct object to pass to theclient.create()method, with he help ofKubernetesObjectApi.getSerializationType(from object.ts) to get the type of the object to deserialize.to sum up, we would need to add such a function to the library:
@brendandburns WDYT?
brendandburns commentedon Jun 24, 2025
@feloy that looks fine to me, I'm open to replacing
yaml.load(...)with that method if that seems better, assuming it is backward compatible (which I think it would be)feloy commentedon Jun 24, 2025
Great, I'll work on this