Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

Watch.Response objects were not preserving the raw JSON data for DynamicKubernetesObject instances. The issue affected all event types (ADDED, MODIFIED, DELETED), despite the original report focusing on ADDED.

Root Cause

Watch.parseLine() called json.deserialize(), which uses the global static GSON instance. DynamicKubernetesApi registers DynamicKubernetesTypeAdaptorFactory on its ApiClient's GSON instance, but Watch wasn't using it.

Changes

  • Watch.java: Changed parseLine() to call json.getGson().fromJson() directly instead of json.deserialize(), ensuring it uses the ApiClient-configured GSON instance with registered TypeAdapters
  • WatchDynamicObjectTest.java: Added tests verifying raw data preservation for DynamicKubernetesObject

Example

// After fix, raw JSON is properly preserved
DynamicKubernetesApi api = new DynamicKubernetesApi(...);
Watchable<DynamicKubernetesObject> watch = api.watch(namespace);

for (Watch.Response<DynamicKubernetesObject> event : watch) {
  // event.object.getRaw() now contains full JSON including spec, status, etc.
  JsonObject raw = event.object.getRaw();
  System.out.println(raw.get("spec"));  // Works for all event types
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Watch.Response with type ADDED does not provide object's data</issue_title>
<issue_description>Describe the bug

If the response received from calling GenericKubernetesApi.watch has type "ADDED", the KubernetesObject in object has only metadata. raw is empty (null). (The object's raw data is provided for type "MODIFIED")

Client Version
v19

Java Version
Java 17

To Reproduce
Call the method, add a Kubernetes object, look at the result.

Expected behavior
The (raw) data should be provided.
</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@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 Nov 17, 2025
…n issue

Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@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

1 similar comment
@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

@k8s-ci-robot k8s-ci-robot 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 Nov 17, 2025
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Watch.Response for ADDED type to return object's data Fix Watch.Response deserialization to preserve DynamicKubernetesObject raw data Nov 17, 2025
Copilot AI requested a review from brendandburns November 17, 2025 23:08
Copilot finished work on behalf of brendandburns November 17, 2025 23:08
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/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.

Watch.Response with type ADDED does not provide object's data

3 participants