Skip to content

Conversation

Copy link

Copilot AI commented Nov 13, 2025

Adds kubectl get functionality to retrieve any Kubernetes resource by name, similar to the kubectl CLI tool. Uses a single generic method with GenericClient instead of separate methods for each resource type.

Implementation

  • AsyncKubectl.Get.cs: Generic async GetAsync<T>() method using GenericClient
  • Kubectl.Get.cs: Synchronous generic Get<T>() wrapper following existing patterns (Version, Cordon)
  • KubectlTests.Get.cs: E2E tests using MinikubeFact for Pod, Service, Deployment, and Namespace

The implementation extracts resource metadata (group, version, plural name) from the type's KubernetesEntityAttribute and automatically handles both namespaced and cluster-scoped resources.

Usage

using k8s.kubectl.beta;

var kubectl = new Kubectl(kubernetesClient);

// Get namespaced resources
var pod = kubectl.Get<V1Pod>("my-pod", "default");
var deployment = kubectl.Get<V1Deployment>("my-deployment", "prod");
var service = kubectl.Get<V1Service>("my-svc", "default");

// Get cluster-scoped resources (no namespace parameter)
var namespace = kubectl.Get<V1Namespace>("kube-system");
var node = kubectl.Get<V1Node>("node-1");

// Async with cancellation
var configMap = await kubectl.GetAsync<V1ConfigMap>("my-config", "default", cancellationToken);

The generic method works with any Kubernetes resource type that has a KubernetesEntityAttribute, making it extensible to all supported resources without requiring additional code.

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<filter_complete></filter_complete>

<issue_title>Implement Kubectl Get</issue_title>
<issue_description>Similar to the kubectl executable we need to implement KubectlGet functionality which will get any known resource.

This should be located in the src/KubernetesClient.Kubectl package.</issue_description>

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

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement Kubectl Get</issue_title>
<issue_description>Similar to the kubectl executable we need to implement KubectlGet functionality which will get any known resource.

This should be located in the src/KubernetesClient.Kubectl package.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@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 Nov 13, 2025
@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/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 13, 2025
@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

Copilot AI changed the title [WIP] Implement KubectlGet functionality for resource retrieval Implement Kubectl Get for common Kubernetes resources Nov 13, 2025
Copilot finished work on behalf of brendandburns November 13, 2025 01:08
Copilot AI requested a review from brendandburns November 13, 2025 01:08
@brendandburns
Copy link
Contributor

@copilot can you refactor this to use the generic client

var generic = new GenericClient(client, "", "v1", "nodes");
instead so that it can work for any supported resource type with a single function instead of having different GetFoo functions for each time

Copy link
Author

Copilot AI commented Nov 13, 2025

@copilot can you refactor this to use the generic client

var generic = new GenericClient(client, "", "v1", "nodes");
instead so that it can...

Refactored to use GenericClient with a single generic Get<T>() method. The implementation extracts resource metadata from the type's KubernetesEntityAttribute and automatically handles both namespaced and cluster-scoped resources.

Usage:

var pod = kubectl.Get<V1Pod>("my-pod", "default");
var namespace = kubectl.Get<V1Namespace>("kube-system");
var deployment = kubectl.Get<V1Deployment>("my-deploy", "prod");

Commit: 2147fb4

Copilot AI changed the title Implement Kubectl Get for common Kubernetes resources Implement Kubectl Get using generic client for any Kubernetes resource Nov 13, 2025
Copilot finished work on behalf of brendandburns November 13, 2025 19:13
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Kubectl Get

3 participants