Skip to content

Commit 0646056

Browse files
Fix User-Agent to use Configuration.VERSION instead of hardcoded value
Co-authored-by: brendandburns <[email protected]>
1 parent 197a2b8 commit 0646056

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

kubernetes/src/main/java/io/kubernetes/client/openapi/ApiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private void init() {
140140
json = new JSON();
141141

142142
// Set default User-Agent.
143-
setUserAgent("Kubernetes Java Client/25.0.0-SNAPSHOT");
143+
setUserAgent("Kubernetes Java Client/" + Configuration.VERSION);
144144

145145
authentications = new HashMap<String, Authentication>();
146146
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.openapi;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
import java.util.Collections;
18+
import okhttp3.Request;
19+
import org.junit.jupiter.api.Test;
20+
21+
class ApiClientTest {
22+
23+
@Test
24+
void testUserAgentMatchesConfigurationVersion() throws ApiException {
25+
ApiClient apiClient = new ApiClient();
26+
27+
// Build a simple request to verify User-Agent header
28+
Request request =
29+
apiClient.buildRequest(
30+
"http://localhost",
31+
"/api/v1/test",
32+
"GET",
33+
Collections.emptyList(),
34+
Collections.emptyList(),
35+
null,
36+
Collections.emptyMap(),
37+
Collections.emptyMap(),
38+
Collections.emptyMap(),
39+
new String[] {},
40+
null);
41+
42+
// Verify the User-Agent header matches the version from Configuration
43+
String expectedUserAgent = "Kubernetes Java Client/" + Configuration.VERSION;
44+
String actualUserAgent = request.header("User-Agent");
45+
46+
assertThat(actualUserAgent).isEqualTo(expectedUserAgent);
47+
}
48+
}

0 commit comments

Comments
 (0)