fix(retention): prevent failures in tag retention rule deletion flow#996
fix(retention): prevent failures in tag retention rule deletion flow#996gcharpe1604 wants to merge 5 commits into
Conversation
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #996 +/- ##
=========================================
- Coverage 10.99% 9.29% -1.71%
=========================================
Files 173 321 +148
Lines 8671 16092 +7421
=========================================
+ Hits 953 1495 +542
- Misses 7612 14462 +6850
- Partials 106 135 +29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| retentionIDStr, err := GetRetentionId(projectName, true) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| retentionResp, err := ListRetention(retentionIDStr) |
There was a problem hiding this comment.
wait, why are we removing this?
There was a problem hiding this comment.
The caller in delete.go already resolves the retention ID via GetRetentionId() before invoking DeleteRetention. The removed lines were performing the same lookup a second time. By accepting retentionID directly, we eliminate a redundant network call.
…ling Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens the harbor tag retention delete flow by propagating prompt/API failures up to Cobra’s RunE boundary and simplifying the retention deletion API helper to avoid redundant lookups.
Changes:
- Refactors the retention-rule selection UI to return
(int64, error)instead of exiting the process. - Updates the prompt helper to surface API failures (and handle empty rule lists) rather than blocking/silent behavior.
- Simplifies
api.DeleteRetentionto accept a resolved retention ID directly and updates the command to use it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| cmd/harbor/root/tag/retention/delete.go | Updates delete command to handle selection errors and pass retention ID directly to deletion helper. |
| pkg/api/retention_handler.go | Changes DeleteRetention to accept retentionID directly and adjusts rule removal logic to use an int64 index. |
| pkg/prompt/prompt.go | Refactors GetRetentionTagRule to return (int64, error) and adds handling for API errors/empty rule lists. |
| pkg/views/retention/select/view.go | Refactors retention selection view to return errors instead of calling os.Exit, and introduces abort/empty-selection handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
5b51cf4 to
96546b8
Compare
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
…command layer Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
790ec71 to
e9c1dcb
Compare
Type of Change
Description / Quick Summary
This PR safeguards the tag retention rule deletion flow against unhandled errors. By propagating errors from API calls and prompt handlers up to Cobra's
RunEboundary, the CLI now exits gracefully when rule lists are empty, when API calls fail, or when the user cancels the interactive prompt.Problem
prompt.GetRetentionTagRule()would block indefinitely on connection failures and did not return errors to its caller.api.DeleteRetention()executed redundant network lookups to resolve project names to retention IDs when the ID was already available.1.Root Cause
cmd/harbor/root/tag/retention/delete.gopkg/api/retention_handler.gopkg/prompt/prompt.gopkg/views/retention/select/view.goThe command and API wrapper layers did not check return errors from
api.ListRetention()and did not propagate the error up to the CobraRunEboundary.Solution
prompt.GetRetentionTagRulesignature to return(int, error)and check for empty rules.DeleteRetentionto use the already-available retention ID and removed a redundant lookup request.cmd/harbor/root/tag/retention/delete.go.Scope
Included
GetRetentionTagRuleand propagating them in thedeletecommand.DeleteRetentionclient helper to use direct ID.Explicitly Not Included
pkg/views/base/selection/model.goto keep this PR strictly isolated).Changes
cmd/harbor/root/tag/retention/delete.go: Added error check forprompt.GetRetentionTagRuleand updatedapi.DeleteRetentioninvocation to use the direct retention ID.pkg/api/retention_handler.go: SimplifiedDeleteRetentionsignature to acceptretentionIDdirectly and removed the redundant call toGetRetentionId.pkg/prompt/prompt.go: RefactoredGetRetentionTagRuleto return(int, error)and added checks for API errors and empty rule lists.pkg/views/retention/select/view.go: RefactoredRetentionListto return(int, error)and propagate selection errors.Testing
Unit Tests
go test ./...)Manual Verification
.\harbor_retention.exe tag retention delete --project <project_name>.Risks & Compatibility