WIP ✨ Added Delete API and implemented a unified interface across all commands and plugin options#5352
Conversation
|
[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 DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
7b91689 to
0299493
Compare
f2fca86 to
ef8842f
Compare
ef8842f to
e5dc71c
Compare
fe43e33 to
e69d8d6
Compare
a703406 to
70004af
Compare
70004af to
dd9ae3c
Compare
dd9ae3c to
7d19d37
Compare
e5b1ce5 to
65d1a67
Compare
65d1a67 to
eede112
Compare
2af42ec to
2850530
Compare
2850530 to
f121750
Compare
| // 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 |
There was a problem hiding this comment.
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.
| // 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. |
| // Use configured output dir or default | ||
| outputDir := p.outputDir | ||
| if outputDir == "" { | ||
| outputDir = cfg.OutputDir | ||
| } | ||
| if outputDir == "" { | ||
| outputDir = DefaultOutputDir | ||
| } |
There was a problem hiding this comment.
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.
| // Extract the command name from positional args (after flags are parsed). | ||
| isDeleteCommand := c.isDeleteCommand(fs.Args()) |
There was a problem hiding this comment.
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).
| // 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:]) | |
| } |
Add delete functionality to remove APIs and webhooks from projects. Users can now clean up scaffolded resources. Generated-by: Cursor/Claude
f121750 to
3b8de56
Compare
|
@camilamacedo86: The following test failed, say
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. DetailsInstructions 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. |
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:
Key Features
Automatic Code Removal
Delete commands automatically remove marker-inserted code from
cmd/main.goand test files:AddToSchemecallsGraceful Error Handling
If automatic removal fails:
Closes
#907