From 57e7854beb39aa0ac74e524fc4cd2a9b77a9d06c Mon Sep 17 00:00:00 2001 From: Ziming Zhang Date: Thu, 1 Aug 2019 15:22:49 +0800 Subject: [PATCH] add disable rule feature for tag retention Change-Id: I335f1fb3e1273c945dda85999a0218440092be12 Signed-off-by: Ziming Zhang --- src/pkg/retention/controller_test.go | 30 +++++++++++++++++++++++++ src/pkg/retention/launcher.go | 4 ++++ src/pkg/retention/launcher_test.go | 19 ++++++++++++++++ src/pkg/retention/policy/rule/models.go | 3 +++ 4 files changed, 56 insertions(+) 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 36c36c046..7de1134cf 100644 --- a/src/pkg/retention/launcher.go +++ b/src/pkg/retention/launcher.go @@ -125,6 +125,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 3511ba34e..74e6645dc 100644 --- a/src/pkg/retention/launcher_test.go +++ b/src/pkg/retention/launcher_test.go @@ -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) 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"`