Skip to content

feat: implement Garbage Collection (gc) command group#1018

Open
gcharpe1604 wants to merge 5 commits into
goharbor:mainfrom
gcharpe1604:feature/gc-commands
Open

feat: implement Garbage Collection (gc) command group#1018
gcharpe1604 wants to merge 5 commits into
goharbor:mainfrom
gcharpe1604:feature/gc-commands

Conversation

@gcharpe1604

@gcharpe1604 gcharpe1604 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a dedicated gc command group to harbor-cli, enabling administrators to manage Harbor Garbage Collection directly from the CLI.

Garbage Collection is currently listed as an unsupported feature in the project README. While Harbor already exposes GC functionality through its API and Go SDK, harbor-cli does not currently provide a CLI interface for these operations. As a result, administrators must rely on the Harbor WebUI for common storage maintenance tasks.

This implementation closes that gap by introducing a dedicated command group for registry-wide Garbage Collection, covering the complete GC workflow from the command line.

Fixes #1017

Type of Change

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

Changes

Commands added

harbor gc history
harbor gc schedule
harbor gc trigger
harbor gc log <gc-id>
harbor gc stop <gc-id>
harbor gc update-schedule

Implementation

  • Added a new gc command group with dedicated Cobra subcommands.
  • Added API handlers for Harbor Garbage Collection operations using the existing Harbor Go SDK.
  • Added Bubble Tea views for GC history and schedule output.
  • Added interactive schedule configuration using huh.
  • Added support for the existing output formats (table, json, yaml, and csv) where applicable.
  • Added command validation tests.
  • Updated the README feature matrix to mark Garbage Collection as supported.

Testing

Verified with:

go build -o harbor_main.exe cmd/harbor/main.go

go test ./cmd/harbor/root/gc/...

go test ./...

Additionally verified:

  • harbor gc --help
  • Command registration
  • Argument validation
  • Cron validation
  • Output rendering

Notes

This implementation follows the existing command organization used throughout the project by introducing a dedicated resource-specific gc command group, consistent with other system-level commands such as scan-all.

Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
Copilot AI review requested due to automatic review settings June 22, 2026 20:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new harbor gc command group to manage Harbor registry-wide Garbage Collection from the CLI (history, logs, schedule view/update, trigger, stop), and updates the README feature matrix accordingly.

Changes:

  • Added gc Cobra command group with subcommands: history, log, schedule, stop, trigger, update-schedule.
  • Added GC API handler layer (pkg/api/gc_handler.go) wiring to Harbor go-client GC endpoints.
  • Added Bubbletea/huh-based views for listing history, viewing schedule, and interactively editing schedule options.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
README.md Marks GC as implemented in the feature list.
pkg/api/gc_handler.go Adds GC API wrapper functions (history/status/log/stop/schedule/update/trigger).
pkg/views/gc/list/view.go Bubbletea table view for GC execution history.
pkg/views/gc/view/view.go Bubbletea table view for current GC schedule.
pkg/views/gc/update/view.go Interactive huh-based prompt + cron validation for schedule/trigger options.
cmd/harbor/root/gc/cmd.go Registers the gc command group and subcommands.
cmd/harbor/root/gc/history.go Implements harbor gc history with paging/query/sort and output formatting.
cmd/harbor/root/gc/log.go Implements harbor gc log [gc-id].
cmd/harbor/root/gc/schedule.go Implements harbor gc schedule (formatted output or TUI view).
cmd/harbor/root/gc/stop.go Implements harbor gc stop [gc-id].
cmd/harbor/root/gc/trigger.go Implements harbor gc trigger (flags or interactive).
cmd/harbor/root/gc/update_schedule.go Implements harbor gc update-schedule [type] (flags or interactive).
cmd/harbor/root/gc/gc_test.go Adds CLI validation tests for GC history and update-schedule.
cmd/harbor/root/cmd.go Registers gc under the system command group.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/cmd.go
Comment thread pkg/api/gc_handler.go
Comment thread cmd/harbor/root/gc/update_schedule.go
Comment thread pkg/views/gc/list/view.go
Comment thread pkg/views/gc/list/view.go
Comment thread pkg/views/gc/view/view.go
Comment thread pkg/views/gc/view/view.go
Comment thread cmd/harbor/root/gc/update_schedule.go
Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.54501% with 343 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.52%. Comparing base (60ad0bd) to head (e71bc24).
⚠️ Report is 188 commits behind head on main.

