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