add disable rule feature for tag retention

Change-Id: I335f1fb3e1273c945dda85999a0218440092be12
Signed-off-by: Ziming Zhang <zziming@vmware.com>
This commit is contained in:
Ziming Zhang 2019-08-01 15:22:49 +08:00
parent 75707adeb9
commit 57e7854beb
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{ Trigger: &policy.Trigger{
Kind: "Schedule", Kind: "Schedule",

View File

@ -125,6 +125,10 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
} }
for _, rule := range ply.Rules { 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 projectCandidates := allProjects
switch level { switch level {
case "system": case "system":

View File

@ -243,6 +243,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) n, err = launcher.Launch(ply, 1, false)

View File

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