feature(tag_retention) add webhook for deleted artifacts (#10982)

Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming 2020-03-10 10:46:58 +08:00 committed by GitHub
parent cb370f8dd9
commit 890200ea19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

View File

@ -65,26 +65,26 @@ func (r *Repository) FromJSON(jsonData string) error {
// Candidate for retention processor to match
type Candidate struct {
// Namespace(project) ID
NamespaceID int64
NamespaceID int64 `json:"namespace_id"`
// Namespace
Namespace string
Namespace string `json:"namespace"`
// Repository name
Repository string
Repository string `json:"repository"`
// Kind of the candidate
// "image" or "chart"
Kind string
Kind string `json:"kind"`
// Tags attached with the candidate
Tags []string
Tags []string `json:"tags"`
// Digest
Digest string
Digest string `json:"digest"`
// Pushed time in seconds
PushedTime int64
PushedTime int64 `json:"pushed_time_second"`
// Pulled time in seconds
PulledTime int64
PulledTime int64 `json:"pulled_time_second"`
// Created time in seconds
CreationTime int64
CreationTime int64 `json:"create_time_second"`
// Labels attached with the candidate
Labels []string
Labels []string `json:"labels"`
}
// Hash code based on the candidate info for differentiation

View File

@ -114,22 +114,26 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
logResults(myLogger, allCandidates, results)
// 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 {
var delNum int
func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandidates []*artifactselector.Candidate, isDryRun bool) error {
var realDelete []*artifactselector.Result
for _, r := range results {
if r.Error == nil {
delNum++
realDelete = append(realDelete, r)
}
}
retainObj := struct {
Total int `json:"total"`
Retained int `json:"retained"`
DryRun bool `json:"dry_run"`
Deleted []*artifactselector.Result `json:"deleted"`
}{
Total: len(allCandidates),
Retained: len(allCandidates) - delNum,
Retained: len(allCandidates) - len(realDelete),
DryRun: isDryRun,
Deleted: realDelete,
}
c, err := json.Marshal(retainObj)
if err != nil {