mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-03 05:21:38 +01:00
feature(tag_retention) add webhook for deleted artifacts (#10982)
Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
parent
cb370f8dd9
commit
890200ea19
@ -65,26 +65,26 @@ func (r *Repository) FromJSON(jsonData string) error {
|
|||||||
// Candidate for retention processor to match
|
// Candidate for retention processor to match
|
||||||
type Candidate struct {
|
type Candidate struct {
|
||||||
// Namespace(project) ID
|
// Namespace(project) ID
|
||||||
NamespaceID int64
|
NamespaceID int64 `json:"namespace_id"`
|
||||||
// Namespace
|
// Namespace
|
||||||
Namespace string
|
Namespace string `json:"namespace"`
|
||||||
// Repository name
|
// Repository name
|
||||||
Repository string
|
Repository string `json:"repository"`
|
||||||
// Kind of the candidate
|
// Kind of the candidate
|
||||||
// "image" or "chart"
|
// "image" or "chart"
|
||||||
Kind string
|
Kind string `json:"kind"`
|
||||||
// Tags attached with the candidate
|
// Tags attached with the candidate
|
||||||
Tags []string
|
Tags []string `json:"tags"`
|
||||||
// Digest
|
// Digest
|
||||||
Digest string
|
Digest string `json:"digest"`
|
||||||
// Pushed time in seconds
|
// Pushed time in seconds
|
||||||
PushedTime int64
|
PushedTime int64 `json:"pushed_time_second"`
|
||||||
// Pulled time in seconds
|
// Pulled time in seconds
|
||||||
PulledTime int64
|
PulledTime int64 `json:"pulled_time_second"`
|
||||||
// Created time in seconds
|
// Created time in seconds
|
||||||
CreationTime int64
|
CreationTime int64 `json:"create_time_second"`
|
||||||
// Labels attached with the candidate
|
// Labels attached with the candidate
|
||||||
Labels []string
|
Labels []string `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash code based on the candidate info for differentiation
|
// Hash code based on the candidate info for differentiation
|
||||||
|
@ -114,22 +114,26 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
|||||||
logResults(myLogger, allCandidates, results)
|
logResults(myLogger, allCandidates, results)
|
||||||
|
|
||||||
// Save retain and total num in DB
|
// Save retain and total num in DB
|
||||||
return saveRetainNum(ctx, results, allCandidates)
|
return saveRetainNum(ctx, results, allCandidates, isDryRun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandidates []*artifactselector.Candidate) error {
|
func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandidates []*artifactselector.Candidate, isDryRun bool) error {
|
||||||
var delNum int
|
var realDelete []*artifactselector.Result
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Error == nil {
|
if r.Error == nil {
|
||||||
delNum++
|
realDelete = append(realDelete, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retainObj := struct {
|
retainObj := struct {
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
Retained int `json:"retained"`
|
Retained int `json:"retained"`
|
||||||
|
DryRun bool `json:"dry_run"`
|
||||||
|
Deleted []*artifactselector.Result `json:"deleted"`
|
||||||
}{
|
}{
|
||||||
Total: len(allCandidates),
|
Total: len(allCandidates),
|
||||||
Retained: len(allCandidates) - delNum,
|
Retained: len(allCandidates) - len(realDelete),
|
||||||
|
DryRun: isDryRun,
|
||||||
|
Deleted: realDelete,
|
||||||
}
|
}
|
||||||
c, err := json.Marshal(retainObj)
|
c, err := json.Marshal(retainObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user