Skip to content

Feature: Implement Garbage Collection (GC) Management Commands #624

Open
intojhanurag wants to merge 27 commits intogoharbor:mainfrom
intojhanurag:feat/gc-commmand-implementation
Open

Feature: Implement Garbage Collection (GC) Management Commands #624
intojhanurag wants to merge 27 commits intogoharbor:mainfrom
intojhanurag:feat/gc-commmand-implementation

Conversation

@intojhanurag
Copy link
Copy Markdown
Contributor

@intojhanurag intojhanurag commented Jan 22, 2026

Description

Currently, the Harbor CLI lacks support for managing Garbage Collection (GC), which is a key gap compared to the Harbor WebUI. Users must switch to the WebUI to trigger or schedule storage cleanup, breaking the flow for CLI-based administration and automation.

This PR adds full GC management capabilities to the Harbor CLI.

Closed

Proposed Solution

Introduce a new gc command group under the System group with the following sub-commands:

  • harbor gc list
    List the history of GC executions, including ID, status, dry-run, and start/end time.

    • --page 2 --page-size 20
    • --sort -creation_time
    • --match job_status=Success : filter gc history by exact match
    • --fuzzy job_name=gc : filter gc history by fuzzy match
    • --range id=1~10 : filter gc history by range
  • harbor gc schedule
    View the current GC schedule (rendered using table view).

  • harbor gc update-schedule [type]
    Update the GC schedule. Supported schedule types: none, hourly, daily, weekly, custom-> Interactive input of user.

    • After harbor gc update-schedule custom
      User will go through the interactive prompt where he will enter the 6-field cron format.
  • harbor gc run
    Manually trigger a GC job. Supports flags:

    • --dry-run: Simulate GC without deleting artifacts.
    • --delete-untagged: Delete untagged artifacts (default: true).
  • harbor gc stop

    • Interactive select from all active running gc and then with cursor he will select the process that he want to stop
  • harbor gc log [id]
    Retrieve and display the log for a specific GC execution.

video demo

https://www.loom.com/share/0b068199f6b34f64b290cee2030e0406

@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch from f0bf5bd to 3a348c1 Compare January 22, 2026 10:42
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 3.09917% with 469 lines in your changes missing coverage. Please review.
✅ Project coverage is 7.29%. Comparing base (60ad0bd) to head (7c5ef97).
⚠️ Report is 106 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/gc/update_schedule.go 14.45% 71 Missing ⚠️
pkg/api/gc_handler.go 0.00% 64 Missing ⚠️
cmd/harbor/root/gc/list.go 0.00% 62 Missing ⚠️
pkg/prompt/prompt.go 0.00% 51 Missing ⚠️
cmd/harbor/root/gc/stop.go 0.00% 35 Missing ⚠️
pkg/views/gc/update/view.go 0.00% 32 Missing ⚠️
cmd/harbor/root/gc/log.go 0.00% 27 Missing ⚠️
cmd/harbor/root/gc/run.go 0.00% 23 Missing ⚠️
pkg/views/gc/schedule/view.go 0.00% 22 Missing ⚠️
cmd/harbor/root/gc/view_schedule.go 0.00% 21 Missing ⚠️
... and 4 more
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #624      +/-   ##
=========================================
- Coverage   10.99%   7.29%   -3.71%     
=========================================
  Files         173     274     +101     
  Lines        8671   13429    +4758     
=========================================
+ Hits          953     979      +26     
- Misses       7612   12341    +4729     
- Partials      106     109       +3     

☔ 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.

@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch from 3a348c1 to c68fc20 Compare January 22, 2026 10:45
@intojhanurag intojhanurag marked this pull request as draft January 22, 2026 11:04
@NucleoFusion
Copy link
Copy Markdown
Contributor

Hi!
so I have already been working on this, but if you wish to do this, I can remove my PR (its been a while since I worked on it)

@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch from 3f08684 to 741cc90 Compare January 22, 2026 12:02
@intojhanurag
Copy link
Copy Markdown
Contributor Author

Hi! so I have already been working on this, but if you wish to do this, I can remove my PR (its been a while since I worked on it)

Hey I am working with this from two days . Please give me the chance to implement this :)
Thanks !

@intojhanurag intojhanurag marked this pull request as ready for review January 22, 2026 12:06
@NucleoFusion
Copy link
Copy Markdown
Contributor

No issues,
but just as a heads up, have a look at existing issues/PRs before building, its fine since it was kinda stale this time, but we wouldnt want 2 contributors to clash.

@NucleoFusion
Copy link
Copy Markdown
Contributor

Also, we use charm/huh as inputs, have a look at my PR.
the update-schedule is not apparent that it requires cron flag to be set. and take that input via charm/huh.

@intojhanurag
Copy link
Copy Markdown
Contributor Author

Also, we use charm/huh as inputs, have a look at my PR. the update-schedule is not apparent that it requires cron flag to be set. and take that input via charm/huh.

Thanks, will take a look !

@intojhanurag intojhanurag marked this pull request as draft January 22, 2026 12:33
@intojhanurag
Copy link
Copy Markdown
Contributor Author

No issues, but just as a heads up, have a look at existing issues/PRs before building, its fine since it was kinda stale this time, but we wouldnt want 2 contributors to clash.

Sorry for that 🥲

@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch from ae2f328 to 8e030ac Compare January 22, 2026 13:10
@intojhanurag intojhanurag marked this pull request as ready for review January 22, 2026 13:16
@intojhanurag intojhanurag marked this pull request as draft January 22, 2026 13:38
@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch 2 times, most recently from 4cd3d65 to bb5d2b0 Compare January 22, 2026 13:55
@intojhanurag intojhanurag marked this pull request as ready for review January 22, 2026 16:02
@intojhanurag
Copy link
Copy Markdown
Contributor Author

Hey @bupd , Can I get a review on this one ?

@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch 8 times, most recently from f5bc52a to 403db9b Compare January 28, 2026 11:16
@NucleoFusion
Copy link
Copy Markdown
Contributor

Do ping me after this is ready for review, from what I can see. Its still being developed

@intojhanurag
Copy link
Copy Markdown
Contributor Author

Do ping me after this is ready for review, from what I can see. Its still being developed

Hey @NucleoFusion , I added all commands mine and as well as mentioned by you on your issue :)
Can you take a look , what i can add next ?

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.

Thanks for the contribution! LGTM, please only address minor changes and make sure merge conflicts are solved.

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
…ommand

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
…pt package

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
  - Add FIXME(goharbor#716) comment for client-side GC job filtering in prompt.go
  - Return error from ViewGCSchedule instead of os.Exit(1)
  - Return error from UpdateSchedule instead of log.Fatal
  - Update callers to handle returned errors

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
…os.Exit

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
…C filtering

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
…aily/weekly)

Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: intojhanurag <aojharaj2004@gmail.com>
Signed-off-by: Anurag Ojha <aojharaj2004@gmail.com>
@intojhanurag intojhanurag force-pushed the feat/gc-commmand-implementation branch from 7c5ef97 to d4de77e Compare March 25, 2026 17:45
@intojhanurag
Copy link
Copy Markdown
Contributor Author

Hey @qcserestipy , I applied all your suggestions. PTAL :)

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. enhancement New feature or request help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Implement Garbage Collection (GC) Management Commands

5 participants