Skip to content

Preserve x-kubernetes-preserve-unknown-fields when serializing plain YAML-loaded CRDs - #3016

Open
brendandburns with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-kubernetes-object-api-issue
Open

Preserve x-kubernetes-preserve-unknown-fields when serializing plain YAML-loaded CRDs#3016
brendandburns with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-kubernetes-object-api-issue

Conversation

Copilot AI commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

KubernetesObjectApi.create() could drop CRD extension fields when input came from a plain YAML object using Kubernetes wire keys (e.g. dashed keys). This caused x-kubernetes-preserve-unknown-fields to be omitted during serialization of known typed models.

  • Serializer key resolution

    • Updated generated model serialization to prefer typed property names when present, and otherwise fall back to Kubernetes wire-format baseName keys.
    • This preserves fields provided as raw YAML keys (including dashed extension keys) without changing behavior for typed objects.
  • Regression coverage: plain object path

    • Added a serializer test for V1CustomResourceDefinition proving that a plain object containing:
      • properties.podTemplate['x-kubernetes-preserve-unknown-fields'] = true
        remains intact after ObjectSerializer.serialize(...).
  • Regression coverage: loadYaml(...) path

    • Extended YAML loader test to include x-kubernetes-preserve-unknown-fields.
    • Confirms loadYaml<V1CustomResourceDefinition>(...) maps dashed YAML key to typed field x_kubernetes_preserve_unknown_fields as expected.
const crd = loadYaml<V1CustomResourceDefinition>(yamlText);
// mapped typed field is preserved for serialization
crd.spec.versions[0].schema!.openAPIV3Schema!.properties!['podTemplate']
  .x_kubernetes_preserve_unknown_fields === true;

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 17, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 17, 2026

Copy link
Copy Markdown

CLA Not Signed

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 17, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Copilot
Once this PR has been reviewed and has the lgtm label, please ask for approval from brendandburns. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Aug 17, 2026
Copilot AI changed the title [WIP] Fix KubernetesObjectApi not preserving unknown fields Preserve x-kubernetes-preserve-unknown-fields when serializing plain YAML-loaded CRDs Aug 17, 2026
Copilot AI requested a review from brendandburns August 17, 2026 20:47
@brendandburns
brendandburns marked this pull request as ready for review August 17, 2026 21:09
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 17, 2026
let instance: {[index: string]: any} = {};
for (let attributeType of attributeTypes) {
instance[attributeType.baseName] = ObjectSerializer.serialize(data[attributeType.name], attributeType.type, attributeType.format);
const value = Object.prototype.hasOwnProperty.call(data, attributeType.name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to go into the OpenAPI Generator, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KubernetesObjectApi drops x-kubernetes-preserve-unknown-fields when given a plain YAML object

3 participants