Files with missing lines Patch % Lines
pkg/api/gc_handler.go 0.00% 93 Missing ⚠️
pkg/views/gc/update/view.go 0.00% 42 Missing ⚠️
pkg/views/gc/view/view.go 0.00% 36 Missing ⚠️
cmd/harbor/root/gc/cmd.go 0.00% 28 Missing ⚠️
pkg/views/gc/list/view.go 0.00% 28 Missing ⚠️
cmd/harbor/root/gc/trigger.go 0.00% 25 Missing ⚠️
cmd/harbor/root/gc/log.go 0.00% 21 Missing ⚠️
cmd/harbor/root/gc/schedule.go 0.00% 21 Missing ⚠️
cmd/harbor/root/gc/stop.go 0.00% 18 Missing ⚠️
cmd/harbor/root/gc/history.go 52.77% 16 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff            @@
##             main   #1018      +/-   ##
=========================================
- Coverage   10.99%   9.52%   -1.47%     
=========================================
  Files         173     332     +159     
  Lines        8671   16493    +7822     
=========================================
+ Hits          953    1571     +618     
- Misses       7612   14785    +7173     
- Partials      106     137      +31     

☔ View full report in Codecov by Harness.
📢 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.

Signed-off-by: Govind Charpe <govind.charpe16@gmail.com>
@gcharpe1604

Copy link
Copy Markdown
Contributor Author

I noticed #1008 introduces generic schedule management.

This proposal focuses on a dedicated GC administration workflow that includes execution history, logs, manual triggering, stopping active runs, and schedule management.

While there is some overlap around scheduling, the broader goal is to provide a complete GC command group rather than only schedule creation/deletion. The scheduling component follows the existing resource-specific pattern already used by scan-all, while the additional commands focus on operational visibility and control of GC executions by leveraging the SDK's built-in GC client.

@gcharpe1604

Copy link
Copy Markdown
Contributor Author

📊 File Changes Breakdown

To keep the review process clean, here is the breakdown of the changes in this PR.

Only 14 files were manually written or modified to implement the core feature. The remaining 136 files are purely auto-generated command documentation (.md) and man pages (.1) created by the repository's doc-generator toolchains.

1. Core Feature Implementation (Manual Changes)

File Action Description Lines Changed
pkg/api/gc_handler.go Created GC endpoints handler calling the Harbor client SDK ~160 lines
pkg/views/gc/ (3 files) Created UI views for GC (history list, schedule, interactive update form) ~190 lines
cmd/harbor/root/gc/ (6 files) Created Subcommands definitions (history, log, schedule, stop, trigger, update-schedule) ~390 lines
cmd/harbor/root/gc/gc_test.go Created Test suite for GC flags, validation, and error states ~95 lines
cmd/harbor/root/cmd.go Modified Registration of the GC command group and sorted imports 5 lines
README.md Modified Updated the feature checklists to mark GC as supported 2 lines

2. Auto-Generated Documentation

These files were automatically generated by running go run doc.go and go run man-docs/man_doc.go from the doc directory to maintain reference consistency:

  • doc/cli-docs/harbor-gc*.md (7 files): Reference manuals for the new gc subcommands.
  • doc/man-docs/man1/harbor-gc*.1 (7 files): Man pages for the new gc subcommands.
  • doc/cli-docs/ & doc/man-docs/ (122 files): Regenerated existing commands reference files to update command tree paths and metadata.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: implement registry-wide Garbage Collection (gc) command group

2 participants