Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

The User-Agent header was hardcoded in ApiClient.init(), causing it to report incorrect version information (e.g., "21.0.0-SNAPSHOT" when using v22.0.0).

Changes

  • ApiClient.java: Use Configuration.VERSION constant instead of hardcoded version string
  • ApiClientTest.java: Add test verifying User-Agent matches Configuration.VERSION

This ensures the User-Agent automatically reflects the correct version from Configuration.VERSION (line 21), which gets updated during releases.

// Before
setUserAgent("Kubernetes Java Client/25.0.0-SNAPSHOT");

// After  
setUserAgent("Kubernetes Java Client/" + Configuration.VERSION);
Original prompt

This section details on the original issue you should resolve

<issue_title>Incorrect User-Agent</issue_title>
<issue_description>Describe the bug
When running this code:

public V1ConfigMap createOrReplace(V1ConfigMap configMap) throws ApiException
{
  V1ObjectMeta metadata = configMap.getMetadata();
  assert (metadata != null);
  // https://github.com/kubernetes-client/java/issues/3653#issuecomment-2307770649
  V1Patch configMapPatch = new V1Patch(JSON.serialize(configMap));
  return PatchUtils.patch(V1ConfigMap.class,
    () -> core.patchNamespacedConfigMap(metadata.getName(), metadata.getNamespace(), configMapPatch).
    fieldManager(fieldManager).
    force(true).
    buildCall(null),
    V1Patch.PATCH_FORMAT_APPLY_YAML,
    client);
}

If I step through the code with a debugger, I can see that the Request object created by PatchUtils.patch() is using the wrong User-Agent version: Request{method=PATCH, url=https://fb6cde70-6232-42cf-a2e1-211ac67c62ed.k8s.ondigitalocean.com/api/v1/namespaces/default/configmaps/install-helm-script?fieldManager=LicensedCluster&force=true, headers=[authorization:Bearer redacted, Accept:application/json, Content-Type:application/json, User-Agent:Kubernetes Java Client/21.0.0-SNAPSHOT]}

I am using v22.0.0, not 21.0.0-SNAPSHOT.

Client Version

<dependency>
  <groupId>io.kubernetes</groupId>
  <artifactId>client-java</artifactId>
  <version>22.0.0</version>
</dependency>

Kubernetes Version
1.31.1

Java Version
Java 23.0.1

To Reproduce
Run the aforementioned code

Expected behavior
The User-Agent should be equal to Kubernetes Java Client/22.0.0.

KubeConfig
N/A

Server (please complete the following information):

  • OS: Linux
  • Environment: DigitalOcean Kubernetes (DOKS)
  • Cloud: DigitalOcean</issue_description>

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

@brendandburns I think this comes from here:

https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/openapi/Configuration.java#L17

We probably need to update it before we cut a release. We'll have to figure out the best way to get that into our automation. I would have thought that mvn release:prepare would do it for us, but apparently not.

@brendandburns Happy to take a PR to add support for that.

💡 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 Dec 10, 2025
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

@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 Dec 10, 2025
Copilot AI changed the title [WIP] Fix incorrect User-Agent in patch request Fix User-Agent to use Configuration.VERSION instead of hardcoded string Dec 10, 2025
Copilot AI requested a review from brendandburns December 10, 2025 19:12
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.

Incorrect User-Agent

3 participants