-
Notifications
You must be signed in to change notification settings - Fork 306
Implement List operations for Kubectl #1693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Add List<T> and ListAsync<T> methods to Kubectl and AsyncKubectl classes that support: - Listing namespaced and cluster-scoped resources - Label selector filtering (e.g., "app=test,tier=frontend") - Field selector filtering (e.g., "metadata.name=my-pod") - Pagination with limit and continue token Also update GenericClient.ListAsync and ListNamespacedAsync to pass through the filtering parameters to the underlying CustomObjects API. Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
brendandburns
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot instead of creating a different Kubectl.List class can you incorporate this into the existing Kubectl.Get class, please move the tests to the test file for KubectlGet also (and thanks for writing tests!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR extends the Kubectl client to support listing arbitrary groups of Kubernetes resources with filtering capabilities, matching the functionality of kubectl get for list operations. The implementation adds List<T> and ListAsync<T> methods that support label selectors, field selectors, and pagination.
Key Changes:
- Added
List<T>andListAsync<T>methods to Kubectl that support namespaced and cluster-scoped resource listing with label/field selector filtering and pagination - Updated
GenericClient.csto accept filter parameters (labelSelector, fieldSelector, limit, continueToken) and pass them to the Kubernetes CustomObjects API - Comprehensive E2E tests covering namespaces, pods, services, deployments, and various filtering scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/KubernetesClient.Kubectl/Beta/AsyncKubectl.List.cs |
Implements async List method with support for filtering and pagination parameters |
src/KubernetesClient.Kubectl/Beta/Kubectl.List.cs |
Implements synchronous List method as a wrapper around AsyncKubectl |
src/KubernetesClient/GenericClient.cs |
Updates ListAsync and ListNamespacedAsync to accept and pass through filter parameters |
tests/Kubectl.Tests/KubectlTests.List.cs |
Adds comprehensive E2E tests for list functionality including label/field selectors |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// <summary> | ||
| /// List Kubernetes resources of a specific type. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of Kubernetes resource list to get (e.g., V1PodList).</typeparam> |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says "The type of Kubernetes resource list to get" but should say "list" instead of "get" since this is a List operation, not a Get operation. Change to: "The type of Kubernetes resource list to list (e.g., V1PodList)."
| /// <typeparam name="T">The type of Kubernetes resource list to get (e.g., V1PodList).</typeparam> | |
| /// <typeparam name="T">The type of Kubernetes resource list to list (e.g., V1PodList).</typeparam> |
| /// <summary> | ||
| /// List Kubernetes resources of a specific type. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of Kubernetes resource list to get (e.g., V1PodList).</typeparam> |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says "The type of Kubernetes resource list to get" but should say "list" instead of "get" since this is a List operation, not a Get operation. Change to: "The type of Kubernetes resource list to list (e.g., V1PodList)."
| /// <typeparam name="T">The type of Kubernetes resource list to get (e.g., V1PodList).</typeparam> | |
| /// <typeparam name="T">The type of Kubernetes resource list to list (e.g., V1PodList).</typeparam> |
- Merged List/ListAsync methods into Kubectl.Get.cs and AsyncKubectl.Get.cs - Moved List tests into KubectlTests.Get.cs - Deleted separate Kubectl.List.cs, AsyncKubectl.List.cs, and KubectlTests.List.cs files Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
Done in commit 78e5790. I've merged the List/ListAsync methods into the existing Kubectl.Get.cs and AsyncKubectl.Get.cs files, moved the tests into KubectlTests.Get.cs, and deleted the separate List files. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, Copilot The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@tg123 this is LGTM to me, feel free to merge if/when you think it's ready |
Summary
This PR implements List operations for the Kubectl class, extending the KubectlGet functionality (#1684) to support listing arbitrary groups of resources with filtering.
Changes
Kubectl.Get.cs/AsyncKubectl.Get.cs: AddedList<T>andListAsync<T>methods supporting:labelSelector)fieldSelector)limitandcontinueTokenGenericClient.cs: UpdatedListAsyncandListNamespacedAsyncto pass filter parameters through to the CustomObjects APIKubectlTests.Get.cs: E2E tests covering namespaces, pods, services, deployments, and selector filteringUsage
Original prompt
This section details on the original issue you should resolve
<issue_title>Implement List operations as part of KubectlGet</issue_title>
<issue_description>In #1684 we added the ability to get arbitrary resources, we should extend this capability to match the ability of
kubectlto list arbitrary groups of resources. We should include all of the potential capabilities for listing like filtering on labels or other flags.Here's the help text from
kubectlto guide this development: