mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-30 06:03:45 +01:00
Merge pull request #10963 from bitsf/retention_move_selectors
feat(pkg) move artifactselector to src/internal/selector
This commit is contained in:
commit
4406ccbd29
@ -6,8 +6,8 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
ierror "github.com/goharbor/harbor/src/internal/error"
|
ierror "github.com/goharbor/harbor/src/internal/error"
|
||||||
"github.com/goharbor/harbor/src/internal/orm"
|
"github.com/goharbor/harbor/src/internal/orm"
|
||||||
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifact"
|
"github.com/goharbor/harbor/src/pkg/artifact"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/q"
|
"github.com/goharbor/harbor/src/pkg/q"
|
||||||
@ -207,7 +207,7 @@ func (c *controller) populateImmutableStatus(ctx context.Context, tag *Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, repoName := utils.ParseRepository(artifact.RepositoryName)
|
_, repoName := utils.ParseRepository(artifact.RepositoryName)
|
||||||
matched, err := c.immutableMtr.Match(artifact.ProjectID, artifactselector.Candidate{
|
matched, err := c.immutableMtr.Match(artifact.ProjectID, selector.Candidate{
|
||||||
Repository: repoName,
|
Repository: repoName,
|
||||||
Tags: []string{tag.Name},
|
Tags: []string{tag.Name},
|
||||||
NamespaceID: artifact.ProjectID,
|
NamespaceID: artifact.ProjectID,
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package artifactselector
|
package selector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package artifactselector
|
package selector
|
||||||
|
|
||||||
// Result keeps the action result
|
// Result keeps the action result
|
||||||
type Result struct {
|
type Result struct {
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package artifactselector
|
package selector
|
||||||
|
|
||||||
// Selector is used to filter the inputting list
|
// Selector is used to filter the inputting list
|
||||||
type Selector interface {
|
type Selector interface {
|
||||||
@ -26,5 +26,5 @@ type Selector interface {
|
|||||||
Select(artifacts []*Candidate) ([]*Candidate, error)
|
Select(artifacts []*Candidate) ([]*Candidate, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectorFactory is factory method to return a selector implementation
|
// Factory is factory method to return a selector implementation
|
||||||
type SelectorFactory func(decoration string, pattern string) Selector
|
type Factory func(decoration string, pattern string) Selector
|
@ -16,7 +16,7 @@ package doublestar
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
iselector "github.com/goharbor/harbor/src/internal/selector"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -46,7 +46,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by regular expressions
|
// Select candidates by regular expressions
|
||||||
func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*artifactselector.Candidate, err error) {
|
func (s *selector) Select(artifacts []*iselector.Candidate) (selected []*iselector.Candidate, err error) {
|
||||||
value := ""
|
value := ""
|
||||||
excludes := false
|
excludes := false
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*
|
|||||||
return selected, nil
|
return selected, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) tagSelectMatch(artifact *artifactselector.Candidate) (selected bool, err error) {
|
func (s *selector) tagSelectMatch(artifact *iselector.Candidate) (selected bool, err error) {
|
||||||
for _, t := range artifact.Tags {
|
for _, t := range artifact.Tags {
|
||||||
matched, err := match(s.pattern, t)
|
matched, err := match(s.pattern, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -109,7 +109,7 @@ func (s *selector) tagSelectMatch(artifact *artifactselector.Candidate) (selecte
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) tagSelectExclude(artifact *artifactselector.Candidate) (selected bool, err error) {
|
func (s *selector) tagSelectExclude(artifact *iselector.Candidate) (selected bool, err error) {
|
||||||
for _, t := range artifact.Tags {
|
for _, t := range artifact.Tags {
|
||||||
matched, err := match(s.pattern, t)
|
matched, err := match(s.pattern, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -123,7 +123,7 @@ func (s *selector) tagSelectExclude(artifact *artifactselector.Candidate) (selec
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for doublestar selector
|
// New is factory method for doublestar selector
|
||||||
func New(decoration string, pattern string) artifactselector.Selector {
|
func New(decoration string, pattern string) iselector.Selector {
|
||||||
return &selector{
|
return &selector{
|
||||||
decoration: decoration,
|
decoration: decoration,
|
||||||
pattern: pattern,
|
pattern: pattern,
|
@ -16,7 +16,7 @@ package doublestar
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
iselector "github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
type RegExpSelectorTestSuite struct {
|
type RegExpSelectorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*artifactselector.Candidate
|
artifacts []*iselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestRegExpSelector is entrance for RegExpSelectorTestSuite
|
// TestRegExpSelector is entrance for RegExpSelectorTestSuite
|
||||||
@ -38,13 +38,13 @@ func TestRegExpSelector(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite to do preparation work
|
// SetupSuite to do preparation work
|
||||||
func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
||||||
suite.artifacts = []*artifactselector.Candidate{
|
suite.artifacts = []*iselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"latest"},
|
Tags: []string{"latest"},
|
||||||
Kind: artifactselector.Image,
|
Kind: iselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -55,7 +55,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "retention",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"4.0"},
|
Tags: []string{"4.0"},
|
||||||
Kind: artifactselector.Image,
|
Kind: iselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -66,7 +66,7 @@ func (suite *RegExpSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "retention",
|
Namespace: "retention",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"4.1"},
|
Tags: []string{"4.1"},
|
||||||
Kind: artifactselector.Image,
|
Kind: iselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -235,7 +235,7 @@ func (suite *RegExpSelectorTestSuite) TestNSExcludes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the returned result matched the expected ones (only check repo:tag)
|
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||||
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
|
func expect(expected []string, candidates []*iselector.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -15,10 +15,10 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/doublestar"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,11 +49,11 @@ type IndexedMeta struct {
|
|||||||
// indexedItem defined item kept in the index
|
// indexedItem defined item kept in the index
|
||||||
type indexedItem struct {
|
type indexedItem struct {
|
||||||
Meta *IndexedMeta
|
Meta *IndexedMeta
|
||||||
Factory artifactselector.SelectorFactory
|
Factory selector.Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the selector with the corresponding selector kind and decoration
|
// Register the selector with the corresponding selector kind and decoration
|
||||||
func Register(kind string, decorations []string, factory artifactselector.SelectorFactory) {
|
func Register(kind string, decorations []string, factory selector.Factory) {
|
||||||
if len(kind) == 0 || factory == nil {
|
if len(kind) == 0 || factory == nil {
|
||||||
// do nothing
|
// do nothing
|
||||||
return
|
return
|
||||||
@ -69,7 +69,7 @@ func Register(kind string, decorations []string, factory artifactselector.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get selector with the provided kind and decoration
|
// Get selector with the provided kind and decoration
|
||||||
func Get(kind, decoration, pattern string) (artifactselector.Selector, error) {
|
func Get(kind, decoration, pattern string) (selector.Selector, error) {
|
||||||
if len(kind) == 0 || len(decoration) == 0 {
|
if len(kind) == 0 || len(decoration) == 0 {
|
||||||
return nil, errors.New("empty selector kind or decoration")
|
return nil, errors.New("empty selector kind or decoration")
|
||||||
}
|
}
|
@ -15,7 +15,7 @@
|
|||||||
package label
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
iselector "github.com/goharbor/harbor/src/internal/selector"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by the labels
|
// Select candidates by the labels
|
||||||
func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*artifactselector.Candidate, err error) {
|
func (s *selector) Select(artifacts []*iselector.Candidate) (selected []*iselector.Candidate, err error) {
|
||||||
for _, art := range artifacts {
|
for _, art := range artifacts {
|
||||||
if isMatched(s.labels, art.Labels, s.decoration) {
|
if isMatched(s.labels, art.Labels, s.decoration) {
|
||||||
selected = append(selected, art)
|
selected = append(selected, art)
|
||||||
@ -49,7 +49,7 @@ func (s *selector) Select(artifacts []*artifactselector.Candidate) (selected []*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for list selector
|
// New is factory method for list selector
|
||||||
func New(decoration string, pattern string) artifactselector.Selector {
|
func New(decoration string, pattern string) iselector.Selector {
|
||||||
labels := make([]string, 0)
|
labels := make([]string, 0)
|
||||||
if len(pattern) > 0 {
|
if len(pattern) > 0 {
|
||||||
labels = append(labels, strings.Split(pattern, ",")...)
|
labels = append(labels, strings.Split(pattern, ",")...)
|
@ -16,7 +16,7 @@ package label
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
iselector "github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
type LabelSelectorTestSuite struct {
|
type LabelSelectorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*artifactselector.Candidate
|
artifacts []*iselector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLabelSelector is entrance for LabelSelectorTestSuite
|
// TestLabelSelector is entrance for LabelSelectorTestSuite
|
||||||
@ -38,13 +38,13 @@ func TestLabelSelector(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite to do preparation work
|
// SetupSuite to do preparation work
|
||||||
func (suite *LabelSelectorTestSuite) SetupSuite() {
|
func (suite *LabelSelectorTestSuite) SetupSuite() {
|
||||||
suite.artifacts = []*artifactselector.Candidate{
|
suite.artifacts = []*iselector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"1.9"},
|
Tags: []string{"1.9"},
|
||||||
Kind: artifactselector.Image,
|
Kind: iselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -55,7 +55,7 @@ func (suite *LabelSelectorTestSuite) SetupSuite() {
|
|||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tags: []string{"dev"},
|
Tags: []string{"dev"},
|
||||||
Kind: artifactselector.Image,
|
Kind: iselector.Image,
|
||||||
PushedTime: time.Now().Unix() - 3600,
|
PushedTime: time.Now().Unix() - 3600,
|
||||||
PulledTime: time.Now().Unix(),
|
PulledTime: time.Now().Unix(),
|
||||||
CreationTime: time.Now().Unix() - 7200,
|
CreationTime: time.Now().Unix() - 7200,
|
||||||
@ -131,7 +131,7 @@ func (suite *LabelSelectorTestSuite) TestWithoutNoneExistingLabels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check whether the returned result matched the expected ones (only check repo:tag)
|
// Check whether the returned result matched the expected ones (only check repo:tag)
|
||||||
func expect(expected []string, candidates []*artifactselector.Candidate) bool {
|
func expect(expected []string, candidates []*iselector.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -1,11 +1,11 @@
|
|||||||
package match
|
package match
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImmutableTagMatcher ...
|
// ImmutableTagMatcher ...
|
||||||
type ImmutableTagMatcher interface {
|
type ImmutableTagMatcher interface {
|
||||||
// Match whether the candidate is in the immutable list
|
// Match whether the candidate is in the immutable list
|
||||||
Match(pid int64, c artifactselector.Candidate) (bool, error)
|
Match(pid int64, c selector.Candidate) (bool, error)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package rule
|
package rule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
iselector "github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/index"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
||||||
@ -14,19 +14,19 @@ type Matcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match ...
|
// Match ...
|
||||||
func (rm *Matcher) Match(pid int64, c artifactselector.Candidate) (bool, error) {
|
func (rm *Matcher) Match(pid int64, c iselector.Candidate) (bool, error) {
|
||||||
if err := rm.getImmutableRules(pid); err != nil {
|
if err := rm.getImmutableRules(pid); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cands := []*artifactselector.Candidate{&c}
|
cands := []*iselector.Candidate{&c}
|
||||||
for _, r := range rm.rules {
|
for _, r := range rm.rules {
|
||||||
if r.Disabled {
|
if r.Disabled {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// match repositories according to the repository selectors
|
// match repositories according to the repository selectors
|
||||||
var repositoryCandidates []*artifactselector.Candidate
|
var repositoryCandidates []*iselector.Candidate
|
||||||
repositorySelectors := r.ScopeSelectors["repository"]
|
repositorySelectors := r.ScopeSelectors["repository"]
|
||||||
if len(repositorySelectors) < 1 {
|
if len(repositorySelectors) < 1 {
|
||||||
continue
|
continue
|
||||||
@ -46,7 +46,7 @@ func (rm *Matcher) Match(pid int64, c artifactselector.Candidate) (bool, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// match tag according to the tag selectors
|
// match tag according to the tag selectors
|
||||||
var tagCandidates []*artifactselector.Candidate
|
var tagCandidates []*iselector.Candidate
|
||||||
tagSelectors := r.TagSelectors
|
tagSelectors := r.TagSelectors
|
||||||
if len(tagSelectors) < 0 {
|
if len(tagSelectors) < 0 {
|
||||||
continue
|
continue
|
||||||
|
@ -2,7 +2,7 @@ package rule
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/model"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -87,7 +87,7 @@ func (s *MatchTestSuite) TestImmuMatch() {
|
|||||||
|
|
||||||
match := NewRuleMatcher()
|
match := NewRuleMatcher()
|
||||||
|
|
||||||
c1 := artifactselector.Candidate{
|
c1 := selector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
@ -97,34 +97,34 @@ func (s *MatchTestSuite) TestImmuMatch() {
|
|||||||
s.require.Equal(isMatch, true)
|
s.require.Equal(isMatch, true)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c2 := artifactselector.Candidate{
|
c2 := selector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "redis",
|
Repository: "redis",
|
||||||
Tags: []string{"1.10"},
|
Tags: []string{"1.10"},
|
||||||
Kind: artifactselector.Image,
|
Kind: selector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c2)
|
isMatch, err = match.Match(1, c2)
|
||||||
s.require.Equal(isMatch, false)
|
s.require.Equal(isMatch, false)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c3 := artifactselector.Candidate{
|
c3 := selector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "immutable",
|
Namespace: "immutable",
|
||||||
Repository: "mysql",
|
Repository: "mysql",
|
||||||
Tags: []string{"9.4.8"},
|
Tags: []string{"9.4.8"},
|
||||||
Kind: artifactselector.Image,
|
Kind: selector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c3)
|
isMatch, err = match.Match(1, c3)
|
||||||
s.require.Equal(isMatch, true)
|
s.require.Equal(isMatch, true)
|
||||||
s.require.Nil(err)
|
s.require.Nil(err)
|
||||||
|
|
||||||
c4 := artifactselector.Candidate{
|
c4 := selector.Candidate{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "immutable",
|
Namespace: "immutable",
|
||||||
Repository: "hello",
|
Repository: "hello",
|
||||||
Tags: []string{"world"},
|
Tags: []string{"world"},
|
||||||
Kind: artifactselector.Image,
|
Kind: selector.Image,
|
||||||
}
|
}
|
||||||
isMatch, err = match.Match(1, c4)
|
isMatch, err = match.Match(1, c4)
|
||||||
s.require.Equal(isMatch, false)
|
s.require.Equal(isMatch, false)
|
||||||
|
@ -17,7 +17,7 @@ package dep
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ type Client interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Candidate : candidates returned
|
// []*art.Candidate : candidates returned
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error)
|
GetCandidates(repo *selector.Repository) ([]*selector.Candidate, error)
|
||||||
|
|
||||||
// Delete the given repository
|
// Delete the given repository
|
||||||
//
|
//
|
||||||
@ -48,7 +48,7 @@ type Client interface {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
DeleteRepository(repo *artifactselector.Repository) error
|
DeleteRepository(repo *selector.Repository) error
|
||||||
|
|
||||||
// Delete the specified candidate
|
// Delete the specified candidate
|
||||||
//
|
//
|
||||||
@ -57,7 +57,7 @@ type Client interface {
|
|||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Delete(candidate *artifactselector.Candidate) error
|
Delete(candidate *selector.Candidate) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient new a basic client
|
// NewClient new a basic client
|
||||||
@ -89,13 +89,13 @@ type basicClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidates gets the tag candidates under the repository
|
// GetCandidates gets the tag candidates under the repository
|
||||||
func (bc *basicClient) GetCandidates(repository *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
func (bc *basicClient) GetCandidates(repository *selector.Repository) ([]*selector.Candidate, error) {
|
||||||
if repository == nil {
|
if repository == nil {
|
||||||
return nil, errors.New("repository is nil")
|
return nil, errors.New("repository is nil")
|
||||||
}
|
}
|
||||||
candidates := make([]*artifactselector.Candidate, 0)
|
candidates := make([]*selector.Candidate, 0)
|
||||||
switch repository.Kind {
|
switch repository.Kind {
|
||||||
case artifactselector.Image:
|
case selector.Image:
|
||||||
artifacts, err := bc.coreClient.ListAllArtifacts(repository.Namespace, repository.Name)
|
artifacts, err := bc.coreClient.ListAllArtifacts(repository.Namespace, repository.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -120,8 +120,8 @@ func (bc *basicClient) GetCandidates(repository *artifactselector.Repository) ([
|
|||||||
lastPushedTime = t.PushTime
|
lastPushedTime = t.PushTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
candidate := &artifactselector.Candidate{
|
candidate := &selector.Candidate{
|
||||||
Kind: artifactselector.Image,
|
Kind: selector.Image,
|
||||||
NamespaceID: repository.NamespaceID,
|
NamespaceID: repository.NamespaceID,
|
||||||
Namespace: repository.Namespace,
|
Namespace: repository.Namespace,
|
||||||
Repository: repository.Name,
|
Repository: repository.Name,
|
||||||
@ -165,12 +165,12 @@ func (bc *basicClient) GetCandidates(repository *artifactselector.Repository) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository deletes the specified repository
|
// DeleteRepository deletes the specified repository
|
||||||
func (bc *basicClient) DeleteRepository(repo *artifactselector.Repository) error {
|
func (bc *basicClient) DeleteRepository(repo *selector.Repository) error {
|
||||||
if repo == nil {
|
if repo == nil {
|
||||||
return errors.New("repository is nil")
|
return errors.New("repository is nil")
|
||||||
}
|
}
|
||||||
switch repo.Kind {
|
switch repo.Kind {
|
||||||
case artifactselector.Image:
|
case selector.Image:
|
||||||
return bc.coreClient.DeleteArtifactRepository(repo.Namespace, repo.Name)
|
return bc.coreClient.DeleteArtifactRepository(repo.Namespace, repo.Name)
|
||||||
/*
|
/*
|
||||||
case art.Chart:
|
case art.Chart:
|
||||||
@ -182,12 +182,12 @@ func (bc *basicClient) DeleteRepository(repo *artifactselector.Repository) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the specified candidate
|
// Deletes the specified candidate
|
||||||
func (bc *basicClient) Delete(candidate *artifactselector.Candidate) error {
|
func (bc *basicClient) Delete(candidate *selector.Candidate) error {
|
||||||
if candidate == nil {
|
if candidate == nil {
|
||||||
return errors.New("candidate is nil")
|
return errors.New("candidate is nil")
|
||||||
}
|
}
|
||||||
switch candidate.Kind {
|
switch candidate.Kind {
|
||||||
case artifactselector.Image:
|
case selector.Image:
|
||||||
return bc.coreClient.DeleteArtifact(candidate.Namespace, candidate.Repository, candidate.Digest)
|
return bc.coreClient.DeleteArtifact(candidate.Namespace, candidate.Repository, candidate.Digest)
|
||||||
/*
|
/*
|
||||||
case art.Chart:
|
case art.Chart:
|
||||||
|
@ -17,7 +17,7 @@ package dep
|
|||||||
import (
|
import (
|
||||||
modelsv2 "github.com/goharbor/harbor/src/api/artifact"
|
modelsv2 "github.com/goharbor/harbor/src/api/artifact"
|
||||||
"github.com/goharbor/harbor/src/api/tag"
|
"github.com/goharbor/harbor/src/api/tag"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
model_tag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
model_tag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -82,20 +82,20 @@ type clientTestSuite struct {
|
|||||||
func (c *clientTestSuite) TestGetCandidates() {
|
func (c *clientTestSuite) TestGetCandidates() {
|
||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
var repository *artifactselector.Repository
|
var repository *selector.Repository
|
||||||
// nil repository
|
// nil repository
|
||||||
candidates, err := client.GetCandidates(repository)
|
candidates, err := client.GetCandidates(repository)
|
||||||
require.NotNil(c.T(), err)
|
require.NotNil(c.T(), err)
|
||||||
|
|
||||||
// image repository
|
// image repository
|
||||||
repository = &artifactselector.Repository{}
|
repository = &selector.Repository{}
|
||||||
repository.Kind = artifactselector.Image
|
repository.Kind = selector.Image
|
||||||
repository.Namespace = "library"
|
repository.Namespace = "library"
|
||||||
repository.Name = "hello-world"
|
repository.Name = "hello-world"
|
||||||
candidates, err = client.GetCandidates(repository)
|
candidates, err = client.GetCandidates(repository)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
assert.Equal(c.T(), 1, len(candidates))
|
assert.Equal(c.T(), 1, len(candidates))
|
||||||
assert.Equal(c.T(), artifactselector.Image, candidates[0].Kind)
|
assert.Equal(c.T(), selector.Image, candidates[0].Kind)
|
||||||
assert.Equal(c.T(), "library", candidates[0].Namespace)
|
assert.Equal(c.T(), "library", candidates[0].Namespace)
|
||||||
assert.Equal(c.T(), "hello-world", candidates[0].Repository)
|
assert.Equal(c.T(), "hello-world", candidates[0].Repository)
|
||||||
assert.Equal(c.T(), "latest", candidates[0].Tags[0])
|
assert.Equal(c.T(), "latest", candidates[0].Tags[0])
|
||||||
@ -118,14 +118,14 @@ func (c *clientTestSuite) TestDelete() {
|
|||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
|
|
||||||
var candidate *artifactselector.Candidate
|
var candidate *selector.Candidate
|
||||||
// nil candidate
|
// nil candidate
|
||||||
err := client.Delete(candidate)
|
err := client.Delete(candidate)
|
||||||
require.NotNil(c.T(), err)
|
require.NotNil(c.T(), err)
|
||||||
|
|
||||||
// image
|
// image
|
||||||
candidate = &artifactselector.Candidate{}
|
candidate = &selector.Candidate{}
|
||||||
candidate.Kind = artifactselector.Image
|
candidate.Kind = selector.Image
|
||||||
err = client.Delete(candidate)
|
err = client.Delete(candidate)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -117,18 +117,18 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
|||||||
return saveRetainNum(ctx, results, allCandidates, isDryRun)
|
return saveRetainNum(ctx, results, allCandidates, isDryRun)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandidates []*artifactselector.Candidate, isDryRun bool) error {
|
func saveRetainNum(ctx job.Context, results []*selector.Result, allCandidates []*selector.Candidate, isDryRun bool) error {
|
||||||
var realDelete []*artifactselector.Result
|
var realDelete []*selector.Result
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Error == nil {
|
if r.Error == nil {
|
||||||
realDelete = append(realDelete, r)
|
realDelete = append(realDelete, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retainObj := struct {
|
retainObj := struct {
|
||||||
Total int `json:"total"`
|
Total int `json:"total"`
|
||||||
Retained int `json:"retained"`
|
Retained int `json:"retained"`
|
||||||
DryRun bool `json:"dry_run"`
|
DryRun bool `json:"dry_run"`
|
||||||
Deleted []*artifactselector.Result `json:"deleted"`
|
Deleted []*selector.Result `json:"deleted"`
|
||||||
}{
|
}{
|
||||||
Total: len(allCandidates),
|
Total: len(allCandidates),
|
||||||
Retained: len(allCandidates) - len(realDelete),
|
Retained: len(allCandidates) - len(realDelete),
|
||||||
@ -143,7 +143,7 @@ func saveRetainNum(ctx job.Context, results []*artifactselector.Result, allCandi
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logResults(logger logger.Interface, all []*artifactselector.Candidate, results []*artifactselector.Result) {
|
func logResults(logger logger.Interface, all []*selector.Candidate, results []*selector.Result) {
|
||||||
hash := make(map[string]error, len(results))
|
hash := make(map[string]error, len(results))
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
if r.Target != nil {
|
if r.Target != nil {
|
||||||
@ -151,10 +151,10 @@ func logResults(logger logger.Interface, all []*artifactselector.Candidate, resu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op := func(c *artifactselector.Candidate) string {
|
op := func(c *selector.Candidate) string {
|
||||||
if e, exists := hash[c.Hash()]; exists {
|
if e, exists := hash[c.Hash()]; exists {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
if _, ok := e.(*artifactselector.ImmutableError); ok {
|
if _, ok := e.(*selector.ImmutableError); ok {
|
||||||
return actionMarkImmutable
|
return actionMarkImmutable
|
||||||
}
|
}
|
||||||
return actionMarkError
|
return actionMarkError
|
||||||
@ -202,7 +202,7 @@ func logResults(logger logger.Interface, all []*artifactselector.Candidate, resu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func arn(art *artifactselector.Candidate) string {
|
func arn(art *selector.Candidate) string {
|
||||||
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Digest)
|
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Digest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ func getParamDryRun(params job.Parameters) (bool, error) {
|
|||||||
return dryRun, nil
|
return dryRun, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParamRepo(params job.Parameters) (*artifactselector.Repository, error) {
|
func getParamRepo(params job.Parameters) (*selector.Repository, error) {
|
||||||
v, ok := params[ParamRepo]
|
v, ok := params[ParamRepo]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, errors.Errorf("missing parameter: %s", ParamRepo)
|
return nil, errors.Errorf("missing parameter: %s", ParamRepo)
|
||||||
@ -256,7 +256,7 @@ func getParamRepo(params job.Parameters) (*artifactselector.Repository, error) {
|
|||||||
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := &artifactselector.Repository{}
|
repo := &selector.Repository{}
|
||||||
if err := repo.FromJSON(repoJSON); err != nil {
|
if err := repo.FromJSON(repoJSON); err != nil {
|
||||||
return nil, errors.Wrap(err, "parse repository from JSON")
|
return nil, errors.Wrap(err, "parse repository from JSON")
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,13 @@ package retention
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/internal/selector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
@ -60,10 +60,10 @@ func (suite *JobTestSuite) TearDownSuite() {
|
|||||||
func (suite *JobTestSuite) TestRunSuccess() {
|
func (suite *JobTestSuite) TestRunSuccess() {
|
||||||
params := make(job.Parameters)
|
params := make(job.Parameters)
|
||||||
params[ParamDryRun] = false
|
params[ParamDryRun] = false
|
||||||
repository := &artifactselector.Repository{
|
repository := &selector.Repository{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Name: "harbor",
|
Name: "harbor",
|
||||||
Kind: artifactselector.Image,
|
Kind: selector.Image,
|
||||||
}
|
}
|
||||||
repoJSON, err := repository.ToJSON()
|
repoJSON, err := repository.ToJSON()
|
||||||
require.Nil(suite.T(), err)
|
require.Nil(suite.T(), err)
|
||||||
@ -112,8 +112,8 @@ func (suite *JobTestSuite) TestRunSuccess() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *selector.Repository) ([]*selector.Candidate, error) {
|
||||||
return []*artifactselector.Candidate{
|
return []*selector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -140,12 +140,12 @@ func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *selector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *selector.Repository) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
beegoorm "github.com/astaxie/beego/orm"
|
beegoorm "github.com/astaxie/beego/orm"
|
||||||
"github.com/goharbor/harbor/src/internal/orm"
|
"github.com/goharbor/harbor/src/internal/orm"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/internal/selector/selectors/index"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
|
||||||
|
|
||||||
cjob "github.com/goharbor/harbor/src/common/job"
|
cjob "github.com/goharbor/harbor/src/common/job"
|
||||||
"github.com/goharbor/harbor/src/common/job/models"
|
"github.com/goharbor/harbor/src/common/job/models"
|
||||||
@ -87,7 +87,7 @@ func NewLauncher(projectMgr project.Manager, repositoryMgr repository.Manager,
|
|||||||
|
|
||||||
type jobData struct {
|
type jobData struct {
|
||||||
TaskID int64
|
TaskID int64
|
||||||
Repository artifactselector.Repository
|
Repository selector.Repository
|
||||||
JobName string
|
JobName string
|
||||||
JobParams map[string]interface{}
|
JobParams map[string]interface{}
|
||||||
}
|
}
|
||||||
@ -114,9 +114,9 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
if scope == nil {
|
if scope == nil {
|
||||||
return 0, launcherError(fmt.Errorf("the scope of policy is nil"))
|
return 0, launcherError(fmt.Errorf("the scope of policy is nil"))
|
||||||
}
|
}
|
||||||
repositoryRules := make(map[artifactselector.Repository]*lwp.Metadata, 0)
|
repositoryRules := make(map[selector.Repository]*lwp.Metadata, 0)
|
||||||
level := scope.Level
|
level := scope.Level
|
||||||
var allProjects []*artifactselector.Candidate
|
var allProjects []*selector.Candidate
|
||||||
var err error
|
var err error
|
||||||
if level == "system" {
|
if level == "system" {
|
||||||
// get projects
|
// get projects
|
||||||
@ -147,12 +147,12 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "project":
|
case "project":
|
||||||
projectCandidates = append(projectCandidates, &artifactselector.Candidate{
|
projectCandidates = append(projectCandidates, &selector.Candidate{
|
||||||
NamespaceID: scope.Reference,
|
NamespaceID: scope.Reference,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryCandidates []*artifactselector.Candidate
|
var repositoryCandidates []*selector.Candidate
|
||||||
// get repositories of projects
|
// get repositories of projects
|
||||||
for _, projectCandidate := range projectCandidates {
|
for _, projectCandidate := range projectCandidates {
|
||||||
repositories, err := getRepositories(l.projectMgr, l.repositoryMgr, projectCandidate.NamespaceID, l.chartServerEnabled)
|
repositories, err := getRepositories(l.projectMgr, l.repositoryMgr, projectCandidate.NamespaceID, l.chartServerEnabled)
|
||||||
@ -177,7 +177,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, repositoryCandidate := range repositoryCandidates {
|
for _, repositoryCandidate := range repositoryCandidates {
|
||||||
reposit := artifactselector.Repository{
|
reposit := selector.Repository{
|
||||||
NamespaceID: repositoryCandidate.NamespaceID,
|
NamespaceID: repositoryCandidate.NamespaceID,
|
||||||
Namespace: repositoryCandidate.Namespace,
|
Namespace: repositoryCandidate.Namespace,
|
||||||
Name: repositoryCandidate.Repository,
|
Name: repositoryCandidate.Repository,
|
||||||
@ -218,7 +218,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
return int64(len(jobDatas)), nil
|
return int64(len(jobDatas)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createJobs(repositoryRules map[artifactselector.Repository]*lwp.Metadata, isDryRun bool) ([]*jobData, error) {
|
func createJobs(repositoryRules map[selector.Repository]*lwp.Metadata, isDryRun bool) ([]*jobData, error) {
|
||||||
jobDatas := []*jobData{}
|
jobDatas := []*jobData{}
|
||||||
for repository, policy := range repositoryRules {
|
for repository, policy := range repositoryRules {
|
||||||
jobData := &jobData{
|
jobData := &jobData{
|
||||||
@ -324,14 +324,14 @@ func launcherError(err error) error {
|
|||||||
return errors.Wrap(err, "launcher")
|
return errors.Wrap(err, "launcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjects(projectMgr project.Manager) ([]*artifactselector.Candidate, error) {
|
func getProjects(projectMgr project.Manager) ([]*selector.Candidate, error) {
|
||||||
projects, err := projectMgr.List()
|
projects, err := projectMgr.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var candidates []*artifactselector.Candidate
|
var candidates []*selector.Candidate
|
||||||
for _, pro := range projects {
|
for _, pro := range projects {
|
||||||
candidates = append(candidates, &artifactselector.Candidate{
|
candidates = append(candidates, &selector.Candidate{
|
||||||
NamespaceID: pro.ProjectID,
|
NamespaceID: pro.ProjectID,
|
||||||
Namespace: pro.Name,
|
Namespace: pro.Name,
|
||||||
})
|
})
|
||||||
@ -340,8 +340,8 @@ func getProjects(projectMgr project.Manager) ([]*artifactselector.Candidate, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
||||||
projectID int64, chartServerEnabled bool) ([]*artifactselector.Candidate, error) {
|
projectID int64, chartServerEnabled bool) ([]*selector.Candidate, error) {
|
||||||
var candidates []*artifactselector.Candidate
|
var candidates []*selector.Candidate
|
||||||
/*
|
/*
|
||||||
pro, err := projectMgr.Get(projectID)
|
pro, err := projectMgr.Get(projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -360,7 +360,7 @@ func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manage
|
|||||||
}
|
}
|
||||||
for _, r := range imageRepositories {
|
for _, r := range imageRepositories {
|
||||||
namespace, repo := utils.ParseRepository(r.Name)
|
namespace, repo := utils.ParseRepository(r.Name)
|
||||||
candidates = append(candidates, &artifactselector.Candidate{
|
candidates = append(candidates, &selector.Candidate{
|
||||||
NamespaceID: projectID,
|
NamespaceID: projectID,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Repository: repo,
|
Repository: repo,
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/job"
|
"github.com/goharbor/harbor/src/common/job"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
_ "github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
_ "github.com/goharbor/harbor/src/internal/selector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/project"
|
"github.com/goharbor/harbor/src/pkg/project"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
type IndexTestSuite struct {
|
type IndexTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
candidates []*artifactselector.Candidate
|
candidates []*selector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestIndexEntry is entry of IndexTestSuite
|
// TestIndexEntry is entry of IndexTestSuite
|
||||||
@ -41,7 +41,7 @@ func TestIndexEntry(t *testing.T) {
|
|||||||
func (suite *IndexTestSuite) SetupSuite() {
|
func (suite *IndexTestSuite) SetupSuite() {
|
||||||
Register("fakeAction", newFakePerformer)
|
Register("fakeAction", newFakePerformer)
|
||||||
|
|
||||||
suite.candidates = []*artifactselector.Candidate{{
|
suite.candidates = []*selector.Candidate{{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Kind: "image",
|
Kind: "image",
|
||||||
@ -77,9 +77,9 @@ type fakePerformer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform the artifacts
|
// Perform the artifacts
|
||||||
func (p *fakePerformer) Perform(candidates []*artifactselector.Candidate) (results []*artifactselector.Result, err error) {
|
func (p *fakePerformer) Perform(candidates []*selector.Candidate) (results []*selector.Result, err error) {
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
results = append(results, &artifactselector.Result{
|
results = append(results, &selector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ package action
|
|||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
"github.com/goharbor/harbor/src/pkg/immutabletag/match/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
)
|
)
|
||||||
@ -37,7 +37,7 @@ type Performer interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Result : result infos
|
// []*art.Result : result infos
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Perform(candidates []*artifactselector.Candidate) ([]*artifactselector.Result, error)
|
Perform(candidates []*selector.Candidate) ([]*selector.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformerFactory is factory method for creating Performer
|
// PerformerFactory is factory method for creating Performer
|
||||||
@ -45,13 +45,13 @@ type PerformerFactory func(params interface{}, isDryRun bool) Performer
|
|||||||
|
|
||||||
// retainAction make sure all the candidates will be retained and others will be cleared
|
// retainAction make sure all the candidates will be retained and others will be cleared
|
||||||
type retainAction struct {
|
type retainAction struct {
|
||||||
all []*artifactselector.Candidate
|
all []*selector.Candidate
|
||||||
// Indicate if it is a dry run
|
// Indicate if it is a dry run
|
||||||
isDryRun bool
|
isDryRun bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the action
|
// Perform the action
|
||||||
func (ra *retainAction) Perform(candidates []*artifactselector.Candidate) (results []*artifactselector.Result, err error) {
|
func (ra *retainAction) Perform(candidates []*selector.Candidate) (results []*selector.Result, err error) {
|
||||||
retainedShare := make(map[string]bool)
|
retainedShare := make(map[string]bool)
|
||||||
immutableShare := make(map[string]bool)
|
immutableShare := make(map[string]bool)
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
@ -71,11 +71,11 @@ func (ra *retainAction) Perform(candidates []*artifactselector.Candidate) (resul
|
|||||||
if len(ra.all) > 0 {
|
if len(ra.all) > 0 {
|
||||||
for _, c := range ra.all {
|
for _, c := range ra.all {
|
||||||
if _, ok := retainedShare[c.Hash()]; !ok {
|
if _, ok := retainedShare[c.Hash()]; !ok {
|
||||||
result := &artifactselector.Result{
|
result := &selector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
}
|
}
|
||||||
if _, ok = immutableShare[c.Hash()]; ok {
|
if _, ok = immutableShare[c.Hash()]; ok {
|
||||||
result.Error = &artifactselector.ImmutableError{}
|
result.Error = &selector.ImmutableError{}
|
||||||
} else {
|
} else {
|
||||||
if !ra.isDryRun {
|
if !ra.isDryRun {
|
||||||
if err := dep.DefaultClient.Delete(c); err != nil {
|
if err := dep.DefaultClient.Delete(c); err != nil {
|
||||||
@ -91,11 +91,11 @@ func (ra *retainAction) Perform(candidates []*artifactselector.Candidate) (resul
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func isImmutable(c *artifactselector.Candidate) bool {
|
func isImmutable(c *selector.Candidate) bool {
|
||||||
projectID := c.NamespaceID
|
projectID := c.NamespaceID
|
||||||
repo := c.Repository
|
repo := c.Repository
|
||||||
_, repoName := utils.ParseRepository(repo)
|
_, repoName := utils.ParseRepository(repo)
|
||||||
matched, err := rule.NewRuleMatcher().Match(projectID, artifactselector.Candidate{
|
matched, err := rule.NewRuleMatcher().Match(projectID, selector.Candidate{
|
||||||
Repository: repoName,
|
Repository: repoName,
|
||||||
Tags: c.Tags,
|
Tags: c.Tags,
|
||||||
NamespaceID: projectID,
|
NamespaceID: projectID,
|
||||||
@ -110,7 +110,7 @@ func isImmutable(c *artifactselector.Candidate) bool {
|
|||||||
// NewRetainAction is factory method for RetainAction
|
// NewRetainAction is factory method for RetainAction
|
||||||
func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
||||||
if params != nil {
|
if params != nil {
|
||||||
if all, ok := params.([]*artifactselector.Candidate); ok {
|
if all, ok := params.([]*selector.Candidate); ok {
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: all,
|
all: all,
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
@ -119,7 +119,7 @@ func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: make([]*artifactselector.Candidate, 0),
|
all: make([]*selector.Candidate, 0),
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ package action
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
"github.com/goharbor/harbor/src/pkg/immutabletag"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -34,7 +34,7 @@ type TestPerformerSuite struct {
|
|||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
all []*artifactselector.Candidate
|
all []*selector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPerformer is the entry of the TestPerformerSuite
|
// TestPerformer is the entry of the TestPerformerSuite
|
||||||
@ -44,7 +44,7 @@ func TestPerformer(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *TestPerformerSuite) SetupSuite() {
|
func (suite *TestPerformerSuite) SetupSuite() {
|
||||||
suite.all = []*artifactselector.Candidate{
|
suite.all = []*selector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -81,7 +81,7 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
all: suite.all,
|
all: suite.all,
|
||||||
}
|
}
|
||||||
|
|
||||||
candidates := []*artifactselector.Candidate{
|
candidates := []*selector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -103,7 +103,7 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
|
|
||||||
// TestPerform tests Perform action
|
// TestPerform tests Perform action
|
||||||
func (suite *TestPerformerSuite) TestPerformImmutable() {
|
func (suite *TestPerformerSuite) TestPerformImmutable() {
|
||||||
all := []*artifactselector.Candidate{
|
all := []*selector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -177,7 +177,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
assert.NoError(suite.T(), immutabletag.ImmuCtr.DeleteImmutableRule(imid))
|
assert.NoError(suite.T(), immutabletag.ImmuCtr.DeleteImmutableRule(imid))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
candidates := []*artifactselector.Candidate{
|
candidates := []*selector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -200,7 +200,7 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
require.Equal(suite.T(), "dev", r.Target.Tags[0])
|
require.Equal(suite.T(), "dev", r.Target.Tags[0])
|
||||||
} else if r.Target.Digest == "d2" {
|
} else if r.Target.Digest == "d2" {
|
||||||
require.Error(suite.T(), r.Error)
|
require.Error(suite.T(), r.Error)
|
||||||
require.IsType(suite.T(), (*artifactselector.ImmutableError)(nil), r.Error)
|
require.IsType(suite.T(), (*selector.ImmutableError)(nil), r.Error)
|
||||||
} else {
|
} else {
|
||||||
require.Fail(suite.T(), "should not delete "+r.Target.Hash())
|
require.Fail(suite.T(), "should not delete "+r.Target.Hash())
|
||||||
}
|
}
|
||||||
@ -213,16 +213,16 @@ func (suite *TestPerformerSuite) TestPerformImmutable() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *selector.Repository) ([]*selector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *selector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *selector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package or
|
package or
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
type processor struct {
|
type processor struct {
|
||||||
// keep evaluator and its related selector if existing
|
// keep evaluator and its related selector if existing
|
||||||
// attentions here, the selectors can be empty/nil, that means match all "**"
|
// attentions here, the selectors can be empty/nil, that means match all "**"
|
||||||
evaluators map[*rule.Evaluator][]artifactselector.Selector
|
evaluators map[*rule.Evaluator][]selector.Selector
|
||||||
// action performer
|
// action performer
|
||||||
performers map[string]action.Performer
|
performers map[string]action.Performer
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ type processor struct {
|
|||||||
// New processor
|
// New processor
|
||||||
func New(parameters []*alg.Parameter) alg.Processor {
|
func New(parameters []*alg.Parameter) alg.Processor {
|
||||||
p := &processor{
|
p := &processor{
|
||||||
evaluators: make(map[*rule.Evaluator][]artifactselector.Selector),
|
evaluators: make(map[*rule.Evaluator][]selector.Selector),
|
||||||
performers: make(map[string]action.Performer),
|
performers: make(map[string]action.Performer),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +59,10 @@ func New(parameters []*alg.Parameter) alg.Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates with the rules
|
// Process the candidates with the rules
|
||||||
func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Result, error) {
|
func (p *processor) Process(artifacts []*selector.Candidate) ([]*selector.Result, error) {
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("no artifacts to retention")
|
log.Debug("no artifacts to retention")
|
||||||
return make([]*artifactselector.Result, 0), nil
|
return make([]*selector.Result, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -75,7 +75,7 @@ func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifac
|
|||||||
// for sync
|
// for sync
|
||||||
type chanItem struct {
|
type chanItem struct {
|
||||||
action string
|
action string
|
||||||
processed []*artifactselector.Candidate
|
processed []*selector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
resChan := make(chan *chanItem, 1)
|
resChan := make(chan *chanItem, 1)
|
||||||
@ -124,9 +124,9 @@ func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifac
|
|||||||
for eva, selectors := range p.evaluators {
|
for eva, selectors := range p.evaluators {
|
||||||
var evaluator = *eva
|
var evaluator = *eva
|
||||||
|
|
||||||
go func(evaluator rule.Evaluator, selectors []artifactselector.Selector) {
|
go func(evaluator rule.Evaluator, selectors []selector.Selector) {
|
||||||
var (
|
var (
|
||||||
processed []*artifactselector.Candidate
|
processed []*selector.Candidate
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifac
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*artifactselector.Result, 0)
|
results := make([]*selector.Result, 0)
|
||||||
// Perform actions
|
// Perform actions
|
||||||
for act, hash := range processedCandidates {
|
for act, hash := range processedCandidates {
|
||||||
var attachedErr error
|
var attachedErr error
|
||||||
@ -192,7 +192,7 @@ func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifac
|
|||||||
|
|
||||||
if attachedErr != nil {
|
if attachedErr != nil {
|
||||||
for _, c := range cl {
|
for _, c := range cl {
|
||||||
results = append(results, &artifactselector.Result{
|
results = append(results, &selector.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
Error: attachedErr,
|
Error: attachedErr,
|
||||||
})
|
})
|
||||||
@ -203,10 +203,10 @@ func (p *processor) Process(artifacts []*artifactselector.Candidate) ([]*artifac
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type cHash map[string]*artifactselector.Candidate
|
type cHash map[string]*selector.Candidate
|
||||||
|
|
||||||
func (ch cHash) toList() []*artifactselector.Candidate {
|
func (ch cHash) toList() []*selector.Candidate {
|
||||||
l := make([]*artifactselector.Candidate, 0)
|
l := make([]*selector.Candidate, 0)
|
||||||
|
|
||||||
for _, v := range ch {
|
for _, v := range ch {
|
||||||
l = append(l, v)
|
l = append(l, v)
|
||||||
|
@ -17,12 +17,12 @@ package or
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/label"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/label"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
||||||
@ -39,7 +39,7 @@ import (
|
|||||||
type ProcessorTestSuite struct {
|
type ProcessorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*artifactselector.Candidate
|
all []*selector.Candidate
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func TestProcessor(t *testing.T) {
|
|||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *ProcessorTestSuite) SetupSuite() {
|
func (suite *ProcessorTestSuite) SetupSuite() {
|
||||||
dao.PrepareTestForPostgresSQL()
|
dao.PrepareTestForPostgresSQL()
|
||||||
suite.all = []*artifactselector.Candidate{
|
suite.all = []*selector.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -92,7 +92,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
|
|||||||
lastxParams[lastx.ParameterX] = 10
|
lastxParams[lastx.ParameterX] = 10
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: lastx.New(lastxParams),
|
Evaluator: lastx.New(lastxParams),
|
||||||
Selectors: []artifactselector.Selector{
|
Selectors: []selector.Selector{
|
||||||
doublestar.New(doublestar.Matches, "*dev*"),
|
doublestar.New(doublestar.Matches, "*dev*"),
|
||||||
label.New(label.With, "L1,L2"),
|
label.New(label.With, "L1,L2"),
|
||||||
},
|
},
|
||||||
@ -103,7 +103,7 @@ func (suite *ProcessorTestSuite) TestProcess() {
|
|||||||
latestKParams[latestps.ParameterK] = 10
|
latestKParams[latestps.ParameterK] = 10
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: latestps.New(latestKParams),
|
Evaluator: latestps.New(latestKParams),
|
||||||
Selectors: []artifactselector.Selector{
|
Selectors: []selector.Selector{
|
||||||
label.New(label.With, "L3"),
|
label.New(label.With, "L3"),
|
||||||
},
|
},
|
||||||
Performer: perf,
|
Performer: perf,
|
||||||
@ -133,7 +133,7 @@ func (suite *ProcessorTestSuite) TestProcess2() {
|
|||||||
alwaysParams := make(map[string]rule.Parameter)
|
alwaysParams := make(map[string]rule.Parameter)
|
||||||
params = append(params, &alg.Parameter{
|
params = append(params, &alg.Parameter{
|
||||||
Evaluator: always.New(alwaysParams),
|
Evaluator: always.New(alwaysParams),
|
||||||
Selectors: []artifactselector.Selector{
|
Selectors: []selector.Selector{
|
||||||
doublestar.New(doublestar.Matches, "latest"),
|
doublestar.New(doublestar.Matches, "latest"),
|
||||||
label.New(label.With, ""),
|
label.New(label.With, ""),
|
||||||
},
|
},
|
||||||
@ -165,16 +165,16 @@ func (suite *ProcessorTestSuite) TestProcess2() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *selector.Repository) ([]*selector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *selector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *selector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package alg
|
package alg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -32,7 +32,7 @@ type Processor interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Result : the processed results
|
// []*art.Result : the processed results
|
||||||
// error : common error object if any errors occurred
|
// error : common error object if any errors occurred
|
||||||
Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Result, error)
|
Process(artifacts []*selector.Candidate) ([]*selector.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter for constructing a processor
|
// Parameter for constructing a processor
|
||||||
@ -42,7 +42,7 @@ type Parameter struct {
|
|||||||
Evaluator rule.Evaluator
|
Evaluator rule.Evaluator
|
||||||
|
|
||||||
// Selectors for the rule
|
// Selectors for the rule
|
||||||
Selectors []artifactselector.Selector
|
Selectors []selector.Selector
|
||||||
|
|
||||||
// Performer for the rule evaluator
|
// Performer for the rule evaluator
|
||||||
Performer action.Performer
|
Performer action.Performer
|
||||||
|
@ -16,13 +16,13 @@ package policy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
|
|
||||||
index4 "github.com/goharbor/harbor/src/pkg/retention/policy/action/index"
|
index4 "github.com/goharbor/harbor/src/pkg/retention/policy/action/index"
|
||||||
|
|
||||||
index3 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
index3 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
||||||
|
|
||||||
index2 "github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
index2 "github.com/goharbor/harbor/src/internal/selector/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ type Builder interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder news a basic builder
|
// NewBuilder news a basic builder
|
||||||
func NewBuilder(all []*artifactselector.Candidate) Builder {
|
func NewBuilder(all []*selector.Candidate) Builder {
|
||||||
return &basicBuilder{
|
return &basicBuilder{
|
||||||
allCandidates: all,
|
allCandidates: all,
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func NewBuilder(all []*artifactselector.Candidate) Builder {
|
|||||||
|
|
||||||
// basicBuilder is default implementation of Builder interface
|
// basicBuilder is default implementation of Builder interface
|
||||||
type basicBuilder struct {
|
type basicBuilder struct {
|
||||||
allCandidates []*artifactselector.Candidate
|
allCandidates []*selector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build policy processor from the raw policy
|
// Build policy processor from the raw policy
|
||||||
@ -76,7 +76,7 @@ func (bb *basicBuilder) Build(policy *lwp.Metadata, isDryRun bool) (alg.Processo
|
|||||||
return nil, errors.Wrap(err, "get action performer by metadata")
|
return nil, errors.Wrap(err, "get action performer by metadata")
|
||||||
}
|
}
|
||||||
|
|
||||||
sl := make([]artifactselector.Selector, 0)
|
sl := make([]selector.Selector, 0)
|
||||||
for _, s := range r.TagSelectors {
|
for _, s := range r.TagSelectors {
|
||||||
sel, err := index2.Get(s.Kind, s.Decoration, s.Pattern)
|
sel, err := index2.Get(s.Kind, s.Decoration, s.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -16,7 +16,7 @@ package policy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
index2 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
index2 "github.com/goharbor/harbor/src/pkg/retention/policy/alg/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/index"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
|
|
||||||
@ -32,9 +32,9 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg/or"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg/or"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/label"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/label"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector/selectors/doublestar"
|
"github.com/goharbor/harbor/src/internal/selector/selectors/doublestar"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ import (
|
|||||||
type TestBuilderSuite struct {
|
type TestBuilderSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*artifactselector.Candidate
|
all []*selector.Candidate
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ func TestBuilder(t *testing.T) {
|
|||||||
// SetupSuite prepares the testing content if needed
|
// SetupSuite prepares the testing content if needed
|
||||||
func (suite *TestBuilderSuite) SetupSuite() {
|
func (suite *TestBuilderSuite) SetupSuite() {
|
||||||
dao.PrepareTestForPostgresSQL()
|
dao.PrepareTestForPostgresSQL()
|
||||||
suite.all = []*artifactselector.Candidate{
|
suite.all = []*selector.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -164,21 +164,21 @@ func (suite *TestBuilderSuite) TestBuild() {
|
|||||||
|
|
||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *artifactselector.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *selector.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *artifactselector.Repository) ([]*artifactselector.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *selector.Repository) ([]*selector.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *artifactselector.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *selector.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *artifactselector.Repository, meta *lwp.Metadata) (string, error) {
|
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *selector.Repository, meta *lwp.Metadata) (string, error) {
|
||||||
return "", errors.New("not implemented")
|
return "", errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package always
|
package always
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ const (
|
|||||||
type evaluator struct{}
|
type evaluator struct{}
|
||||||
|
|
||||||
// Process for the "always" Evaluator simply returns the input with no error
|
// Process for the "always" Evaluator simply returns the input with no error
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package always
|
package always
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
sut := New(rule.Parameters{})
|
sut := New(rule.Parameters{})
|
||||||
input := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*selector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ package dayspl
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (result []*artifactselector.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) (result []*selector.Candidate, err error) {
|
||||||
minPullTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
minPullTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if a.PulledTime >= minPullTime {
|
if a.PulledTime >= minPullTime {
|
||||||
|
@ -17,7 +17,7 @@ package dayspl
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*artifactselector.Candidate{
|
data := []*selector.Candidate{
|
||||||
{PulledTime: daysAgo(now, 1, time.Hour)},
|
{PulledTime: daysAgo(now, 1, time.Hour)},
|
||||||
{PulledTime: daysAgo(now, 2, time.Hour)},
|
{PulledTime: daysAgo(now, 2, time.Hour)},
|
||||||
{PulledTime: daysAgo(now, 3, time.Hour)},
|
{PulledTime: daysAgo(now, 3, time.Hour)},
|
||||||
|
@ -17,7 +17,7 @@ package daysps
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (result []*artifactselector.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) (result []*selector.Candidate, err error) {
|
||||||
minPushTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
minPushTime := time.Now().UTC().Add(time.Duration(-1*24*e.n) * time.Hour).Unix()
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if a.PushedTime >= minPushTime {
|
if a.PushedTime >= minPushTime {
|
||||||
|
@ -17,7 +17,7 @@ package daysps
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*artifactselector.Candidate{
|
data := []*selector.Candidate{
|
||||||
{PushedTime: daysAgo(now, 1, time.Hour)},
|
{PushedTime: daysAgo(now, 1, time.Hour)},
|
||||||
{PushedTime: daysAgo(now, 2, time.Hour)},
|
{PushedTime: daysAgo(now, 2, time.Hour)},
|
||||||
{PushedTime: daysAgo(now, 3, time.Hour)},
|
{PushedTime: daysAgo(now, 3, time.Hour)},
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package rule
|
package rule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Evaluator defines method of executing rule
|
// Evaluator defines method of executing rule
|
||||||
@ -28,7 +28,7 @@ type Evaluator interface {
|
|||||||
// Returns:
|
// Returns:
|
||||||
// []*art.Candidate : matched candidates for next stage
|
// []*art.Candidate : matched candidates for next stage
|
||||||
// error : common error object if any errors occurred
|
// error : common error object if any errors occurred
|
||||||
Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error)
|
Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error)
|
||||||
|
|
||||||
// Specify what action is performed to the candidates processed by this evaluator
|
// Specify what action is performed to the candidates processed by this evaluator
|
||||||
Action() string
|
Action() string
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package index
|
package index
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ func (suite *IndexTestSuite) TestGet() {
|
|||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
require.NotNil(suite.T(), evaluator)
|
require.NotNil(suite.T(), evaluator)
|
||||||
|
|
||||||
candidates := []*artifactselector.Candidate{{
|
candidates := []*selector.Candidate{{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Kind: "image",
|
Kind: "image",
|
||||||
@ -102,7 +102,7 @@ type fakeEvaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process rule
|
// Process rule
|
||||||
func (e *fakeEvaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
func (e *fakeEvaluator) Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ package lastx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
@ -40,7 +40,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (retain []*artifactselector.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) (retain []*selector.Candidate, err error) {
|
||||||
cutoff := time.Now().Add(time.Duration(e.x*-24) * time.Hour)
|
cutoff := time.Now().Add(time.Duration(e.x*-24) * time.Hour)
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
if time.Unix(a.PushedTime, 0).UTC().After(cutoff) {
|
if time.Unix(a.PushedTime, 0).UTC().After(cutoff) {
|
||||||
|
@ -2,7 +2,7 @@ package lastx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
data := []*artifactselector.Candidate{
|
data := []*selector.Candidate{
|
||||||
{PushedTime: now.Add(time.Duration(1*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(1*-24) * time.Hour).Unix()},
|
||||||
{PushedTime: now.Add(time.Duration(2*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(2*-24) * time.Hour).Unix()},
|
||||||
{PushedTime: now.Add(time.Duration(3*-24) * time.Hour).Unix()},
|
{PushedTime: now.Add(time.Duration(3*-24) * time.Hour).Unix()},
|
||||||
|
@ -16,7 +16,7 @@ package latestk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
@ -40,7 +40,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error) {
|
||||||
// Sort artifacts by their "active time"
|
// Sort artifacts by their "active time"
|
||||||
//
|
//
|
||||||
// Active time is defined as the selection of c.PulledTime or c.PushedTime,
|
// Active time is defined as the selection of c.PulledTime or c.PushedTime,
|
||||||
@ -81,7 +81,7 @@ func New(params rule.Parameters) rule.Evaluator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func activeTime(c *artifactselector.Candidate) int64 {
|
func activeTime(c *selector.Candidate) int64 {
|
||||||
if c.PulledTime > c.PushedTime {
|
if c.PulledTime > c.PushedTime {
|
||||||
return c.PulledTime
|
return c.PulledTime
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ package latestk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
@ -29,11 +29,11 @@ import (
|
|||||||
type EvaluatorTestSuite struct {
|
type EvaluatorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*artifactselector.Candidate
|
artifacts []*selector.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) SetupSuite() {
|
func (e *EvaluatorTestSuite) SetupSuite() {
|
||||||
e.artifacts = []*artifactselector.Candidate{
|
e.artifacts = []*selector.Candidate{
|
||||||
{PulledTime: 1, PushedTime: 2},
|
{PulledTime: 1, PushedTime: 2},
|
||||||
{PulledTime: 3, PushedTime: 4},
|
{PulledTime: 3, PushedTime: 4},
|
||||||
{PulledTime: 6, PushedTime: 5},
|
{PulledTime: 6, PushedTime: 5},
|
||||||
|
@ -17,7 +17,7 @@ package latestpl
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error) {
|
||||||
sort.Slice(artifacts, func(i, j int) bool {
|
sort.Slice(artifacts, func(i, j int) bool {
|
||||||
return artifacts[i].PulledTime > artifacts[j].PulledTime
|
return artifacts[i].PulledTime > artifacts[j].PulledTime
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,7 @@ package latestpl
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*artifactselector.Candidate{{PulledTime: 0}, {PulledTime: 1}, {PulledTime: 2}, {PulledTime: 3}, {PulledTime: 4}}
|
data := []*selector.Candidate{{PulledTime: 0}, {PulledTime: 1}, {PulledTime: 2}, {PulledTime: 3}, {PulledTime: 4}}
|
||||||
rand.Shuffle(len(data), func(i, j int) {
|
rand.Shuffle(len(data), func(i, j int) {
|
||||||
data[i], data[j] = data[j], data[i]
|
data[i], data[j] = data[j], data[i]
|
||||||
})
|
})
|
||||||
|
@ -17,7 +17,7 @@ package latestps
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ type evaluator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the candidates based on the rule definition
|
// Process the candidates based on the rule definition
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) ([]*artifactselector.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) ([]*selector.Candidate, error) {
|
||||||
// The updated proposal does not guarantee the order artifacts are provided, so we have to sort them first
|
// The updated proposal does not guarantee the order artifacts are provided, so we have to sort them first
|
||||||
sort.Slice(artifacts, func(i, j int) bool {
|
sort.Slice(artifacts, func(i, j int) bool {
|
||||||
return artifacts[i].PushedTime > artifacts[j].PushedTime
|
return artifacts[i].PushedTime > artifacts[j].PushedTime
|
||||||
|
@ -3,7 +3,7 @@ package latestps
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}, {PushedTime: 4}}
|
data := []*selector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}, {PushedTime: 4}}
|
||||||
rand.Shuffle(len(data), func(i, j int) {
|
rand.Shuffle(len(data), func(i, j int) {
|
||||||
data[i], data[j] = data[j], data[i]
|
data[i], data[j] = data[j], data[i]
|
||||||
})
|
})
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package nothing
|
package nothing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/action"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
)
|
)
|
||||||
@ -28,7 +28,7 @@ const (
|
|||||||
type evaluator struct{}
|
type evaluator struct{}
|
||||||
|
|
||||||
// Process for the "nothing" Evaluator simply returns the input with no error
|
// Process for the "nothing" Evaluator simply returns the input with no error
|
||||||
func (e *evaluator) Process(artifacts []*artifactselector.Candidate) (processed []*artifactselector.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*selector.Candidate) (processed []*selector.Candidate, err error) {
|
||||||
return processed, err
|
return processed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package nothing
|
package nothing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
@ -36,7 +36,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
sut := New(rule.Parameters{})
|
sut := New(rule.Parameters{})
|
||||||
input := []*artifactselector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*selector.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package immutabletag
|
package immutabletag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/goharbor/harbor/src/pkg/artifactselector"
|
"github.com/goharbor/harbor/src/internal/selector"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ type FakeMatcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match ...
|
// Match ...
|
||||||
func (f *FakeMatcher) Match(pid int64, c artifactselector.Candidate) (bool, error) {
|
func (f *FakeMatcher) Match(pid int64, c selector.Candidate) (bool, error) {
|
||||||
args := f.Called()
|
args := f.Called()
|
||||||
return args.Bool(0), args.Error(1)
|
return args.Bool(0), args.Error(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user