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