diff --git a/src/pkg/retention/controller_test.go b/src/pkg/retention/controller_test.go index 9b7d03935..28202dd71 100644 --- a/src/pkg/retention/controller_test.go +++ b/src/pkg/retention/controller_test.go @@ -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", diff --git a/src/pkg/retention/launcher.go b/src/pkg/retention/launcher.go index e3d554826..b246f9828 100644 --- a/src/pkg/retention/launcher.go +++ b/src/pkg/retention/launcher.go @@ -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": diff --git a/src/pkg/retention/launcher_test.go b/src/pkg/retention/launcher_test.go index 55f5cd559..f2f14b586 100644 --- a/src/pkg/retention/launcher_test.go +++ b/src/pkg/retention/launcher_test.go @@ -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) diff --git a/src/pkg/retention/policy/rule/models.go b/src/pkg/retention/policy/rule/models.go index 78475ae10..448b10183 100644 --- a/src/pkg/retention/policy/rule/models.go +++ b/src/pkg/retention/policy/rule/models.go @@ -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"`