mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-01 04:21:36 +01:00
fix tag_retention bug
Signed-off-by: Ziming Zhang <zziming@vmware.com> Change-Id: I8e645c351817afede442a1bf29dd7ad6da31ad06
This commit is contained in:
parent
63d16d4b6b
commit
98994ce459
@ -131,7 +131,7 @@ func (r *DefaultAPIController) UpdateRetention(p *policy.Metadata) error {
|
||||
case policy.TriggerKindSchedule:
|
||||
if p0.Trigger.Settings["cron"] != p.Trigger.Settings["cron"] {
|
||||
// unschedule old
|
||||
if len(p0.Trigger.References[policy.TriggerReferencesJobid].(string)) > 0 {
|
||||
if len(p0.Trigger.Settings[policy.TriggerSettingsCron].(string)) > 0 {
|
||||
needUn = true
|
||||
}
|
||||
// schedule new
|
||||
@ -197,6 +197,8 @@ func (r *DefaultAPIController) TriggerRetentionExec(policyID int64, trigger stri
|
||||
}
|
||||
id, err := r.manager.CreateExecution(exec)
|
||||
if _, err = r.launcher.Launch(p, id, dryRun); err != nil {
|
||||
// clean execution if launch failed
|
||||
_ = r.manager.DeleteExecution(id)
|
||||
return 0, err
|
||||
}
|
||||
return id, err
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
jobmodels "github.com/goharbor/harbor/src/common/models"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/dao/models"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/q"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// CreatePolicy Create Policy
|
||||
@ -101,27 +102,31 @@ func fillStatus(exec *models.RetentionExecution) error {
|
||||
return err
|
||||
}
|
||||
var (
|
||||
total, running, succeed, failed, stopped int
|
||||
total, running, succeed, failed, stopped int64
|
||||
)
|
||||
for k, v := range r {
|
||||
total += v.(int)
|
||||
for k, s := range r {
|
||||
v, err := strconv.ParseInt(s.(string), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
total += v
|
||||
switch k {
|
||||
case jobmodels.JobScheduled:
|
||||
running += v.(int)
|
||||
running += v
|
||||
case jobmodels.JobPending:
|
||||
running += v.(int)
|
||||
running += v
|
||||
case jobmodels.JobRunning:
|
||||
running += v.(int)
|
||||
running += v
|
||||
case jobmodels.JobRetrying:
|
||||
running += v.(int)
|
||||
running += v
|
||||
case jobmodels.JobFinished:
|
||||
succeed += v.(int)
|
||||
succeed += v
|
||||
case jobmodels.JobCanceled:
|
||||
stopped += v.(int)
|
||||
stopped += v
|
||||
case jobmodels.JobStopped:
|
||||
stopped += v.(int)
|
||||
stopped += v
|
||||
case jobmodels.JobError:
|
||||
failed += v.(int)
|
||||
failed += v
|
||||
}
|
||||
}
|
||||
if total == 0 {
|
||||
|
@ -97,6 +97,9 @@ func (f *fakeRetentionManager) UpdateExecution(execution *Execution) error {
|
||||
func (f *fakeRetentionManager) GetExecution(eid int64) (*Execution, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (f *fakeRetentionManager) DeleteExecution(eid int64) error {
|
||||
return nil
|
||||
}
|
||||
func (f *fakeRetentionManager) ListTasks(query ...*q.TaskQuery) ([]*Task, error) {
|
||||
return []*Task{
|
||||
{
|
||||
|
@ -42,6 +42,8 @@ type Manager interface {
|
||||
GetPolicy(ID int64) (*policy.Metadata, error)
|
||||
// Create a new retention execution
|
||||
CreateExecution(execution *Execution) (int64, error)
|
||||
// Delete a new retention execution
|
||||
DeleteExecution(int64) error
|
||||
// Get the specified execution
|
||||
GetExecution(eid int64) (*Execution, error)
|
||||
// List execution histories
|
||||
@ -127,6 +129,11 @@ func (d *DefaultManager) CreateExecution(execution *Execution) (int64, error) {
|
||||
return dao.CreateExecution(exec)
|
||||
}
|
||||
|
||||
// DeleteExecution Delete Execution
|
||||
func (d *DefaultManager) DeleteExecution(eid int64) error {
|
||||
return dao.DeleteExecution(eid)
|
||||
}
|
||||
|
||||
// ListExecutions List Executions
|
||||
func (d *DefaultManager) ListExecutions(policyID int64, query *q.Query) ([]*Execution, error) {
|
||||
execs, err := dao.ListExecutions(policyID, query)
|
||||
|
@ -161,6 +161,9 @@ func TestExecution(t *testing.T) {
|
||||
es, err := m.ListExecutions(policyID, nil)
|
||||
assert.Nil(t, err)
|
||||
assert.EqualValues(t, 1, len(es))
|
||||
|
||||
err = m.DeleteExecution(id)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestTask(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user