Merge pull request #8529 from bitsf/tag_retention_disable_rule

add disable rule feature for tag retention
This commit is contained in:
Steven Zou 2019-08-06 20:05:28 +08:00 committed by GitHub
commit 92c2cfa35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 0 deletions

View File

@ -65,6 +65,36 @@ func (s *ControllerTestSuite) TestPolicy() {
},
},
},
{
ID: 2,
Priority: 1,
Template: "recentXdays",
Disabled: true,
Parameters: rule.Parameters{
"num": 3,
},
TagSelectors: []*rule.Selector{
{
Kind: "label",
Decoration: "with",
Pattern: "latest",
},
{
Kind: "regularExpression",
Decoration: "matches",
Pattern: "release-[\\d\\.]+",
},
},
ScopeSelectors: map[string][]*rule.Selector{
"repository": {
{
Kind: "regularExpression",
Decoration: "matches",
Pattern: ".+",
},
},
},
},
},
Trigger: &policy.Trigger{
Kind: "Schedule",

View File

@ -124,6 +124,10 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
}
for _, rule := range ply.Rules {
if rule.Disabled {
log.Infof("Policy %d rule %d %s is disabled", ply.ID, rule.ID, rule.Template)
continue
}
projectCandidates := allProjects
switch level {
case "system":

View File

@ -251,6 +251,25 @@ func (l *launchTestSuite) TestLaunch() {
},
},
},
{
Disabled: true,
ScopeSelectors: map[string][]*rule.Selector{
"project": {
{
Kind: "doublestar",
Decoration: "nsMatches",
Pattern: "library1",
},
},
"repository": {
{
Kind: "doublestar",
Decoration: "repoMatches",
Pattern: "**",
},
},
},
},
},
}
n, err = launcher.Launch(ply, 1, false)

View File

@ -22,6 +22,9 @@ type Metadata struct {
// Priority of rule when doing calculating
Priority int `json:"priority" valid:"Required"`
// Disabled rule
Disabled bool `json:"disabled"`
// Action of the rule performs
// "retain"
Action string `json:"action" valid:"Required"`