diff --git a/src/pkg/artifactselector/candidate.go b/src/pkg/artifactselector/candidate.go index 818f29e5e..8a3996f29 100644 --- a/src/pkg/artifactselector/candidate.go +++ b/src/pkg/artifactselector/candidate.go @@ -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 diff --git a/src/pkg/retention/job.go b/src/pkg/retention/job.go index 55bec12db..cd69bec46 100644 --- a/src/pkg/retention/job.go +++ b/src/pkg/retention/job.go @@ -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"` + 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 {