Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 13, 2025

Implementation Plan for KubectlGet

  • Explore repository structure and existing kubectl implementations
  • Understand the IKubernetes client API structure
  • Build the project successfully
  • Refactor to use GenericClient for a single Get method (per @brendandburns feedback)
  • Implement AsyncKubectl.Get.cs with generic async Get functionality
  • Implement Kubectl.Get.cs with generic sync wrapper
  • Update tests to use new generic Get API
  • Ensure tests pass and code builds
  • Address code review suggestions (dispose GenericClient, ternary operator, specific exceptions)
  • Rebase onto latest master (per @tg123 request)

Rebase Complete

Successfully rebased onto master commit 068251c. The branch now includes latest changes from master:

All code builds successfully with no errors, including for the new .NET 10 target framework.

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 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
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
Contributor 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
Copy link
Contributor

@brendandburns brendandburns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 17, 2025
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 17, 2025
@brendandburns brendandburns marked this pull request as ready for review November 18, 2025 18:09
Copilot AI review requested due to automatic review settings November 18, 2025 18:09
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 18, 2025
Copilot finished reviewing on behalf of brendandburns November 18, 2025 18:12
Copy link
Contributor

Copilot AI left a 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 implements kubectl get functionality for the KubernetesClient.Kubectl package, enabling retrieval of any Kubernetes resource by name using a generic client approach. The implementation follows existing patterns in the codebase (similar to Version and Cordon methods) with separate async and synchronous methods.

Key changes:

  • Generic GetAsync<T>() and Get<T>() methods that work with any Kubernetes resource type marked with KubernetesEntityAttribute
  • Automatic detection of resource metadata (group, version, plural name) from the type
  • Intelligent handling of both namespaced and cluster-scoped resources
  • Comprehensive E2E tests for Pod, Service, Deployment, and Namespace resources

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/KubernetesClient.Kubectl/Beta/AsyncKubectl.Get.cs Implements async generic GetAsync<T>() method using GenericClient to retrieve resources
src/KubernetesClient.Kubectl/Beta/Kubectl.Get.cs Provides synchronous wrapper Get<T>() method following existing patterns
tests/Kubectl.Tests/KubectlTests.Get.cs E2E tests using MinikubeFact for Pod, Service, Deployment, and Namespace resources

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 17 to 26
var genericClient = new GenericClient(client, metadata.Group, metadata.ApiVersion, metadata.PluralName, disposeClient: false);

if (@namespace != null)
{
return await genericClient.ReadNamespacedAsync<T>(@namespace, name, cancellationToken).ConfigureAwait(false);
}
else
{
return await genericClient.ReadAsync<T>(name, cancellationToken).ConfigureAwait(false);
}
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GenericClient instance is not disposed after use. While disposeClient: false prevents disposal of the underlying Kubernetes client, the GenericClient itself should be disposed to follow proper IDisposable patterns. Consider wrapping it in a using statement or calling Dispose() after the Read operation.

Copilot uses AI. Check for mistakes.
Comment on lines 74 to 77
catch
{
// Ignore cleanup errors
}
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic catch clause.

Copilot uses AI. Check for mistakes.
Comment on lines 134 to 137
catch
{
// Ignore cleanup errors
}
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic catch clause.

Copilot uses AI. Check for mistakes.
Comment on lines 210 to 212
catch
{
// Ignore cleanup errors
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generic catch clause.

Suggested change
catch
{
// Ignore cleanup errors
catch (Exception ex)
{
// Ignore cleanup errors, but log for visibility
Console.WriteLine($"Cleanup error in DeleteNamespacedDeployment: {ex}");

Copilot uses AI. Check for mistakes.
Comment on lines 19 to 26
if (@namespace != null)
{
return await genericClient.ReadNamespacedAsync<T>(@namespace, name, cancellationToken).ConfigureAwait(false);
}
else
{
return await genericClient.ReadAsync<T>(name, cancellationToken).ConfigureAwait(false);
}
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both branches of this 'if' statement return - consider using '?' to express intent better.

Suggested change
if (@namespace != null)
{
return await genericClient.ReadNamespacedAsync<T>(@namespace, name, cancellationToken).ConfigureAwait(false);
}
else
{
return await genericClient.ReadAsync<T>(name, cancellationToken).ConfigureAwait(false);
}
return @namespace != null
? await genericClient.ReadNamespacedAsync<T>(@namespace, name, cancellationToken).ConfigureAwait(false)
: await genericClient.ReadAsync<T>(name, cancellationToken).ConfigureAwait(false);

Copilot uses AI. Check for mistakes.
@tg123
Copy link
Member

tg123 commented Nov 19, 2025

@copilot could you please rebase

…ator, specific exception handling

Co-authored-by: tg123 <[email protected]>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 19, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

Copilot AI and others added 3 commits November 19, 2025 08:14
…oseconds (#1687)

* Initial plan

* Fix datetime serialization to always output 6 decimal places for fractional seconds

Co-authored-by: tg123 <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tg123 <[email protected]>
* Initial plan

* Add .NET 10 support to all projects and workflows

Co-authored-by: tg123 <[email protected]>

* Fix datetime serialization to always output 6 decimal places for microseconds (#1687)

* Initial plan

* Fix datetime serialization to always output 6 decimal places for fractional seconds

Co-authored-by: tg123 <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tg123 <[email protected]>

* Initial plan

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: tg123 <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot could you please rebase

Rebased onto latest master. The branch now includes the latest changes:

Also addressed code review suggestions:

  • Added using statement to properly dispose GenericClient
  • Simplified return logic with ternary operator
  • Changed generic catch clauses to specific HttpOperationException

All tests build successfully including for the new .NET 10 target framework.

Copilot finished work on behalf of tg123 November 19, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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

4 participants