mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-30 06:03:45 +01:00
Merge pull request #8763 from bitsf/tag_retention_rule_order
remove rule none and change rule order
This commit is contained in:
commit
dfdcb3c9cb
@ -66,18 +66,6 @@ func (r *RetentionAPI) GetMetadatas() {
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"rule_template": "nDaysSinceLastPull",
|
||||
"display_text": "pulled within the last # days",
|
||||
"action": "retain",
|
||||
"params": [
|
||||
{
|
||||
"type": "int",
|
||||
"unit": "DAYS",
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"rule_template": "nDaysSinceLastPush",
|
||||
"display_text": "pushed within the last # days",
|
||||
@ -91,11 +79,17 @@ func (r *RetentionAPI) GetMetadatas() {
|
||||
]
|
||||
},
|
||||
{
|
||||
"rule_template": "nothing",
|
||||
"display_text": "none",
|
||||
"action": "retain",
|
||||
"params": []
|
||||
},
|
||||
"rule_template": "nDaysSinceLastPull",
|
||||
"display_text": "pulled within the last # days",
|
||||
"action": "retain",
|
||||
"params": [
|
||||
{
|
||||
"type": "int",
|
||||
"unit": "DAYS",
|
||||
"required": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"rule_template": "always",
|
||||
"display_text": "always",
|
||||
@ -114,14 +108,6 @@ func (r *RetentionAPI) GetMetadatas() {
|
||||
}
|
||||
],
|
||||
"tag_selectors": [
|
||||
{
|
||||
"display_text": "Labels",
|
||||
"kind": "label",
|
||||
"decorations": [
|
||||
"withLabels",
|
||||
"withoutLabels"
|
||||
]
|
||||
},
|
||||
{
|
||||
"display_text": "Tags",
|
||||
"kind": "doublestar",
|
||||
|
@ -152,12 +152,7 @@ func (s *ControllerTestSuite) TestExecution() {
|
||||
},
|
||||
TagSelectors: []*rule.Selector{
|
||||
{
|
||||
Kind: "label",
|
||||
Decoration: "with",
|
||||
Pattern: "latest",
|
||||
},
|
||||
{
|
||||
Kind: "regularExpression",
|
||||
Kind: "doublestar",
|
||||
Decoration: "matches",
|
||||
Pattern: "release-[\\d\\.]+",
|
||||
},
|
||||
@ -165,7 +160,7 @@ func (s *ControllerTestSuite) TestExecution() {
|
||||
ScopeSelectors: map[string][]*rule.Selector{
|
||||
"repository": {
|
||||
{
|
||||
Kind: "regularExpression",
|
||||
Kind: "doublestar",
|
||||
Decoration: "matches",
|
||||
Pattern: ".+",
|
||||
},
|
||||
|
@ -31,9 +31,6 @@ func DeletePolicyAndExec(id int64) error {
|
||||
if _, err := o.Raw("delete from retention_task where execution_id in (select id from retention_execution where policy_id = ?) ", id).Exec(); err != nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := o.Raw("delete from retention_execution where policy_id = ?", id).Exec(); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := o.Delete(&models.RetentionExecution{
|
||||
PolicyID: id,
|
||||
}); err != nil {
|
||||
@ -73,7 +70,13 @@ func UpdateExecution(e *models.RetentionExecution, cols ...string) error {
|
||||
// DeleteExecution Delete Execution
|
||||
func DeleteExecution(id int64) error {
|
||||
o := dao.GetOrmer()
|
||||
_, err := o.Delete(&models.RetentionExecution{
|
||||
_, err := o.Delete(&models.RetentionTask{
|
||||
ExecutionID: id,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = o.Delete(&models.RetentionExecution{
|
||||
ID: id,
|
||||
})
|
||||
return err
|
||||
|
@ -30,7 +30,6 @@ import (
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/label"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
@ -90,10 +89,6 @@ func (suite *JobTestSuite) TestRunSuccess() {
|
||||
Template: latestps.TemplateID,
|
||||
Parameters: ruleParams,
|
||||
TagSelectors: []*rule.Selector{{
|
||||
Kind: label.Kind,
|
||||
Decoration: label.With,
|
||||
Pattern: "L3",
|
||||
}, {
|
||||
Kind: doublestar.Kind,
|
||||
Decoration: doublestar.Matches,
|
||||
Pattern: "**",
|
||||
|
@ -168,8 +168,10 @@ func TestExecution(t *testing.T) {
|
||||
|
||||
func TestTask(t *testing.T) {
|
||||
m := NewManager()
|
||||
err := m.DeleteExecution(1000)
|
||||
require.Nil(t, err)
|
||||
task := &Task{
|
||||
ExecutionID: 1,
|
||||
ExecutionID: 1000,
|
||||
JobID: "1",
|
||||
Status: jjob.PendingStatus.String(),
|
||||
StatusCode: jjob.PendingStatus.Code(),
|
||||
@ -183,7 +185,7 @@ func TestTask(t *testing.T) {
|
||||
// get
|
||||
tk, err := m.GetTask(id)
|
||||
require.Nil(t, err)
|
||||
assert.EqualValues(t, 1, tk.ExecutionID)
|
||||
assert.EqualValues(t, 1000, tk.ExecutionID)
|
||||
|
||||
// update
|
||||
task.ID = id
|
||||
@ -202,11 +204,11 @@ func TestTask(t *testing.T) {
|
||||
|
||||
// list
|
||||
tasks, err := m.ListTasks(&q.TaskQuery{
|
||||
ExecutionID: 1,
|
||||
ExecutionID: 1000,
|
||||
})
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, 1, len(tasks))
|
||||
assert.Equal(t, int64(1), tasks[0].ExecutionID)
|
||||
assert.Equal(t, int64(1000), tasks[0].ExecutionID)
|
||||
assert.Equal(t, 1, tasks[0].Total)
|
||||
assert.Equal(t, jjob.SuccessStatus.String(), tasks[0].Status)
|
||||
assert.Equal(t, jjob.SuccessStatus.Code(), tasks[0].StatusCode)
|
||||
|
@ -67,7 +67,6 @@ func (m *Metadata) Valid(v *validation.Validation) {
|
||||
_ = v.SetError("Trigger.Settings", "cron in Trigger.Settings is required")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ import (
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestk"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestpl"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/nothing"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -122,11 +121,11 @@ func init() {
|
||||
}, lastx.New)
|
||||
|
||||
// Register nothing
|
||||
Register(&Metadata{
|
||||
TemplateID: nothing.TemplateID,
|
||||
Action: action.Retain,
|
||||
Parameters: []*IndexedParam{},
|
||||
}, nothing.New)
|
||||
// Register(&Metadata{
|
||||
// TemplateID: nothing.TemplateID,
|
||||
// Action: action.Retain,
|
||||
// Parameters: []*IndexedParam{},
|
||||
// }, nothing.New)
|
||||
|
||||
// Register always
|
||||
Register(&Metadata{
|
||||
|
@ -84,7 +84,7 @@ func (suite *IndexTestSuite) TestGet() {
|
||||
// TestIndex tests Index
|
||||
func (suite *IndexTestSuite) TestIndex() {
|
||||
metas := Index()
|
||||
require.Equal(suite.T(), 9, len(metas))
|
||||
require.Equal(suite.T(), 8, len(metas))
|
||||
assert.Condition(suite.T(), func() bool {
|
||||
for _, m := range metas {
|
||||
if m.TemplateID == "fakeEvaluator" &&
|
||||
|
@ -45,11 +45,11 @@ type Metadata struct {
|
||||
// Selector to narrow down the list
|
||||
type Selector struct {
|
||||
// Kind of the selector
|
||||
// "regularExpression" or "label"
|
||||
Kind string `json:"kind" valid:"Required"`
|
||||
// "doublestar" or "label"
|
||||
Kind string `json:"kind" valid:"Required;Match(doublestar)"`
|
||||
|
||||
// Decorated the selector
|
||||
// for "regularExpression" : "matches" and "excludes"
|
||||
// for "doublestar" : "matching" and "excluding"
|
||||
// for "label" : "with" and "without"
|
||||
Decoration string `json:"decoration" valid:"Required"`
|
||||
|
||||
|
@ -17,8 +17,6 @@ package index
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/label"
|
||||
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
||||
"github.com/pkg/errors"
|
||||
@ -36,7 +34,7 @@ func init() {
|
||||
}, doublestar.New)
|
||||
|
||||
// Register label selector
|
||||
Register(label.Kind, []string{label.With, label.Without}, label.New)
|
||||
// Register(label.Kind, []string{label.With, label.Without}, label.New)
|
||||
}
|
||||
|
||||
// index for keeping the mapping between selector meta and its implementation
|
||||
|
Loading…
Reference in New Issue
Block a user