Merge pull request #8867 from bitsf/tag_retention_same_digest_tag

Tag retention same digest tag
This commit is contained in:
Daniel Jiang 2019-08-29 12:26:44 +08:00 committed by GitHub
commit 9fa70db866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 1 deletions

View File

@ -109,6 +109,7 @@ func (bc *basicClient) GetCandidates(repository *res.Repository) ([]*res.Candida
Namespace: repository.Namespace,
Repository: repository.Name,
Tag: image.Name,
Digest: image.Digest,
Labels: labels,
CreationTime: image.Created.Unix(),
PulledTime: image.PullTime.Unix(),

View File

@ -119,6 +119,7 @@ func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Cand
Repository: "harbor",
Kind: "image",
Tag: "latest",
Digest: "latest",
PushedTime: time.Now().Unix() - 11,
PulledTime: time.Now().Unix() - 2,
CreationTime: time.Now().Unix() - 10,
@ -129,6 +130,7 @@ func (frc *fakeRetentionClient) GetCandidates(repo *res.Repository) ([]*res.Cand
Repository: "harbor",
Kind: "image",
Tag: "dev",
Digest: "dev",
PushedTime: time.Now().Unix() - 10,
PulledTime: time.Now().Unix() - 3,
CreationTime: time.Now().Unix() - 20,

View File

@ -47,6 +47,7 @@ func (suite *TestPerformerSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "latest",
Digest: "latest",
PushedTime: time.Now().Unix(),
Labels: []string{"L1", "L2"},
},
@ -55,6 +56,7 @@ func (suite *TestPerformerSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "dev",
Digest: "dev",
PushedTime: time.Now().Unix(),
Labels: []string{"L3"},
},
@ -81,6 +83,7 @@ func (suite *TestPerformerSuite) TestPerform() {
Repository: "harbor",
Kind: "image",
Tag: "latest",
Digest: "latest",
PushedTime: time.Now().Unix(),
Labels: []string{"L1", "L2"},
},

View File

@ -56,6 +56,7 @@ func (suite *ProcessorTestSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "latest",
Digest: "latest",
PushedTime: time.Now().Unix(),
Labels: []string{"L1", "L2"},
},
@ -64,6 +65,7 @@ func (suite *ProcessorTestSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "dev",
Digest: "dev",
PushedTime: time.Now().Unix(),
Labels: []string{"L3"},
},

View File

@ -73,6 +73,7 @@ func (suite *TestBuilderSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "latest",
Digest: "latest",
PushedTime: time.Now().Unix(),
Labels: []string{"L1", "L2"},
},
@ -82,6 +83,7 @@ func (suite *TestBuilderSuite) SetupSuite() {
Repository: "harbor",
Kind: "image",
Tag: "dev",
Digest: "dev",
PushedTime: time.Now().Unix(),
Labels: []string{"L3"},
},

View File

@ -18,6 +18,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"github.com/goharbor/harbor/src/common/utils/log"
"github.com/pkg/errors"
)
@ -72,6 +73,8 @@ type Candidate struct {
Kind string
// Tag info
Tag string
// Digest
Digest string
// Pushed time in seconds
PushedTime int64
// Pulled time in seconds
@ -84,7 +87,10 @@ type Candidate struct {
// Hash code based on the candidate info for differentiation
func (c *Candidate) Hash() string {
raw := fmt.Sprintf("%s:%s/%s:%s", c.Kind, c.Namespace, c.Repository, c.Tag)
if c.Digest == "" {
log.Errorf("Lack Digest of Candidate for %s/%s:%s", c.Namespace, c.Repository, c.Tag)
}
raw := fmt.Sprintf("%s:%s/%s:%s", c.Kind, c.Namespace, c.Repository, c.Digest)
return base64.StdEncoding.EncodeToString([]byte(raw))
}