Skip to content

fix(registry): handle missing registry lookup in delete by name#841

Open
PrasunaEnumarthy wants to merge 1 commit into
goharbor:mainfrom
PrasunaEnumarthy:fix/registry-id-resolution
Open

fix(registry): handle missing registry lookup in delete by name#841
PrasunaEnumarthy wants to merge 1 commit into
goharbor:mainfrom
PrasunaEnumarthy:fix/registry-id-resolution

Conversation

@PrasunaEnumarthy
Copy link
Copy Markdown
Contributor

Description

This PR fixes registry name lookup so it no longer fails silently when a registry is missing or falls beyond the first page of results.

It also updates harbor registry delete <name> to stop immediately when name resolution fails instead of proceeding with registry ID 0.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • query registries by exact name in GetRegistryIdByName
  • return registry '' not found when lookup fails
  • handle lookup errors in registry delete
  • add focused unit tests for lookup and delete error handling

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.56%. Comparing base (60ad0bd) to head (9a1e28a).
⚠️ Report is 162 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/registry/delete.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #841      +/-   ##
=========================================
- Coverage   10.99%   8.56%   -2.43%     
=========================================
  Files         173     288     +115     
  Lines        8671   14446    +5775     
=========================================
+ Hits          953    1237     +284     
- Misses       7612   13091    +5479     
- Partials      106     118      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread cmd/harbor/root/registry/delete.go Outdated
@qcserestipy qcserestipy self-requested a review April 29, 2026 18:55
Copy link
Copy Markdown
Collaborator

@qcserestipy qcserestipy left a comment

Choose a reason for hiding this comment

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

This PR fixes issue, but also introduces new architectural patterns not used elsewhere in this project:

  • newDeleteRegistryCommand(deps ...) constructor pattern
  • deleteRegistryDeps DI struct in command layer
  • mutable package-level function seam (listRegistriesFunc) in API layer

I think this goes beyond scope of #840 and breaks local consistency (other commands do not use this style).

Can we keep this fix minimal and follow existing patterns?

  • keep DeleteRegistryCommand() style consistent with other commands
  • handle GetRegistryIdByName error directly in current flow
  • add focused tests without introducing a new command-constructor/DI pattern

@qcserestipy qcserestipy added the Changes Requesed feedback that must be addressed before merging. label Apr 29, 2026
@PrasunaEnumarthy
Copy link
Copy Markdown
Contributor Author

This PR fixes issue, but also introduces new architectural patterns not used elsewhere in this project:

  • newDeleteRegistryCommand(deps ...) constructor pattern
  • deleteRegistryDeps DI struct in command layer
  • mutable package-level function seam (listRegistriesFunc) in API layer

I think this goes beyond scope of #840 and breaks local consistency (other commands do not use this style).

Can we keep this fix minimal and follow existing patterns?

  • keep DeleteRegistryCommand() style consistent with other commands
  • handle GetRegistryIdByName error directly in current flow
  • add focused tests without introducing a new command-constructor/DI pattern

Hi @qcserestipy , I’ve made the requested changes... removed the DI/constructor setup, cleaned up the seam, aligned the command with existing patterns, and simplified the tests.

The lint issues seem to be pre-existing (from a golangci-lint update) and aren’t related to this PR. Happy to fix them in a separate PR if you’d prefer.

Copy link
Copy Markdown
Collaborator

@qcserestipy qcserestipy left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution, please adjust the code according to the comments. Please also do not change the layout of the actual command. Do now create unneeded types and do not add uneeded constructor functions. Please stick to consistent format of cobra commands as for others.

Comment thread pkg/api/registry_handler.go
Comment thread cmd/harbor/root/registry/delete_test.go
Signed-off-by: PrasunaEnumarthy <eswari.prasuna@gmail.com>
@PrasunaEnumarthy PrasunaEnumarthy force-pushed the fix/registry-id-resolution branch from b2ee3c1 to 9a1e28a Compare May 17, 2026 07:56
@PrasunaEnumarthy
Copy link
Copy Markdown
Contributor Author

@qcserestipy , thanks for the review! Sorry for the late response. I've addressed all the feedback:

  • Removed abstractions: GetRegistryIdByName now uses ListFlags{Name: registryName} directly, matching existing lookup patterns.
  • No layout changes: DeleteRegistryCommand() follows the standard project Cobra pattern with no DI, constructors, or new types.
  • Updated tests: Simplified TestDeleteRegistryCommand to focus strictly on metadata and parameters, removing all E2E behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changes Requesed feedback that must be addressed before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: registry lookup by name can silently fail and delete may use ID 0

3 participants