Skip to content

Incorrectly parsing Knative Service YAML in 1.4.0 #2670

Closed

Description

@0x5457

Describe the bug
When using the loadYaml method to parse a Knative Service YAML, version 1.4.0 incorrectly handles the parsing and loses the spec content. This appears to be a regression as it works correctly in version 1.3.0.

Client Version
e.g. 1.4.0

Server Version
e.g. N/A

To Reproduce
Steps to reproduce the behavior:

const k8s = require('@kubernetes/client-node');

const x = k8s.loadYaml(`apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-world
spec:
  template:
    spec:
      containers:
        - image: ghcr.io/knative/helloworld-go:latest
          ports:
            - containerPort: 8080
          env:
            - name: TARGET
              value: "World"`);
console.log(JSON.stringify(x, null, 2));

Actual Behavior (1.4.0)

{
  "apiVersion": "serving.knative.dev/v1",
  "kind": "Service",
  "metadata": {
    "name": "hello-world"
  },
  "spec": {}
}

Expected behavior (1.3.0)
The parsed object maintains the complete structure including all spec content:

{
  "apiVersion": "serving.knative.dev/v1",
  "kind": "Service",
  "metadata": {
    "name": "hello-world"
  },
  "spec": {
    "template": {
      "spec": {
        "containers": [
          {
            "image": "ghcr.io/knative/helloworld-go:latest",
            "ports": [
              {
                "containerPort": 8080
              }
            ],
            "env": [
              {
                "name": "TARGET",
                "value": "World"
              }
            ]
          }
        ]
      }
    }
  }
}

It appears that the parser might be incorrectly treating the Knative Service as a native Kubernetes Service, causing it to lose the Knative-specific spec configuration.

Activity

  1. changed the title [-]loadYaml regression: Incorrectly parsing Knative Service YAML in v1.4.0[/-] [+]loadYaml regression: Incorrectly parsing Knative Service YAML in 1.4.0[/+] on Oct 20, 2025
  2. changed the title [-]loadYaml regression: Incorrectly parsing Knative Service YAML in 1.4.0[/-] [+]Incorrectly parsing Knative Service YAML in 1.4.0[/+] on Oct 20, 2025
  3. brendandburns commented on Oct 20, 2025

    @brendandburns
    Contributor

    Yeah, this is caused by this here:
    https://github.com/kubernetes-client/javascript/blob/main/src/util.ts#L168

    In general, parsing to non-built in objects isn't really well supported, we should augment the loadYaml function so that it considers the API group.

  4. 0x5457 commented on Oct 20, 2025

    @0x5457
    ContributorAuthor

    The issue affects not only loadYaml/loadAllYaml but also KubernetesObjectApi.read()

    Additional Test Case

    const k8s = require('@kubernetes/client-node');
    
    const kc = new k8s.KubeConfig();
    kc.loadFromDefault();
    
    const client = k8s.KubernetesObjectApi.makeApiClient(kc);
    const knative = {
      apiVersion: 'serving.knative.dev/v1',
      kind: 'Service',
      metadata: {
        name: 'hello-world',
      },
    };
    
    client.read(knative).then((obj) => {
      console.log(JSON.stringify(obj.spec)); // ==> {}
    });
  5. brendandburns commented on Oct 22, 2025

    @brendandburns
    Contributor

    Yeah, in general it is tricky to parse non-native extension objects as part of this library. The "right" thing to do is probably to enumerate all of the loaded objects using the discovery APIs and then possibly dynamically generate the right object models based on those schemas, but that's pretty complicated.

    This is an area where we could use help improving things, but for now using the raw client:
    https://github.com/kubernetes-client/javascript/blob/main/examples/raw-example.js

    May be a better way until there are structured objects for non-native objects.

  6. brendandburns commented on Nov 8, 2025

    @brendandburns
    Contributor

    Closing via #2688

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

Metadata

Metadata

Assignees

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