Skip to content

Commit 180cc76

Browse files
authored
feat(operator): set userAgent on Kubernetes client (kroxylicious#3624)
* Set userAgent on operator's Kubernetes client Configure KUBERNETES_USER_AGENT env var in the operator Deployment manifest using fabric8's built-in support. The value is interpolated at build time via Maven resource filtering to include the project version, e.g. "kroxylicious-operator/0.21.0". Assisted-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Sam Barker <sam@quadrocket.co.uk> * Add changelog entry for operator userAgent Assisted-by: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Sam Barker <sam@quadrocket.co.uk> --------- Signed-off-by: Sam Barker <sam@quadrocket.co.uk>
1 parent dc16b83 commit 180cc76

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Format `<github issue/pr number>: <short description>`.
77

88
## SNAPSHOT
99

10+
* [#3624](https://github.com/kroxylicious/kroxylicious/pull/3624): feat(operator): set Kubernetes client User-Agent to `kroxylicious-operator/<version>` for API server audit log identification
1011
* [#3565](https://github.com/kroxylicious/kroxylicious/pull/3514): build(deps): bump kubernetes-client.version from 7.5.2 to 7.6.1
1112
* [#3514](https://github.com/kroxylicious/kroxylicious/pull/3514): build(deps): build(deps-dev): bump org.yaml:snakeyaml from 2.5 to 2.6
1213
* [#3564](https://github.com/kroxylicious/kroxylicious/pull/3564): build(deps): bump apicurio-registry.version from 3.1.6 to 3.2.1

kroxylicious-operator/packaging/install/03.Deployment.kroxylicious-operator.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ spec:
3939
drop: ["ALL"]
4040
readOnlyRootFilesystem: true
4141
terminationMessagePolicy: FallbackToLogsOnError
42+
env:
43+
- name: KUBERNETES_USER_AGENT
44+
value: "kroxylicious-operator/$[project.version]"
4245
args: [ ]
4346
resources:
4447
requests:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright Kroxylicious Authors.
3+
*
4+
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
package io.kroxylicious.kubernetes.operator;
8+
9+
import org.junit.jupiter.api.Test;
10+
import org.junitpioneer.jupiter.SetEnvironmentVariable;
11+
12+
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
class CreateKubernetesClientTest {
17+
18+
@Test
19+
@SetEnvironmentVariable(key = "KUBERNETES_USER_AGENT", value = "kroxylicious-operator/0.12.0")
20+
void shouldUseUserAgentFromEnvironment() {
21+
try (var client = new KubernetesClientBuilder().build()) {
22+
assertThat(client.getConfiguration().getUserAgent())
23+
.isEqualTo("kroxylicious-operator/0.12.0");
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)