Skip to content

feat(schedule): add smart router for schedule create and delete commands#1008

Open
Psykii22 wants to merge 1 commit into
goharbor:mainfrom
Psykii22:feat/schedule-router
Open

feat(schedule): add smart router for schedule create and delete commands#1008
Psykii22 wants to merge 1 commit into
goharbor:mainfrom
Psykii22:feat/schedule-router

Conversation

@Psykii22

@Psykii22 Psykii22 commented Jun 19, 2026

Copy link
Copy Markdown

Description

This pull request introduces the ability to create and delete scheduled jobs directly from the CLI.

Previously, the harbor schedule command only supported listing existing schedules. Because Harbor's Go client SDK has completely separate services for updating each job type (e.g., client.GC, client.ScanAll), this PR implements a unified "Smart Router" pattern in pkg/api/schedule_handler.go.

This pattern allows users to pass a generic --type flag from a single CLI command and routes the schedule payload to the correct Harbor backend API automatically. For this initial PR, we have implemented routing for the two most common system-wide schedules (gc and scan-all). The router is designed to be easily extensible so that the remaining schedule types (like purgeaudit, replication, etc.) can be seamlessly added in future PRs.

Fixes #1009

Type of Change

Please select the relevant type.

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

Changes

  • Created pkg/api/schedule_handler.go to act as a unified router for constructing schedule payloads and sending them to the correct Harbor endpoints.
  • Added harbor schedule create command, requiring a --type (e.g., gc, scan-all) and a 6-field --cron string.
  • Added harbor schedule delete command, which sends a schedule payload of type None to the specified job type to disable it.
  • Registered the new subcommands in cmd/harbor/root/schedule/cmd.go.

Examples & Usage

Here are the new commands that manage schedules, and examples of what the schedule format looks like:

1. Create a Garbage Collection schedule:
harbor schedule create --type gc --cron "0 0 * * * *"

2. Create a Scan-All schedule:
harbor schedule create --type scan-all --cron "0 0 * * * *"

3. Delete schedules:
harbor schedule delete --type gc
harbor schedule delete --type scan-all

Schedule Format:

The --cron flag expects a 6-field cron string (which Harbor requires instead of the standard 5-field linux cron). The format is:
Seconds Minutes Hours Day-of-month Month Day-of-week

When a user runs the delete command, the CLI automatically passes Type: "None" to the backend Harbor API to disable the schedule.

Signed-off-by: Psykii22 <189542486+Psykii22@users.noreply.github.com>
@NucleoFusion

Copy link
Copy Markdown
Contributor

I like the idea of this, please make an issue and connect the PR to that issue for this.
And explain in detail why this is nice and what is required for us to do this cleanly.

@NucleoFusion

Copy link
Copy Markdown
Contributor

Also, if you could, mention all the commands that have schedule, and what the schedule looks like

@Psykii22

Copy link
Copy Markdown
Author

Should i add commands for other schedules types also like the purgeaudit and replication. and should i open new issues for that or add in this one

@NucleoFusion

Copy link
Copy Markdown
Contributor

Not yet, it should be a separate PR, but we should discuss the pattern, and if we want any modifications etc

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]:Add create and delete commands for system schedules

2 participants