fix(retention): prevent failures in tag retention rule deletion flow#996
Open
gcharpe1604 wants to merge 1 commit into
Open
fix(retention): prevent failures in tag retention rule deletion flow#996gcharpe1604 wants to merge 1 commit into
gcharpe1604 wants to merge 1 commit 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.17% -1.83%
=========================================
Files 173 321 +148
Lines 8671 16085 +7414
=========================================
+ Hits 953 1475 +522
- Misses 7612 14476 +6864
- Partials 106 134 +28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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