mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
refactor selector of retention
extract select from pkg/retention, move it to pkg/artselector to make it usable by immutable tag Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
1d16fcfd93
commit
42a5db83b2
@ -88,10 +88,10 @@ func (f *fakedTransfer) Transfer(src *model.Resource, dst *model.Resource) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRun(t *testing.T) {
|
func TestRun(t *testing.T) {
|
||||||
err := transfer.RegisterFactory("res", fakedTransferFactory)
|
err := transfer.RegisterFactory("art", fakedTransferFactory)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"src_resource": `{"type":"res"}`,
|
"src_resource": `{"type":"art"}`,
|
||||||
"dst_resource": `{}`,
|
"dst_resource": `{}`,
|
||||||
}
|
}
|
||||||
rep := &Replication{}
|
rep := &Replication{}
|
||||||
|
@ -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 res
|
package art
|
||||||
|
|
||||||
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 res
|
package art
|
||||||
|
|
||||||
// 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 res
|
package art
|
||||||
|
|
||||||
// Selector is used to filter the inputting list
|
// Selector is used to filter the inputting list
|
||||||
type Selector interface {
|
type Selector interface {
|
@ -16,7 +16,7 @@ package doublestar
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bmatcuk/doublestar"
|
"github.com/bmatcuk/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -46,7 +46,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by regular expressions
|
// Select candidates by regular expressions
|
||||||
func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate, err error) {
|
func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.Candidate, err error) {
|
||||||
value := ""
|
value := ""
|
||||||
excludes := false
|
excludes := false
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for doublestar selector
|
// New is factory method for doublestar selector
|
||||||
func New(decoration string, pattern string) res.Selector {
|
func New(decoration string, pattern string) art.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/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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 []*res.Candidate
|
artifacts []*art.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 = []*res.Candidate{
|
suite.artifacts = []*art.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tag: "latest",
|
Tag: "latest",
|
||||||
Kind: res.Image,
|
Kind: art.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",
|
||||||
Tag: "4.0",
|
Tag: "4.0",
|
||||||
Kind: res.Image,
|
Kind: art.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",
|
||||||
Tag: "4.1",
|
Tag: "4.1",
|
||||||
Kind: res.Image,
|
Kind: art.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 []*res.Candidate) bool {
|
func expect(expected []string, candidates []*art.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -17,8 +17,8 @@ package index
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
"github.com/goharbor/harbor/src/pkg/art/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 res.SelectorFactory
|
Factory art.SelectorFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 res.SelectorFactory) {
|
func Register(kind string, decorations []string, factory art.SelectorFactory) {
|
||||||
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 res.SelectorFactory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get selector with the provided kind and decoration
|
// Get selector with the provided kind and decoration
|
||||||
func Get(kind, decoration, pattern string) (res.Selector, error) {
|
func Get(kind, decoration, pattern string) (art.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")
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ package label
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -39,7 +39,7 @@ type selector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select candidates by the labels
|
// Select candidates by the labels
|
||||||
func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate, err error) {
|
func (s *selector) Select(artifacts []*art.Candidate) (selected []*art.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)
|
||||||
@ -50,7 +50,7 @@ func (s *selector) Select(artifacts []*res.Candidate) (selected []*res.Candidate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New is factory method for list selector
|
// New is factory method for list selector
|
||||||
func New(decoration string, pattern string) res.Selector {
|
func New(decoration string, pattern string) art.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/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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 []*res.Candidate
|
artifacts []*art.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 = []*res.Candidate{
|
suite.artifacts = []*art.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
Tag: "1.9",
|
Tag: "1.9",
|
||||||
Kind: res.Image,
|
Kind: art.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",
|
||||||
Tag: "dev",
|
Tag: "dev",
|
||||||
Kind: res.Image,
|
Kind: art.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 []*res.Candidate) bool {
|
func expect(expected []string, candidates []*art.Candidate) bool {
|
||||||
hash := make(map[string]bool)
|
hash := make(map[string]bool)
|
||||||
|
|
||||||
for _, art := range candidates {
|
for _, art := range candidates {
|
@ -21,8 +21,8 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
"github.com/goharbor/harbor/src/common/http/modifier/auth"
|
||||||
"github.com/goharbor/harbor/src/jobservice/config"
|
"github.com/goharbor/harbor/src/jobservice/config"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/clients/core"
|
"github.com/goharbor/harbor/src/pkg/clients/core"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultClient for the retention
|
// DefaultClient for the retention
|
||||||
@ -33,30 +33,30 @@ type Client interface {
|
|||||||
// Get the tag candidates under the repository
|
// Get the tag candidates under the repository
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// repo *res.Repository : repository info
|
// repo *art.Repository : repository info
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// []*res.Candidate : candidates returned
|
// []*art.Candidate : candidates returned
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
GetCandidates(repo *res.Repository) ([]*res.Candidate, error)
|
GetCandidates(repo *art.Repository) ([]*art.Candidate, error)
|
||||||
|
|
||||||
// Delete the given repository
|
// Delete the given repository
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// repo *res.Repository : repository info
|
// repo *art.Repository : repository info
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
DeleteRepository(repo *res.Repository) error
|
DeleteRepository(repo *art.Repository) error
|
||||||
|
|
||||||
// Delete the specified candidate
|
// Delete the specified candidate
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// candidate *res.Candidate : the deleting candidate
|
// candidate *art.Candidate : the deleting candidate
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Delete(candidate *res.Candidate) error
|
Delete(candidate *art.Candidate) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient new a basic client
|
// NewClient new a basic client
|
||||||
@ -88,13 +88,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 *res.Repository) ([]*res.Candidate, error) {
|
func (bc *basicClient) GetCandidates(repository *art.Repository) ([]*art.Candidate, error) {
|
||||||
if repository == nil {
|
if repository == nil {
|
||||||
return nil, errors.New("repository is nil")
|
return nil, errors.New("repository is nil")
|
||||||
}
|
}
|
||||||
candidates := make([]*res.Candidate, 0)
|
candidates := make([]*art.Candidate, 0)
|
||||||
switch repository.Kind {
|
switch repository.Kind {
|
||||||
case res.Image:
|
case art.Image:
|
||||||
images, err := bc.coreClient.ListAllImages(repository.Namespace, repository.Name)
|
images, err := bc.coreClient.ListAllImages(repository.Namespace, repository.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -104,8 +104,8 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
|
|||||||
for _, label := range image.Labels {
|
for _, label := range image.Labels {
|
||||||
labels = append(labels, label.Name)
|
labels = append(labels, label.Name)
|
||||||
}
|
}
|
||||||
candidate := &res.Candidate{
|
candidate := &art.Candidate{
|
||||||
Kind: res.Image,
|
Kind: art.Image,
|
||||||
Namespace: repository.Namespace,
|
Namespace: repository.Namespace,
|
||||||
Repository: repository.Name,
|
Repository: repository.Name,
|
||||||
Tag: image.Name,
|
Tag: image.Name,
|
||||||
@ -118,7 +118,7 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
|
|||||||
candidates = append(candidates, candidate)
|
candidates = append(candidates, candidate)
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
case res.Chart:
|
case art.Chart:
|
||||||
charts, err := bc.coreClient.ListAllCharts(repository.Namespace, repository.Name)
|
charts, err := bc.coreClient.ListAllCharts(repository.Namespace, repository.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -128,8 +128,8 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
|
|||||||
for _, label := range chart.Labels {
|
for _, label := range chart.Labels {
|
||||||
labels = append(labels, label.Name)
|
labels = append(labels, label.Name)
|
||||||
}
|
}
|
||||||
candidate := &res.Candidate{
|
candidate := &art.Candidate{
|
||||||
Kind: res.Chart,
|
Kind: art.Chart,
|
||||||
Namespace: repository.Namespace,
|
Namespace: repository.Namespace,
|
||||||
Repository: repository.Name,
|
Repository: repository.Name,
|
||||||
Tag: chart.Name,
|
Tag: chart.Name,
|
||||||
@ -148,15 +148,15 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository deletes the specified repository
|
// DeleteRepository deletes the specified repository
|
||||||
func (bc *basicClient) DeleteRepository(repo *res.Repository) error {
|
func (bc *basicClient) DeleteRepository(repo *art.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 res.Image:
|
case art.Image:
|
||||||
return bc.coreClient.DeleteImageRepository(repo.Namespace, repo.Name)
|
return bc.coreClient.DeleteImageRepository(repo.Namespace, repo.Name)
|
||||||
/*
|
/*
|
||||||
case res.Chart:
|
case art.Chart:
|
||||||
return bc.coreClient.DeleteChartRepository(repo.Namespace, repo.Name)
|
return bc.coreClient.DeleteChartRepository(repo.Namespace, repo.Name)
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
@ -165,15 +165,15 @@ func (bc *basicClient) DeleteRepository(repo *res.Repository) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the specified candidate
|
// Deletes the specified candidate
|
||||||
func (bc *basicClient) Delete(candidate *res.Candidate) error {
|
func (bc *basicClient) Delete(candidate *art.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 res.Image:
|
case art.Image:
|
||||||
return bc.coreClient.DeleteImage(candidate.Namespace, candidate.Repository, candidate.Tag)
|
return bc.coreClient.DeleteImage(candidate.Namespace, candidate.Repository, candidate.Tag)
|
||||||
/*
|
/*
|
||||||
case res.Chart:
|
case art.Chart:
|
||||||
return bc.coreClient.DeleteChart(candidate.Namespace, candidate.Repository, candidate.Tag)
|
return bc.coreClient.DeleteChart(candidate.Namespace, candidate.Repository, candidate.Tag)
|
||||||
*/
|
*/
|
||||||
default:
|
default:
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
jmodels "github.com/goharbor/harbor/src/common/job/models"
|
jmodels "github.com/goharbor/harbor/src/common/job/models"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/testing/clients"
|
"github.com/goharbor/harbor/src/testing/clients"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -73,33 +73,33 @@ type clientTestSuite struct {
|
|||||||
func (c *clientTestSuite) TestGetCandidates() {
|
func (c *clientTestSuite) TestGetCandidates() {
|
||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
var repository *res.Repository
|
var repository *art.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 = &res.Repository{}
|
repository = &art.Repository{}
|
||||||
repository.Kind = res.Image
|
repository.Kind = art.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(), res.Image, candidates[0].Kind)
|
assert.Equal(c.T(), art.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].Tag)
|
assert.Equal(c.T(), "latest", candidates[0].Tag)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// chart repository
|
// chart repository
|
||||||
repository.Kind = res.Chart
|
repository.Kind = art.Chart
|
||||||
repository.Namespace = "goharbor"
|
repository.Namespace = "goharbor"
|
||||||
repository.Name = "harbor"
|
repository.Name = "harbor"
|
||||||
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(), res.Chart, candidates[0].Kind)
|
assert.Equal(c.T(), art.Chart, candidates[0].Kind)
|
||||||
assert.Equal(c.T(), "goharbor", candidates[0].Namespace)
|
assert.Equal(c.T(), "goharbor", candidates[0].Namespace)
|
||||||
assert.Equal(c.T(), "1.0", candidates[0].Tag)
|
assert.Equal(c.T(), "1.0", candidates[0].Tag)
|
||||||
*/
|
*/
|
||||||
@ -109,20 +109,20 @@ func (c *clientTestSuite) TestDelete() {
|
|||||||
client := &basicClient{}
|
client := &basicClient{}
|
||||||
client.coreClient = &fakeCoreClient{}
|
client.coreClient = &fakeCoreClient{}
|
||||||
|
|
||||||
var candidate *res.Candidate
|
var candidate *art.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 = &res.Candidate{}
|
candidate = &art.Candidate{}
|
||||||
candidate.Kind = res.Image
|
candidate.Kind = art.Image
|
||||||
err = client.Delete(candidate)
|
err = client.Delete(candidate)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// chart
|
// chart
|
||||||
candidate.Kind = res.Chart
|
candidate.Kind = art.Chart
|
||||||
err = client.Delete(candidate)
|
err = client.Delete(candidate)
|
||||||
require.Nil(c.T(), err)
|
require.Nil(c.T(), err)
|
||||||
*/
|
*/
|
||||||
|
@ -23,10 +23,10 @@ import (
|
|||||||
|
|
||||||
"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/art"
|
||||||
"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/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/olekukonko/tablewriter"
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -116,7 +116,7 @@ func (pj *Job) Run(ctx job.Context, params job.Parameters) error {
|
|||||||
return saveRetainNum(ctx, results, allCandidates)
|
return saveRetainNum(ctx, results, allCandidates)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveRetainNum(ctx job.Context, retained []*res.Result, allCandidates []*res.Candidate) error {
|
func saveRetainNum(ctx job.Context, retained []*art.Result, allCandidates []*art.Candidate) error {
|
||||||
var delNum int
|
var delNum int
|
||||||
for _, r := range retained {
|
for _, r := range retained {
|
||||||
if r.Error == nil {
|
if r.Error == nil {
|
||||||
@ -138,7 +138,7 @@ func saveRetainNum(ctx job.Context, retained []*res.Result, allCandidates []*res
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logResults(logger logger.Interface, all []*res.Candidate, results []*res.Result) {
|
func logResults(logger logger.Interface, all []*art.Candidate, results []*art.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 {
|
||||||
@ -146,7 +146,7 @@ func logResults(logger logger.Interface, all []*res.Candidate, results []*res.Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
op := func(art *res.Candidate) string {
|
op := func(art *art.Candidate) string {
|
||||||
if e, exists := hash[art.Hash()]; exists {
|
if e, exists := hash[art.Hash()]; exists {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return actionMarkError
|
return actionMarkError
|
||||||
@ -194,7 +194,7 @@ func logResults(logger logger.Interface, all []*res.Candidate, results []*res.Re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func arn(art *res.Candidate) string {
|
func arn(art *art.Candidate) string {
|
||||||
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Tag)
|
return fmt.Sprintf("%s/%s:%s", art.Namespace, art.Repository, art.Tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ func getParamDryRun(params job.Parameters) (bool, error) {
|
|||||||
return dryRun, nil
|
return dryRun, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParamRepo(params job.Parameters) (*res.Repository, error) {
|
func getParamRepo(params job.Parameters) (*art.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)
|
||||||
@ -248,7 +248,7 @@ func getParamRepo(params job.Parameters) (*res.Repository, error) {
|
|||||||
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
return nil, errors.Errorf("invalid parameter: %s", ParamRepo)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := &res.Repository{}
|
repo := &art.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")
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,14 @@ import (
|
|||||||
|
|
||||||
"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/art"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art/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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -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 := &res.Repository{
|
repository := &art.Repository{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Name: "harbor",
|
Name: "harbor",
|
||||||
Kind: res.Image,
|
Kind: art.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 *res.Repository) ([]*res.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
||||||
return []*res.Candidate{
|
return []*art.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -140,12 +140,12 @@ func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Cand
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *res.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *res.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/index"
|
"github.com/goharbor/harbor/src/pkg/art/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"
|
||||||
@ -27,12 +27,12 @@ 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/core/config"
|
"github.com/goharbor/harbor/src/core/config"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/project"
|
"github.com/goharbor/harbor/src/pkg/project"
|
||||||
"github.com/goharbor/harbor/src/pkg/repository"
|
"github.com/goharbor/harbor/src/pkg/repository"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
"github.com/goharbor/harbor/src/pkg/retention/policy"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/q"
|
"github.com/goharbor/harbor/src/pkg/retention/q"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ func NewLauncher(projectMgr project.Manager, repositoryMgr repository.Manager,
|
|||||||
|
|
||||||
type jobData struct {
|
type jobData struct {
|
||||||
TaskID int64
|
TaskID int64
|
||||||
Repository res.Repository
|
Repository art.Repository
|
||||||
JobName string
|
JobName string
|
||||||
JobParams map[string]interface{}
|
JobParams map[string]interface{}
|
||||||
}
|
}
|
||||||
@ -111,9 +111,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[res.Repository]*lwp.Metadata, 0)
|
repositoryRules := make(map[art.Repository]*lwp.Metadata, 0)
|
||||||
level := scope.Level
|
level := scope.Level
|
||||||
var allProjects []*res.Candidate
|
var allProjects []*art.Candidate
|
||||||
var err error
|
var err error
|
||||||
if level == "system" {
|
if level == "system" {
|
||||||
// get projects
|
// get projects
|
||||||
@ -144,12 +144,12 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "project":
|
case "project":
|
||||||
projectCandidates = append(projectCandidates, &res.Candidate{
|
projectCandidates = append(projectCandidates, &art.Candidate{
|
||||||
NamespaceID: scope.Reference,
|
NamespaceID: scope.Reference,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryCandidates []*res.Candidate
|
var repositoryCandidates []*art.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)
|
||||||
@ -174,7 +174,7 @@ func (l *launcher) Launch(ply *policy.Metadata, executionID int64, isDryRun bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, repositoryCandidate := range repositoryCandidates {
|
for _, repositoryCandidate := range repositoryCandidates {
|
||||||
reposit := res.Repository{
|
reposit := art.Repository{
|
||||||
Namespace: repositoryCandidate.Namespace,
|
Namespace: repositoryCandidate.Namespace,
|
||||||
Name: repositoryCandidate.Repository,
|
Name: repositoryCandidate.Repository,
|
||||||
Kind: repositoryCandidate.Kind,
|
Kind: repositoryCandidate.Kind,
|
||||||
@ -214,7 +214,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[res.Repository]*lwp.Metadata, isDryRun bool) ([]*jobData, error) {
|
func createJobs(repositoryRules map[art.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{
|
||||||
@ -320,14 +320,14 @@ func launcherError(err error) error {
|
|||||||
return errors.Wrap(err, "launcher")
|
return errors.Wrap(err, "launcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProjects(projectMgr project.Manager) ([]*res.Candidate, error) {
|
func getProjects(projectMgr project.Manager) ([]*art.Candidate, error) {
|
||||||
projects, err := projectMgr.List()
|
projects, err := projectMgr.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var candidates []*res.Candidate
|
var candidates []*art.Candidate
|
||||||
for _, pro := range projects {
|
for _, pro := range projects {
|
||||||
candidates = append(candidates, &res.Candidate{
|
candidates = append(candidates, &art.Candidate{
|
||||||
NamespaceID: pro.ProjectID,
|
NamespaceID: pro.ProjectID,
|
||||||
Namespace: pro.Name,
|
Namespace: pro.Name,
|
||||||
})
|
})
|
||||||
@ -336,8 +336,8 @@ func getProjects(projectMgr project.Manager) ([]*res.Candidate, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manager,
|
||||||
projectID int64, chartServerEnabled bool) ([]*res.Candidate, error) {
|
projectID int64, chartServerEnabled bool) ([]*art.Candidate, error) {
|
||||||
var candidates []*res.Candidate
|
var candidates []*art.Candidate
|
||||||
/*
|
/*
|
||||||
pro, err := projectMgr.Get(projectID)
|
pro, err := projectMgr.Get(projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,7 +351,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, &res.Candidate{
|
candidates = append(candidates, &art.Candidate{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Repository: repo,
|
Repository: repo,
|
||||||
Kind: "image",
|
Kind: "image",
|
||||||
@ -366,7 +366,7 @@ func getRepositories(projectMgr project.Manager, repositoryMgr repository.Manage
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, r := range chartRepositories {
|
for _, r := range chartRepositories {
|
||||||
candidates = append(candidates, &res.Candidate{
|
candidates = append(candidates, &art.Candidate{
|
||||||
Namespace: pro.Name,
|
Namespace: pro.Name,
|
||||||
Repository: r.Name,
|
Repository: r.Name,
|
||||||
Kind: "chart",
|
Kind: "chart",
|
||||||
|
@ -21,12 +21,12 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/chartserver"
|
"github.com/goharbor/harbor/src/chartserver"
|
||||||
"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/art/selectors/doublestar"
|
||||||
"github.com/goharbor/harbor/src/pkg/project"
|
"github.com/goharbor/harbor/src/pkg/project"
|
||||||
"github.com/goharbor/harbor/src/pkg/repository"
|
"github.com/goharbor/harbor/src/pkg/repository"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/q"
|
"github.com/goharbor/harbor/src/pkg/retention/q"
|
||||||
_ "github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
|
||||||
hjob "github.com/goharbor/harbor/src/testing/job"
|
hjob "github.com/goharbor/harbor/src/testing/job"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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/res"
|
|
||||||
"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"
|
||||||
@ -29,7 +29,7 @@ import (
|
|||||||
type IndexTestSuite struct {
|
type IndexTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
candidates []*res.Candidate
|
candidates []*art.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 = []*res.Candidate{{
|
suite.candidates = []*art.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 []*res.Candidate) (results []*res.Result, err error) {
|
func (p *fakePerformer) Perform(candidates []*art.Candidate) (results []*art.Result, err error) {
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
results = append(results, &res.Result{
|
results = append(results, &art.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -29,12 +29,12 @@ type Performer interface {
|
|||||||
// Perform the action
|
// Perform the action
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// candidates []*res.Candidate : the targets to perform
|
// candidates []*art.Candidate : the targets to perform
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// []*res.Result : result infos
|
// []*art.Result : result infos
|
||||||
// error : common error if any errors occurred
|
// error : common error if any errors occurred
|
||||||
Perform(candidates []*res.Candidate) ([]*res.Result, error)
|
Perform(candidates []*art.Candidate) ([]*art.Result, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformerFactory is factory method for creating Performer
|
// PerformerFactory is factory method for creating Performer
|
||||||
@ -42,13 +42,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 []*res.Candidate
|
all []*art.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 []*res.Candidate) (results []*res.Result, err error) {
|
func (ra *retainAction) Perform(candidates []*art.Candidate) (results []*art.Result, err error) {
|
||||||
retained := make(map[string]bool)
|
retained := make(map[string]bool)
|
||||||
for _, c := range candidates {
|
for _, c := range candidates {
|
||||||
retained[c.Hash()] = true
|
retained[c.Hash()] = true
|
||||||
@ -56,14 +56,14 @@ func (ra *retainAction) Perform(candidates []*res.Candidate) (results []*res.Res
|
|||||||
|
|
||||||
// start to delete
|
// start to delete
|
||||||
if len(ra.all) > 0 {
|
if len(ra.all) > 0 {
|
||||||
for _, art := range ra.all {
|
for _, c := range ra.all {
|
||||||
if _, ok := retained[art.Hash()]; !ok {
|
if _, ok := retained[c.Hash()]; !ok {
|
||||||
result := &res.Result{
|
result := &art.Result{
|
||||||
Target: art,
|
Target: c,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ra.isDryRun {
|
if !ra.isDryRun {
|
||||||
if err := dep.DefaultClient.Delete(art); err != nil {
|
if err := dep.DefaultClient.Delete(c); err != nil {
|
||||||
result.Error = err
|
result.Error = err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func (ra *retainAction) Perform(candidates []*res.Candidate) (results []*res.Res
|
|||||||
// 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.([]*res.Candidate); ok {
|
if all, ok := params.([]*art.Candidate); ok {
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: all,
|
all: all,
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
@ -88,7 +88,7 @@ func NewRetainAction(params interface{}, isDryRun bool) Performer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &retainAction{
|
return &retainAction{
|
||||||
all: make([]*res.Candidate, 0),
|
all: make([]*art.Candidate, 0),
|
||||||
isDryRun: isDryRun,
|
isDryRun: isDryRun,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -31,7 +31,7 @@ type TestPerformerSuite struct {
|
|||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
all []*res.Candidate
|
all []*art.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestPerformer is the entry of the TestPerformerSuite
|
// TestPerformer is the entry of the TestPerformerSuite
|
||||||
@ -41,7 +41,7 @@ func TestPerformer(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *TestPerformerSuite) SetupSuite() {
|
func (suite *TestPerformerSuite) SetupSuite() {
|
||||||
suite.all = []*res.Candidate{
|
suite.all = []*art.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -77,7 +77,7 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
all: suite.all,
|
all: suite.all,
|
||||||
}
|
}
|
||||||
|
|
||||||
candidates := []*res.Candidate{
|
candidates := []*art.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -100,16 +100,16 @@ func (suite *TestPerformerSuite) TestPerform() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *res.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *res.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -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][]res.Selector
|
evaluators map[*rule.Evaluator][]art.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][]res.Selector),
|
evaluators: make(map[*rule.Evaluator][]art.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 []*res.Candidate) ([]*res.Result, error) {
|
func (p *processor) Process(artifacts []*art.Candidate) ([]*art.Result, error) {
|
||||||
if len(artifacts) == 0 {
|
if len(artifacts) == 0 {
|
||||||
log.Debug("no artifacts to retention")
|
log.Debug("no artifacts to retention")
|
||||||
return make([]*res.Result, 0), nil
|
return make([]*art.Result, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -75,7 +75,7 @@ func (p *processor) Process(artifacts []*res.Candidate) ([]*res.Result, error) {
|
|||||||
// for sync
|
// for sync
|
||||||
type chanItem struct {
|
type chanItem struct {
|
||||||
action string
|
action string
|
||||||
processed []*res.Candidate
|
processed []*art.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
resChan := make(chan *chanItem, 1)
|
resChan := make(chan *chanItem, 1)
|
||||||
@ -124,9 +124,9 @@ func (p *processor) Process(artifacts []*res.Candidate) ([]*res.Result, error) {
|
|||||||
for eva, selectors := range p.evaluators {
|
for eva, selectors := range p.evaluators {
|
||||||
var evaluator = *eva
|
var evaluator = *eva
|
||||||
|
|
||||||
go func(evaluator rule.Evaluator, selectors []res.Selector) {
|
go func(evaluator rule.Evaluator, selectors []art.Selector) {
|
||||||
var (
|
var (
|
||||||
processed []*res.Candidate
|
processed []*art.Candidate
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ func (p *processor) Process(artifacts []*res.Candidate) ([]*res.Result, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
results := make([]*res.Result, 0)
|
results := make([]*art.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 []*res.Candidate) ([]*res.Result, error) {
|
|||||||
|
|
||||||
if attachedErr != nil {
|
if attachedErr != nil {
|
||||||
for _, c := range cl {
|
for _, c := range cl {
|
||||||
results = append(results, &res.Result{
|
results = append(results, &art.Result{
|
||||||
Target: c,
|
Target: c,
|
||||||
Error: attachedErr,
|
Error: attachedErr,
|
||||||
})
|
})
|
||||||
@ -203,10 +203,10 @@ func (p *processor) Process(artifacts []*res.Candidate) ([]*res.Result, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type cHash map[string]*res.Candidate
|
type cHash map[string]*art.Candidate
|
||||||
|
|
||||||
func (ch cHash) toList() []*res.Candidate {
|
func (ch cHash) toList() []*art.Candidate {
|
||||||
l := make([]*res.Candidate, 0)
|
l := make([]*art.Candidate, 0)
|
||||||
|
|
||||||
for _, v := range ch {
|
for _, v := range ch {
|
||||||
l = append(l, v)
|
l = append(l, v)
|
||||||
|
@ -19,6 +19,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art/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"
|
||||||
@ -26,9 +29,6 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/always"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/always"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/lastx"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/lastx"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/label"
|
|
||||||
"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"
|
||||||
@ -38,7 +38,7 @@ import (
|
|||||||
type ProcessorTestSuite struct {
|
type ProcessorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*res.Candidate
|
all []*art.Candidate
|
||||||
|
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ func TestProcessor(t *testing.T) {
|
|||||||
|
|
||||||
// SetupSuite ...
|
// SetupSuite ...
|
||||||
func (suite *ProcessorTestSuite) SetupSuite() {
|
func (suite *ProcessorTestSuite) SetupSuite() {
|
||||||
suite.all = []*res.Candidate{
|
suite.all = []*art.Candidate{
|
||||||
{
|
{
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
Repository: "harbor",
|
Repository: "harbor",
|
||||||
@ -90,7 +90,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: []res.Selector{
|
Selectors: []art.Selector{
|
||||||
doublestar.New(doublestar.Matches, "*dev*"),
|
doublestar.New(doublestar.Matches, "*dev*"),
|
||||||
label.New(label.With, "L1,L2"),
|
label.New(label.With, "L1,L2"),
|
||||||
},
|
},
|
||||||
@ -101,7 +101,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: []res.Selector{
|
Selectors: []art.Selector{
|
||||||
label.New(label.With, "L3"),
|
label.New(label.With, "L3"),
|
||||||
},
|
},
|
||||||
Performer: perf,
|
Performer: perf,
|
||||||
@ -131,7 +131,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: []res.Selector{
|
Selectors: []art.Selector{
|
||||||
doublestar.New(doublestar.Matches, "latest"),
|
doublestar.New(doublestar.Matches, "latest"),
|
||||||
label.New(label.With, ""),
|
label.New(label.With, ""),
|
||||||
},
|
},
|
||||||
@ -163,16 +163,16 @@ func (suite *ProcessorTestSuite) TestProcess2() {
|
|||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *res.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRepository ...
|
// DeleteRepository ...
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *res.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package alg
|
package alg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Processor processing the whole policy targeting a repository.
|
// Processor processing the whole policy targeting a repository.
|
||||||
@ -27,12 +27,12 @@ type Processor interface {
|
|||||||
// Process the artifact candidates
|
// Process the artifact candidates
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// artifacts []*res.Candidate : process the retention candidates
|
// artifacts []*art.Candidate : process the retention candidates
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// []*res.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 []*res.Candidate) ([]*res.Result, error)
|
Process(artifacts []*art.Candidate) ([]*art.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 []res.Selector
|
Selectors []art.Selector
|
||||||
|
|
||||||
// Performer for the rule evaluator
|
// Performer for the rule evaluator
|
||||||
Performer action.Performer
|
Performer action.Performer
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
|
|
||||||
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/retention/res/selectors/index"
|
index2 "github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/index"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/alg"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ type Builder interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder news a basic builder
|
// NewBuilder news a basic builder
|
||||||
func NewBuilder(all []*res.Candidate) Builder {
|
func NewBuilder(all []*art.Candidate) Builder {
|
||||||
return &basicBuilder{
|
return &basicBuilder{
|
||||||
allCandidates: all,
|
allCandidates: all,
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func NewBuilder(all []*res.Candidate) Builder {
|
|||||||
|
|
||||||
// basicBuilder is default implementation of Builder interface
|
// basicBuilder is default implementation of Builder interface
|
||||||
type basicBuilder struct {
|
type basicBuilder struct {
|
||||||
allCandidates []*res.Candidate
|
allCandidates []*art.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([]res.Selector, 0)
|
sl := make([]art.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 {
|
||||||
|
@ -22,7 +22,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/retention/res/selectors/index"
|
"github.com/goharbor/harbor/src/pkg/art/selectors/index"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
"github.com/goharbor/harbor/src/pkg/retention/dep"
|
||||||
|
|
||||||
@ -30,9 +30,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/retention/res/selectors/label"
|
"github.com/goharbor/harbor/src/pkg/art/selectors/label"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res/selectors/doublestar"
|
"github.com/goharbor/harbor/src/pkg/art/selectors/doublestar"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule/latestps"
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/lwp"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -55,7 +55,7 @@ import (
|
|||||||
type TestBuilderSuite struct {
|
type TestBuilderSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
all []*res.Candidate
|
all []*art.Candidate
|
||||||
oldClient dep.Client
|
oldClient dep.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,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() {
|
||||||
suite.all = []*res.Candidate{
|
suite.all = []*art.Candidate{
|
||||||
{
|
{
|
||||||
NamespaceID: 1,
|
NamespaceID: 1,
|
||||||
Namespace: "library",
|
Namespace: "library",
|
||||||
@ -163,21 +163,21 @@ func (suite *TestBuilderSuite) TestBuild() {
|
|||||||
|
|
||||||
type fakeRetentionClient struct{}
|
type fakeRetentionClient struct{}
|
||||||
|
|
||||||
func (frc *fakeRetentionClient) DeleteRepository(repo *res.Repository) error {
|
func (frc *fakeRetentionClient) DeleteRepository(repo *art.Repository) error {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCandidates ...
|
// GetCandidates ...
|
||||||
func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Candidate, error) {
|
func (frc *fakeRetentionClient) GetCandidates(repo *art.Repository) ([]*art.Candidate, error) {
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete ...
|
// Delete ...
|
||||||
func (frc *fakeRetentionClient) Delete(candidate *res.Candidate) error {
|
func (frc *fakeRetentionClient) Delete(candidate *art.Candidate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubmitTask ...
|
// SubmitTask ...
|
||||||
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *res.Repository, meta *lwp.Metadata) (string, error) {
|
func (frc *fakeRetentionClient) SubmitTask(taskID int64, repository *art.Repository, meta *lwp.Metadata) (string, error) {
|
||||||
return "", errors.New("not implemented")
|
return "", errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package always
|
package always
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -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 []*res.Candidate) ([]*res.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ package always
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -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 := []*res.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*art.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*res.Candidate) (result []*res.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) (result []*art.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 {
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"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"
|
||||||
@ -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 := []*res.Candidate{
|
data := []*art.Candidate{
|
||||||
{PulledTime: daysAgo(now, 1)},
|
{PulledTime: daysAgo(now, 1)},
|
||||||
{PulledTime: daysAgo(now, 2)},
|
{PulledTime: daysAgo(now, 2)},
|
||||||
{PulledTime: daysAgo(now, 3)},
|
{PulledTime: daysAgo(now, 3)},
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*res.Candidate) (result []*res.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) (result []*art.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 {
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"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"
|
||||||
@ -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 := []*res.Candidate{
|
data := []*art.Candidate{
|
||||||
{PushedTime: daysAgo(now, 1)},
|
{PushedTime: daysAgo(now, 1)},
|
||||||
{PushedTime: daysAgo(now, 2)},
|
{PushedTime: daysAgo(now, 2)},
|
||||||
{PushedTime: daysAgo(now, 3)},
|
{PushedTime: daysAgo(now, 3)},
|
||||||
|
@ -14,19 +14,19 @@
|
|||||||
|
|
||||||
package rule
|
package rule
|
||||||
|
|
||||||
import "github.com/goharbor/harbor/src/pkg/retention/res"
|
import "github.com/goharbor/harbor/src/pkg/art"
|
||||||
|
|
||||||
// Evaluator defines method of executing rule
|
// Evaluator defines method of executing rule
|
||||||
type Evaluator interface {
|
type Evaluator interface {
|
||||||
// Filter the inputs and return the filtered outputs
|
// Filter the inputs and return the filtered outputs
|
||||||
//
|
//
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// artifacts []*res.Candidate : candidates for processing
|
// artifacts []*art.Candidate : candidates for processing
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// []*res.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 []*res.Candidate) ([]*res.Candidate, error)
|
Process(artifacts []*art.Candidate) ([]*art.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
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -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 := []*res.Candidate{{
|
candidates := []*art.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 []*res.Candidate) ([]*res.Candidate, error) {
|
func (e *fakeEvaluator) Process(artifacts []*art.Candidate) ([]*art.Candidate, error) {
|
||||||
return artifacts, nil
|
return artifacts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -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 []*res.Candidate) (retain []*res.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) (retain []*art.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) {
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -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 := []*res.Candidate{
|
data := []*art.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()},
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -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 []*res.Candidate) ([]*res.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.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 *res.Candidate) int64 {
|
func activeTime(c *art.Candidate) int64 {
|
||||||
if c.PulledTime > c.PushedTime {
|
if c.PulledTime > c.PushedTime {
|
||||||
return c.PulledTime
|
return c.PulledTime
|
||||||
}
|
}
|
||||||
|
@ -22,18 +22,18 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EvaluatorTestSuite struct {
|
type EvaluatorTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
artifacts []*res.Candidate
|
artifacts []*art.Candidate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) SetupSuite() {
|
func (e *EvaluatorTestSuite) SetupSuite() {
|
||||||
e.artifacts = []*res.Candidate{
|
e.artifacts = []*art.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},
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -41,7 +41,7 @@ type evaluator struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *evaluator) Process(artifacts []*res.Candidate) ([]*res.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.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
|
||||||
})
|
})
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -52,7 +52,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*res.Candidate{{PulledTime: 0}, {PulledTime: 1}, {PulledTime: 2}, {PulledTime: 3}, {PulledTime: 4}}
|
data := []*art.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]
|
||||||
})
|
})
|
||||||
|
@ -21,9 +21,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -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 []*res.Candidate) ([]*res.Candidate, error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) ([]*art.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
|
||||||
|
@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (e *EvaluatorTestSuite) TestNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *EvaluatorTestSuite) TestProcess() {
|
func (e *EvaluatorTestSuite) TestProcess() {
|
||||||
data := []*res.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}, {PushedTime: 4}}
|
data := []*art.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,9 +15,9 @@
|
|||||||
package nothing
|
package nothing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"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"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -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 []*res.Candidate) (processed []*res.Candidate, err error) {
|
func (e *evaluator) Process(artifacts []*art.Candidate) (processed []*art.Candidate, err error) {
|
||||||
return processed, err
|
return processed, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ package nothing
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/pkg/art"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
"github.com/goharbor/harbor/src/pkg/retention/policy/rule"
|
||||||
"github.com/goharbor/harbor/src/pkg/retention/res"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -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 := []*res.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
input := []*art.Candidate{{PushedTime: 0}, {PushedTime: 1}, {PushedTime: 2}, {PushedTime: 3}}
|
||||||
|
|
||||||
result, err := sut.Process(input)
|
result, err := sut.Process(input)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user