mirror of
https://github.com/project-zot/zot.git
synced 2024-12-30 22:34:13 -05:00
fix(metadb): set LastUpdated field also for indexes (#2088)
Signed-off-by: Andreea-Lupu <andreealupu1470@yahoo.com>
This commit is contained in:
parent
3c8da6e6fc
commit
e59d8da454
3 changed files with 86 additions and 2 deletions
|
@ -233,13 +233,24 @@ func AddImageMetaToRepoMeta(repoMeta *proto_go.RepoMeta, repoBlobs *proto_go.Rep
|
||||||
}
|
}
|
||||||
case ispec.MediaTypeImageIndex:
|
case ispec.MediaTypeImageIndex:
|
||||||
subBlobs := []string{}
|
subBlobs := []string{}
|
||||||
|
lastUpdated := time.Time{}
|
||||||
|
|
||||||
for _, manifest := range imageMeta.Index.Manifests {
|
for _, manifest := range imageMeta.Index.Manifests {
|
||||||
subBlobs = append(subBlobs, manifest.Digest.String())
|
subBlobs = append(subBlobs, manifest.Digest.String())
|
||||||
|
|
||||||
|
blobInfo := repoBlobs.Blobs[manifest.Digest.String()]
|
||||||
|
|
||||||
|
if blobInfo != nil && blobInfo.LastUpdated != nil {
|
||||||
|
if lastUpdated.Before(blobInfo.LastUpdated.AsTime()) {
|
||||||
|
lastUpdated = blobInfo.LastUpdated.AsTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repoBlobs.Blobs[imageMeta.Digest.String()] = &proto_go.BlobInfo{
|
repoBlobs.Blobs[imageMeta.Digest.String()] = &proto_go.BlobInfo{
|
||||||
Size: imageMeta.Size,
|
Size: imageMeta.Size,
|
||||||
SubBlobs: subBlobs,
|
SubBlobs: subBlobs,
|
||||||
|
LastUpdated: mConvert.GetProtoTime(&lastUpdated),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package convert_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
@ -70,3 +71,31 @@ func TestConvertErrors(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetProtoEarlierUpdatedImage(t *testing.T) {
|
||||||
|
Convey("GetProtoEarlierUpdatedImage with nil params", t, func() {
|
||||||
|
// repoLastImage is nil
|
||||||
|
lastImage := gen.RepoLastUpdatedImage{}
|
||||||
|
|
||||||
|
repoLastUpdatedImage := convert.GetProtoEarlierUpdatedImage(nil, &lastImage)
|
||||||
|
So(repoLastUpdatedImage, ShouldNotBeNil)
|
||||||
|
So(repoLastUpdatedImage.LastUpdated, ShouldBeNil)
|
||||||
|
|
||||||
|
// lastImage is nil
|
||||||
|
repoLastImage := gen.RepoLastUpdatedImage{}
|
||||||
|
|
||||||
|
repoLastUpdatedImage = convert.GetProtoEarlierUpdatedImage(&repoLastImage, nil)
|
||||||
|
So(repoLastUpdatedImage, ShouldNotBeNil)
|
||||||
|
So(repoLastUpdatedImage.LastUpdated, ShouldBeNil)
|
||||||
|
|
||||||
|
// lastImage.LastUpdated is not nil, but repoLastImage.LastUpdated is nil
|
||||||
|
lastUpdated := time.Time{}
|
||||||
|
lastImage = gen.RepoLastUpdatedImage{
|
||||||
|
LastUpdated: convert.GetProtoTime(&lastUpdated),
|
||||||
|
}
|
||||||
|
|
||||||
|
repoLastUpdatedImage = convert.GetProtoEarlierUpdatedImage(&repoLastImage, &lastImage)
|
||||||
|
So(repoLastUpdatedImage, ShouldNotBeNil)
|
||||||
|
So(repoLastUpdatedImage.LastUpdated, ShouldNotBeNil)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -685,6 +685,50 @@ func RunMetaDBTests(t *testing.T, metaDB mTypes.MetaDB, preparationFuncs ...func
|
||||||
err = metaDB.SetRepoReference(ctx, "", "tag", imgData1)
|
err = metaDB.SetRepoReference(ctx, "", "tag", imgData1)
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Check last updated for indexes", func() {
|
||||||
|
config1 := GetDefaultConfig()
|
||||||
|
config1.Created = DateRef(2009, 2, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
config2 := GetDefaultConfig()
|
||||||
|
config2.Created = DateRef(2011, 2, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
config3 := GetDefaultConfig()
|
||||||
|
config3.Created = DateRef(2011, 3, 1, 12, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
|
image1 := CreateMultiarchWith().Images([]Image{
|
||||||
|
CreateImageWith().RandomLayers(1, 10).ImageConfig(config1).Build(),
|
||||||
|
}).Build()
|
||||||
|
image2 := CreateMultiarchWith().Images([]Image{
|
||||||
|
CreateImageWith().RandomLayers(1, 10).ImageConfig(config2).Build(),
|
||||||
|
CreateImageWith().RandomLayers(1, 10).ImageConfig(config3).Build(),
|
||||||
|
}).Build()
|
||||||
|
|
||||||
|
_, err := metaDB.GetRepoMeta(ctx, repo1)
|
||||||
|
So(err, ShouldNotBeNil)
|
||||||
|
|
||||||
|
for i := range image1.Images {
|
||||||
|
err := metaDB.SetRepoReference(ctx, repo1, image1.Images[i].DigestStr(),
|
||||||
|
image1.Images[i].AsImageMeta())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = metaDB.SetRepoReference(ctx, repo1, tag1, image1.AsImageMeta())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
for i := range image2.Images {
|
||||||
|
err := metaDB.SetRepoReference(ctx, repo1, image2.Images[i].DigestStr(),
|
||||||
|
image2.Images[i].AsImageMeta())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = metaDB.SetRepoReference(ctx, repo1, tag2, image2.AsImageMeta())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
repoMeta, err := metaDB.GetRepoMeta(ctx, repo1)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(*repoMeta.LastUpdatedImage.LastUpdated, ShouldEqual, time.Date(2011, 3, 1, 12, 0, 0, 0, time.UTC))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Test RemoveRepoReference", func() {
|
Convey("Test RemoveRepoReference", func() {
|
||||||
|
|
Loading…
Reference in a new issue