Skip to content

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

Description

@0x5457

Describe the bug
KubernetesObjectApi.create() silently drops the CRD schema extension x-kubernetes-preserve-unknown-fields when given a plain JavaScript object parsed from YAML.

Client Version
1.4.0

Server Version
1.34

To Reproduce

const yaml = require("js-yaml");
const k8s = require("@kubernetes/client-node");

async function main() {
  const crd = yaml.load(`
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: foos.example.com
spec:
  group: example.com
  scope: Namespaced
  names:
    plural: foos
    singular: foo
    kind: Foo
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                podTemplate:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
`);
  const kc = new k8s.KubeConfig();
  kc.loadFromDefault();
  kc.setCurrentContext("orbstack");
  const client = k8s.KubernetesObjectApi.makeApiClient(kc);

  const result  = await client.create(crd);
  console.log(result.body)
}

main().then(() => console.log("done"));

the API server response does not contain x-kubernetes-preserve-unknown-fields.

Expected behavior
The API server response should retain x-kubernetes-preserve-unknown-fields: true, since it is present in the YAML input.

Example Code
Code snippet for what you are doing

Environment (please complete the following information):

  • OS: [macOS]
  • Node.js version [26.5.0]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions