Skip to content

Commit

Permalink
fix(metadb): populate image pushTimestamp if it's 0 value
Browse files Browse the repository at this point in the history
in the case of an already existing meta db without pushTimestamp field
its value would be 0 until image is updated, check for zero values and update them
with time.Now() so that retention logic won't remove them.

Signed-off-by: Petu Eusebiu <[email protected]>
  • Loading branch information
eusebiu-constantin-petu-dbk committed Nov 8, 2023
1 parent 7f52f58 commit 56434c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/meta/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ func (bdw *BoltDB) SetRepoReference(ctx context.Context, repo string, reference
PushTimestamp: timestamppb.Now(),
PushedBy: userid,
}
} else if protoRepoMeta.Statistics[imageMeta.Digest.String()].PushTimestamp.AsTime().IsZero() {
protoRepoMeta.Statistics[imageMeta.Digest.String()].PushTimestamp = timestamppb.Now()
}

if _, ok := protoRepoMeta.Signatures[imageMeta.Digest.String()]; !ok {
Expand Down
2 changes: 2 additions & 0 deletions pkg/meta/dynamodb/dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ func (dwr *DynamoDB) SetRepoReference(ctx context.Context, repo string, referenc
PushTimestamp: timestamppb.Now(),
PushedBy: userid,
}
} else if repoMeta.Statistics[imageMeta.Digest.String()].PushTimestamp.AsTime().IsZero() {
repoMeta.Statistics[imageMeta.Digest.String()].PushTimestamp = timestamppb.Now()
}

if _, ok := repoMeta.Signatures[imageMeta.Digest.String()]; !ok {
Expand Down
8 changes: 8 additions & 0 deletions pkg/meta/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@ func RunParseStorageTests(rootDir string, metaDB mTypes.MetaDB) {
So(repoMeta.StarCount, ShouldEqual, 1)
So(time.Now(), ShouldHappenAfter, repoMeta.Statistics[image.DigestStr()].LastPullTimestamp)

// update statistics (simulate that a metaDB has most statistics, but not pushTimestamp)
stats := repoMeta.Statistics[image.DigestStr()]
stats.PushTimestamp = time.Time{}
repoMeta.Statistics[image.DigestStr()] = stats

err = metaDB.SetRepoMeta(repo, repoMeta)
So(err, ShouldBeNil)

err = meta.ParseStorage(metaDB, storeController, log.NewLogger("debug", ""))
So(err, ShouldBeNil)

Expand Down

0 comments on commit 56434c7

Please sign in to comment.