prevent retained tag with same digest deleted by other tag

Signed-off-by: Ziming Zhang <zziming@vmware.com>
Change-Id: I6a69b405b454ca0350677204e06bfa2b24616b33
This commit is contained in:
Ziming Zhang 2019-08-28 17:48:42 +08:00
parent 3f5ecd1f9c
commit 063f2bfee9
3 changed files with 9 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

@ -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

@ -72,6 +72,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 +86,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 == "" {
panic("Lack Digest of Candidate")
}
raw := fmt.Sprintf("%s:%s/%s:%s", c.Kind, c.Namespace, c.Repository, c.Digest)
return base64.StdEncoding.EncodeToString([]byte(raw))
}