feat(schedule): add smart router for schedule create and delete commands#1008
Open
Psykii22 wants to merge 1 commit into
Open
feat(schedule): add smart router for schedule create and delete commands#1008Psykii22 wants to merge 1 commit into
Psykii22 wants to merge 1 commit into
Conversation
Signed-off-by: Psykii22 <189542486+Psykii22@users.noreply.github.com>
Contributor
|
I like the idea of this, please make an issue and connect the PR to that issue for this. |
Contributor
|
Also, if you could, mention all the commands that have schedule, and what the schedule looks like |
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 |
Contributor
|
Not yet, it should be a separate PR, but we should discuss the pattern, and if we want any modifications etc |
5 tasks
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.
Description
This pull request introduces the ability to create and delete scheduled jobs directly from the CLI.
Previously, the
harbor schedulecommand 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 inpkg/api/schedule_handler.go.This pattern allows users to pass a generic
--typeflag 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 (gcandscan-all). The router is designed to be easily extensible so that the remaining schedule types (likepurgeaudit,replication, etc.) can be seamlessly added in future PRs.Fixes #1009
Type of Change
Please select the relevant type.
Changes
pkg/api/schedule_handler.goto act as a unified router for constructing schedule payloads and sending them to the correct Harbor endpoints.harbor schedule createcommand, requiring a--type(e.g.,gc,scan-all) and a 6-field--cronstring.harbor schedule deletecommand, which sends a schedule payload of typeNoneto the specified job type to disable it.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 gcharbor schedule delete --type scan-allSchedule Format:
The
--cronflag 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-weekWhen a user runs the
deletecommand, the CLI automatically passesType: "None"to the backend Harbor API to disable the schedule.