Skip to content

Implement KubectlDelete to delete Kubernetes resources#1696

Merged
k8s-ci-robot merged 7 commits intomasterfrom
copilot/implement-kubectl-delete
Dec 10, 2025
Merged

Implement KubectlDelete to delete Kubernetes resources#1696
k8s-ci-robot merged 7 commits intomasterfrom
copilot/implement-kubectl-delete

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Adds kubectl delete equivalent functionality to the Kubectl package, enabling deletion of Kubernetes resources by name.

Implementation

  • AsyncKubectl.Delete.cs: DeleteAsync<T> method supporting both namespaced and cluster-scoped resources via GenericClient
  • Kubectl.Delete.cs: Synchronous Delete<T> wrapper following existing patterns
  • KubectlTests.Delete.cs: Test coverage for Pod, Service, Deployment (namespaced) and Namespace (cluster-scoped)

Usage

var kubectl = new Kubectl(client);

// Namespaced resource
var deletedPod = kubectl.Delete<V1Pod>("my-pod", "default");

// Cluster-scoped resource
var deletedNs = kubectl.Delete<V1Namespace>("my-namespace");

// Async with cancellation
var deleted = await asyncKubectl.DeleteAsync<V1Service>("my-service", "default", cancellationToken);

The implementation automatically determines resource scope from type metadata and delegates to GenericClient's existing delete operations.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • crl.comodoca.com
    • Triggering command: /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/csharp/csharp/src/KubernetesClient.Classic/KubernetesClient.Classic.csproj --packages /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot bash --no�� ct tificateValidationTests.cs grep (dns block)
  • kubernetes.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • ocsp.comodoca.com
    • Triggering command: /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/.dotnet/dotnet restore --no-dependencies /home/REDACTED/work/csharp/csharp/src/KubernetesClient.Classic/KubernetesClient.Classic.csproj --packages /home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/home/REDACTED/work/csharp/.codeql-scratch/dbs/csharp/working/emptyFakeDotnetRoot bash --no�� ct tificateValidationTests.cs grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement KubectlDelete to delete resources</issue_title>
<issue_description>The Kubectl package does not currently support the equivalent of kubectl delete ...

</issue_description>

<agent_instructions>The full details of kubectl delete can be found here: https://kubernetes.io/docs/reference/kubectl/generated/kubectl_delete/ please implement them in csharp.</agent_instructions>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@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 Dec 10, 2025
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@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 Dec 10, 2025
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
@brendandburns brendandburns marked this pull request as ready for review December 10, 2025 19:46
Copilot AI review requested due to automatic review settings December 10, 2025 19:46
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 lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Dec 10, 2025
Copilot AI changed the title [WIP] Add support for KubectlDelete to remove resources Implement KubectlDelete to delete Kubernetes resources Dec 10, 2025
@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 Dec 10, 2025
Copilot AI requested a review from brendandburns December 10, 2025 19:49
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 adds support for deleting Kubernetes resources through the Kubectl package, implementing the equivalent of kubectl delete command. The implementation follows the established patterns in the codebase, using the existing GenericClient infrastructure and providing both async and synchronous APIs.

Key Changes:

  • Added DeleteAsync<T> method in AsyncKubectl for asynchronous delete operations with proper ConfigureAwait(false) pattern
  • Added synchronous Delete<T> wrapper method in Kubectl following existing patterns
  • Added comprehensive unit tests covering both namespaced (Pod, Service, Deployment) and cluster-scoped (Namespace) resources

Reviewed changes

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

File Description
src/KubernetesClient.Kubectl/Beta/AsyncKubectl.Delete.cs Implements async DeleteAsync method using GenericClient, supporting both namespaced and cluster-scoped resources
src/KubernetesClient.Kubectl/Beta/Kubectl.Delete.cs Provides synchronous Delete wrapper using GetAwaiter().GetResult() pattern
tests/Kubectl.Tests/KubectlTests.Delete.cs Adds four test cases covering Pod, Service, Deployment, and Namespace deletion with verification

The implementation is well-structured and consistent with existing code. However, the tests could be improved by adding try-finally blocks for proper resource cleanup in case of test failures, which is the established pattern in other tests in this codebase (e.g., KubectlTests.Get.cs).


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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 10, 2025
brendandburns and others added 3 commits December 10, 2025 11:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@brendandburns
Copy link
Contributor

/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 Dec 10, 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

Details 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

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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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 KubectlDelete to delete resources

4 participants