Skip to content

WIP ✨ Added Delete API and implemented a unified interface across all commands and plugin options#5352

Open
camilamacedo86 wants to merge 1 commit intokubernetes-sigs:masterfrom
camilamacedo86:add-delete-api
Open

WIP ✨ Added Delete API and implemented a unified interface across all commands and plugin options#5352
camilamacedo86 wants to merge 1 commit intokubernetes-sigs:masterfrom
camilamacedo86:add-delete-api

Conversation

@camilamacedo86
Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 commented Jan 4, 2026

Add comprehensive delete functionality to remove APIs and webhooks from projects. Users can now clean up scaffolded resources with automatic code removal, proper validation, and complete state restoration.

What's New

Users can now delete scaffolded APIs and webhooks from their projects:

# Delete APIs
kubebuilder delete api --group crew --version v1 --kind Captain

# Delete webhooks (all types or specific types)
kubebuilder delete webhook --group crew --version v1 --kind Captain
kubebuilder delete webhook --group crew --version v1 --kind Captain --defaulting

# Delete optional plugin features
kubebuilder delete --plugins=helm/v2-alpha
kubebuilder delete --plugins=grafana/v1-alpha
kubebuilder delete --plugins=autoupdate/v1-alpha

Key Features

Automatic Code Removal

Delete commands automatically remove marker-inserted code from cmd/main.go and test files:

  • Removes API/webhook imports
  • Removes AddToScheme calls
  • Removes controller/webhook setup blocks
  • Updates PROJECT file

Graceful Error Handling

If automatic removal fails:

  • Shows clear warnings (doesn't fail the operation)
  • Provides manual cleanup instructions
  • References code fragment constants for easy lookup

Closes

#907

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 4, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 4, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-delete-api branch 20 times, most recently from f2fca86 to ef8842f Compare January 25, 2026 10:52
@camilamacedo86 camilamacedo86 changed the title WIP ✨ Add delete api and delete webhook commands ✨ Add delete api and delete webhook commands Jan 25, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-delete-api branch 2 times, most recently from fe43e33 to e69d8d6 Compare February 5, 2026 11:21
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 5, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-delete-api branch 2 times, most recently from a703406 to 70004af Compare February 5, 2026 11:25
Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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

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

@camilamacedo86 camilamacedo86 changed the title ✨ Added Delete API and implemented a unified interface across all commands and plugin options WIP ✨ Added Delete API and implemented a unified interface across all commands and plugin options Feb 5, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-delete-api branch 2 times, most recently from e5b1ce5 to 65d1a67 Compare February 7, 2026 07:50
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 9, 2026
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2026
@camilamacedo86 camilamacedo86 force-pushed the add-delete-api branch 2 times, most recently from 2af42ec to 2850530 Compare April 5, 2026 12:56
@camilamacedo86 camilamacedo86 requested a review from Copilot April 5, 2026 12:59
Copy link
Copy Markdown

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

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

Comment on lines +240 to +246
// Comment out patches section header (best effort)
if err := util.CommentCode(kustomizeFilePath, "patches:", "#"); err != nil {
log.Warn("Unable to comment out 'patches:' section",
"file", kustomizeFilePath, "error", err)
}

// Comment out manager webhook patch
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

Commenting out the patches: header can leave existing patch list items (e.g., the default - path: manager_metrics_patch.yaml) at the top level, which makes config/default/kustomization.yaml invalid YAML. Instead of commenting out the section header, remove/comment only the webhook-specific patch entries (e.g., manager_webhook_patch.yaml) and keep the patches: key intact when other patches remain.

Suggested change
// Comment out patches section header (best effort)
if err := util.CommentCode(kustomizeFilePath, "patches:", "#"); err != nil {
log.Warn("Unable to comment out 'patches:' section",
"file", kustomizeFilePath, "error", err)
}
// Comment out manager webhook patch
// Keep the patches: section header intact so any non-webhook patches remain valid YAML.
// Comment out only the webhook-specific patch entry.

Copilot uses AI. Check for mistakes.
Comment on lines +443 to +450
// Use configured output dir or default
outputDir := p.outputDir
if outputDir == "" {
outputDir = cfg.OutputDir
}
if outputDir == "" {
outputDir = DefaultOutputDir
}
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

In delete mode, outputDir := p.outputDir will almost always be the flag default ("dist"), so the deletion path won't honor a previously configured non-default output dir stored in the plugin config (e.g. chart generated under --output-dir=charts). This can leave the real chart directory behind when users run kubebuilder delete --plugins=helm/v2-alpha. Consider deriving the delete target from the decoded plugin config first (with fallback to the flag only when explicitly set), so deletion removes the same output dir that was created.

Copilot uses AI. Check for mistakes.
Comment on lines +414 to +415
// Extract the command name from positional args (after flags are parsed).
isDeleteCommand := c.isDeleteCommand(fs.Args())
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

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

getInfoFromFlags now has delete-specific behavior (detecting delete via positional args and appending user --plugins to the PROJECT layout plugin chain). There are unit tests for getInfoFromFlags, but none appear to cover this delete-path merge/dedup logic; adding coverage would help prevent regressions (e.g., ensuring kubebuilder delete api --plugins=deploy-image/v1-alpha retains layout plugins while adding deploy-image).

Suggested change
// Extract the command name from positional args (after flags are parsed).
isDeleteCommand := c.isDeleteCommand(fs.Args())
// Prefer parsed positional args, but fall back to the original process args
// because subcommand names like "delete" may not be present in fs.Args()
// after Cobra/pflag parsing.
isDeleteCommand := c.isDeleteCommand(fs.Args())
if !isDeleteCommand && len(os.Args) > 1 {
isDeleteCommand = c.isDeleteCommand(os.Args[1:])
}

Copilot uses AI. Check for mistakes.
Add delete functionality to remove APIs and webhooks from projects.
Users can now clean up scaffolded resources.

Generated-by: Cursor/Claude
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@camilamacedo86: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-test 3b8de56 link true /test pull-kubebuilder-test

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants