Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Oct 20, 2025

  • Understand the issue: getSerializationType incorrectly treats Knative Services as K8s Services
  • Update getSerializationType to check if API group is built-in
  • Return undefined for non-built-in groups so they're treated as KubernetesObject
  • Add test case for Knative Service YAML parsing
  • Add test case for custom resources
  • Update util_test.ts to test the new behavior
  • Run existing tests to ensure no regressions
  • Verify fix with manual testing
  • Format code with prettier
Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrectly parsing Knative Service YAML in 1.4.0</issue_title>
<issue_description>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.

</issue_description>

<agent_instructions>Update the getSerializationType function so that it considers the API group in determining the type and it returns undefined if the api group is not one of the build-in Kubernetes api groups or empty string.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@brendandburns 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.</comment_new>

Fixes #2670


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 20, 2025
@k8s-ci-robot
Copy link
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.

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

@Copilot Copilot AI requested a review from brendandburns October 20, 2025 17:35
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 20, 2025
Copy link
Contributor

@brendandburns brendandburns left a comment

Choose a reason for hiding this comment

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

Generally looks good, but I think the code could be simplified by returning KubernetesObject rather than undefined when the API group is not a built-in API.


// Only return a type name if this is a built-in Kubernetes API group
if (!isBuiltInApiGroup(gv.group)) {
return undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Return 'KubernetesObject' here.

const data = ObjectSerializer.parse(await response.body.text(), contentType);
if (type === undefined) {
type = getSerializationType(data.apiVersion, data.kind);
type = getSerializationType(data.apiVersion, data.kind) ?? 'KubernetesObject';
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than requiring the caller to do this, just modify getSerializationType to return KubernetesOjbect for the non-native case.

return undefined;
}

const version = gv.version.charAt(0).toUpperCase() + gv.version.slice(1);

Choose a reason for hiding this comment

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

Suggested change
const version = gv.version.charAt(0).toUpperCase() + gv.version.slice(1);
const version = gv.version ? gv.version.charAt(0).toUpperCase() + gv.version.slice(1) : '';

Perhaps add check so code doesn't throw when gv.version is undefined or malformed. (Keep getSerializationType protected for edge cases)

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrectly parsing Knative Service YAML in 1.4.0

4 participants