From e64ade8198d9893e22f869d6513e5fb21ef141ed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 01:38:46 +0000 Subject: [PATCH 1/2] Initial plan From d1af24d881ece774d3cb3578c412d93137e0050f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 3 Dec 2025 01:46:37 +0000 Subject: [PATCH 2/2] Add allNamespaces() method to KubectlGet to match kubectl --all-namespaces/-A flag Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com> --- .../client/extended/kubectl/KubectlGet.java | 11 +++- .../extended/kubectl/KubectlGetTest.java | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlGet.java b/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlGet.java index 19479f6a8d..263baf0a8a 100644 --- a/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlGet.java +++ b/extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlGet.java @@ -29,10 +29,12 @@ public class KubectlGet private ListOptions listOptions; private Class apiTypeClass; private Class apiTypeListClass; + private boolean allNamespaces; KubectlGet(Class apiTypeClass) { this.apiTypeClass = apiTypeClass; this.listOptions = new ListOptions(); + this.allNamespaces = false; } public KubectlGet apiListTypeClass( @@ -51,6 +53,11 @@ public KubectlGet namespace(String namespace) { return this; } + public KubectlGet allNamespaces() { + this.allNamespaces = true; + return this; + } + public KubectlGetSingle name(String name) { return new KubectlGetSingle(name); } @@ -64,7 +71,9 @@ public List execute() throws KubectlException { ? getGenericApi(apiTypeClass) : getGenericApi(apiTypeClass, apiTypeListClass); try { - if (isNamespaced()) { + if (allNamespaces) { + return (List) api.list(listOptions).throwsApiException().getObject().getItems(); + } else if (isNamespaced()) { return (List) api.list(namespace, listOptions).throwsApiException().getObject().getItems(); diff --git a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlGetTest.java b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlGetTest.java index d3aad023d7..84c2ff799c 100644 --- a/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlGetTest.java +++ b/extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlGetTest.java @@ -96,6 +96,56 @@ void getDefaultNamespacePods() throws KubectlException { assertThat(pods).hasSize(2); } + @Test + void getAllNamespacePodsWithAllNamespacesFlag() throws KubectlException { + V1PodList podList = + new V1PodList() + .items( + Arrays.asList( + new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1")), + new V1Pod().metadata(new V1ObjectMeta().namespace("kube-system").name("foo2")))); + apiServer.stubFor( + get(urlPathEqualTo("/api/v1/pods")) + .willReturn( + aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(podList)))); + + List pods = + Kubectl.get(V1Pod.class) + .apiClient(apiClient) + .skipDiscovery() + .allNamespaces() + .execute(); + + apiServer.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods"))); + assertThat(pods).hasSize(2); + } + + @Test + void getAllNamespacesFlagOverridesNamespace() throws KubectlException { + V1PodList podList = + new V1PodList() + .items( + Arrays.asList( + new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1")), + new V1Pod().metadata(new V1ObjectMeta().namespace("kube-system").name("foo2")))); + apiServer.stubFor( + get(urlPathEqualTo("/api/v1/pods")) + .willReturn( + aResponse().withStatus(200).withBody(apiClient.getJSON().serialize(podList)))); + + // When allNamespaces() is called, it should ignore the namespace setting + List pods = + Kubectl.get(V1Pod.class) + .apiClient(apiClient) + .skipDiscovery() + .namespace("default") + .allNamespaces() + .execute(); + + apiServer.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods"))); + assertThat(pods).hasSize(2); + } + @Test void getDefaultNamespaceOnePod() throws KubectlException { V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().namespace("default").name("foo1"));