mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 01:27:49 +01:00
add more rule evaluators
Signed-off-by: Steven Zou <szou@vmware.com>
This commit is contained in:
parent
1575d90523
commit
07250469ac
83
src/pkg/retention/policy/rule/latest/evaluator.go
Normal file
83
src/pkg/retention/policy/rule/latest/evaluator.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package latestk
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"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/res"
|
||||
)
|
||||
|
||||
const (
|
||||
// TemplateID of latest active k rule
|
||||
TemplateID = "latestActiveK"
|
||||
// ParameterK ...
|
||||
ParameterK = TemplateID
|
||||
// DefaultK defines the default K
|
||||
DefaultK = 10
|
||||
)
|
||||
|
||||
// evaluator for evaluating latest active k images
|
||||
type evaluator struct {
|
||||
// latest k
|
||||
k int
|
||||
}
|
||||
|
||||
// Process the candidates based on the rule definition
|
||||
func (e *evaluator) Process(artifacts []*res.Candidate) ([]*res.Candidate, error) {
|
||||
// TODO: REPLACE SAMPLE CODE WITH REAL IMPLEMENTATION
|
||||
return artifacts, nil
|
||||
}
|
||||
|
||||
// Specify what action is performed to the candidates processed by this evaluator
|
||||
func (e *evaluator) Action() string {
|
||||
return action.Retain
|
||||
}
|
||||
|
||||
// New a Evaluator
|
||||
func New(params rule.Parameters) rule.Evaluator {
|
||||
if params != nil {
|
||||
if param, ok := params[ParameterK]; ok {
|
||||
if v, ok := param.(int); ok {
|
||||
return &evaluator{
|
||||
k: v,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("default parameter %d used for rule %s", DefaultK, TemplateID)
|
||||
|
||||
return &evaluator{
|
||||
k: DefaultK,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Register itself
|
||||
rule.Register(&rule.IndexMeta{
|
||||
TemplateID: TemplateID,
|
||||
Action: action.Retain,
|
||||
Parameters: []*rule.IndexedParam{
|
||||
{
|
||||
Name: ParameterK,
|
||||
Type: "int",
|
||||
Unit: "count",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}, New)
|
||||
}
|
83
src/pkg/retention/policy/rule/latestpull/evaluator.go
Normal file
83
src/pkg/retention/policy/rule/latestpull/evaluator.go
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright Project Harbor Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package latestk
|
||||
|
||||
import (
|
||||
"github.com/goharbor/harbor/src/common/utils/log"
|
||||
"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/res"
|
||||
)
|
||||
|
||||
const (
|
||||
// TemplateID of latest pulled k rule
|
||||
TemplateID = "latestPulledK"
|
||||
// ParameterK ...
|
||||
ParameterK = TemplateID
|
||||
// DefaultK defines the default K
|
||||
DefaultK = 10
|
||||
)
|
||||
|
||||
// evaluator for evaluating latest pulled k images
|
||||
type evaluator struct {
|
||||
// latest k
|
||||
k int
|
||||
}
|
||||
|
||||
// Process the candidates based on the rule definition
|
||||
func (e *evaluator) Process(artifacts []*res.Candidate) ([]*res.Candidate, error) {
|
||||
// TODO: REPLACE SAMPLE CODE WITH REAL IMPLEMENTATION
|
||||
return artifacts, nil
|
||||
}
|
||||
|
||||
// Specify what action is performed to the candidates processed by this evaluator
|
||||
func (e *evaluator) Action() string {
|
||||
return action.Retain
|
||||
}
|
||||
|
||||
// New a Evaluator
|
||||
func New(params rule.Parameters) rule.Evaluator {
|
||||
if params != nil {
|
||||
if param, ok := params[ParameterK]; ok {
|
||||
if v, ok := param.(int); ok {
|
||||
return &evaluator{
|
||||
k: v,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("default parameter %d used for rule %s", DefaultK, TemplateID)
|
||||
|
||||
return &evaluator{
|
||||
k: DefaultK,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Register itself
|
||||
rule.Register(&rule.IndexMeta{
|
||||
TemplateID: TemplateID,
|
||||
Action: action.Retain,
|
||||
Parameters: []*rule.IndexedParam{
|
||||
{
|
||||
Name: ParameterK,
|
||||
Type: "int",
|
||||
Unit: "count",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}, New)
|
||||
}
|
@ -50,6 +50,10 @@ type Candidate struct {
|
||||
Tag string
|
||||
// Pushed time in seconds
|
||||
PushedTime int64
|
||||
// Pulled time in seconds
|
||||
PulledTime int64
|
||||
// Created time in seconds
|
||||
CreationTime int64
|
||||
// Labels attached with the candidate
|
||||
Labels []string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user