Repository navigation
Description
Describe the bug
Since the switch to the new code generator, every generated model rejects JSON properties that
are not in its openapiFields. Any field added by a newer Kubernetes version therefore turns a
successful read into an IllegalArgumentException, even on stable v1 APIs.
Kubernetes treats adding an optional field as a backward-compatible change
(API changes guide),
and other clients ignore unknown fields when decoding responses. For example, client-go
decodes with Go's lenient encoding/json. So with this client, any cluster upgrade that adds a
field can break reads.
Reproduction
- client-java / client-java-api
27.0.0(latest release) - EKS Auto Mode, kubelet
v1.37.0-eks-29d7970
V1Node node = new CoreV1Api(apiClient).readNode(nodeName).execute();java.lang.IllegalArgumentException: The field `runningInUserNamespace` in the JSON string is not
defined in the `V1NodeSystemInfo` properties. JSON: {"machineID":"...", ...,
"swap":{"capacity":1073737728},"runningInUserNamespace":false}
Upgrading isn't possible here: 27.0.0 is the newest release, and master doesn't have the field
either.
Where it comes from
Each model's CustomTypeAdapterFactory.read calls validateJsonElement before deserializing, and
that method throws on any key that is not in openapiFields. For example,
V1NodeSystemInfo.validateJsonElement:
for (Map.Entry<String, JsonElement> entry : entries) {
if (!V1NodeSystemInfo.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(... "is not defined in the `V1NodeSystemInfo` properties" ...);
}
}Parent models also call their children's validateJsonElement on the raw JSON
(V1NodeStatus → V1NodeSystemInfo), so one new field anywhere in the object fails the whole
read. Watches fail the same way.
The -legacy builds, made with the previous generator, ignored unknown fields; this was confirmed
in #3428.
History
This has been reported several times, each time for one specific field, and closed by
regenerating for the next Kubernetes version: #3428 (appArmorProfile), #3784, #3980
(volumeMounts), #4054, #4809. In #4809 a maintainer noted that "the new code generator isn't
tolerant of unknown fields" and said they would look for a configuration setting. I couldn't find
an issue tracking that, hence this one.
Upstream generator request for the same behaviour:
OpenAPITools/openapi-generator#19969 (open since 2024-10, no response).
Proposed fix
Have the generated models ignore unknown properties, as the legacy client did, while keeping the
required-field and type checks. For example, customise the okhttp-gson pojo.mustache
template used for generation to remove the "check to see if the JSON string contains additional
fields" loop, or put it behind an opt-in strict mode.
Workaround (for anyone hitting this)
Put a Gson TypeAdapterFactory in front of the client's shared Gson, built via
JSON.getGson().newBuilder(). For each generated model, it removes keys missing from
openapiFields, works through nested models, lists and maps using the declared field types,
and then hands off to the model's own adapter. Install it with JSON.setGson(...) before the
first API call.
Activity
brendandburns commentedon Oct 14, 2026
The workaround that you suggest seems like the best option.
In general, older client plus newer server is not guaranteed to work properly, while this mostly works in this case because it is a status field, if you tried to do this with a spec field and you did a read followed by a write with an older client library, you would lose the contents of that field, so using an older client with a newer server is really not a great option.
brendandburns commentedon Oct 29, 2026
I'm leaving this open for now to address this general problem, but for the specific issue, 28.0.0 is out which supports 1.37
therealemmanueloppong commentedon Nov 8, 2026
Hi @brendandburns, I'd like to work on the general fix for this, if that's alright. I tested what the generator can do, using openapi-generator 7.18.0 (the version
genpins) on a small spec with a parent and child model, with the same options asjava.xml.disallowAdditionalPropertiesIfNotPresent=falseremoves the check and also keeps unknown fields in a newadditionalPropertiesmap on every model. That avoids losing data on a read then write, but each model grows by about 80 lines (275 to 356 in my sample), gets new public methods (getAdditionalProperties,putAdditionalProperty), andequals,hashCodeandtoStringinclude the unknown fields.pojo.mustachetemplate, passed with-t, that only removes the unknown-field loop. The output differs from today's by exactly those 8 lines per model, with no new API. Unknown fields are ignored on read, as with the legacy client. The cost is maintaining one template file across generator upgrades.I lean towards option 2 for a small, mechanical change, but option 1 is closer to preserving unknown fields. Which would you prefer? The change would be in
kubernetes-client/gen, plus a regeneration here. I used an AI assistant (Claude Code) for the investigation and will say so in the PRs.