Fix sync extension logging (#2537)

* fix: nil pointer dereference on localimagestore

fixes https://github.com/project-zot/zot/issues/2527

Signed-off-by: Anders Bennedsgaard <abbennedsgaard@gmail.com>

* fix: no logging from sync extension imagestore

Signed-off-by: Anders Bennedsgaard <abbennedsgaard@gmail.com>

* feat: create local imagestore not found error

Signed-off-by: Anders Bennedsgaard <abbennedsgaard@gmail.com>

* fix: add test

Signed-off-by: Anders Bennedsgaard <abbennedsgaard@gmail.com>

---------

Signed-off-by: Anders Bennedsgaard <abbennedsgaard@gmail.com>
This commit is contained in:
Anders Bennedsgaard
2024-07-15 19:30:43 +02:00
committed by GitHub
parent e5eacaa082
commit 8262c46ad7
5 changed files with 22 additions and 9 deletions
+6 -6
View File
@@ -92,7 +92,7 @@ func (registry *DestinationRegistry) GetImageReference(repo, reference string) (
func (registry *DestinationRegistry) CommitImage(imageReference types.ImageReference, repo, reference string) error {
imageStore := registry.storeController.GetImageStore(repo)
tempImageStore := getImageStoreFromImageReference(imageReference, repo, reference)
tempImageStore := getImageStoreFromImageReference(imageReference, repo, reference, registry.log)
defer os.RemoveAll(tempImageStore.RootDir())
@@ -282,11 +282,11 @@ func (registry *DestinationRegistry) copyBlob(repo string, blobDigest digest.Dig
}
// use only with local imageReferences.
func getImageStoreFromImageReference(imageReference types.ImageReference, repo, reference string,
func getImageStoreFromImageReference(imageReference types.ImageReference, repo, reference string, log log.Logger,
) storageTypes.ImageStore {
tmpRootDir := getTempRootDirFromImageReference(imageReference, repo, reference)
return getImageStore(tmpRootDir)
return getImageStore(tmpRootDir, log)
}
func getTempRootDirFromImageReference(imageReference types.ImageReference, repo, reference string) string {
@@ -301,8 +301,8 @@ func getTempRootDirFromImageReference(imageReference types.ImageReference, repo,
return tmpRootDir
}
func getImageStore(rootDir string) storageTypes.ImageStore {
metrics := monitoring.NewMetricsServer(false, log.Logger{})
func getImageStore(rootDir string, log log.Logger) storageTypes.ImageStore {
metrics := monitoring.NewMetricsServer(false, log)
return local.NewImageStore(rootDir, false, false, log.Logger{}, metrics, nil, nil)
return local.NewImageStore(rootDir, false, false, log, metrics, nil, nil)
}
+4
View File
@@ -12,6 +12,7 @@ import (
"github.com/containers/image/v5/types"
"github.com/gofrs/uuid"
zerr "zotregistry.dev/zot/errors"
"zotregistry.dev/zot/pkg/extensions/sync/constants"
"zotregistry.dev/zot/pkg/storage"
storageConstants "zotregistry.dev/zot/pkg/storage/constants"
@@ -40,6 +41,9 @@ func (oci OciLayoutStorageImpl) GetContext() *types.SystemContext {
func (oci OciLayoutStorageImpl) GetImageReference(repo string, reference string) (types.ImageReference, error) {
localImageStore := oci.storeController.GetImageStore(repo)
if localImageStore == nil {
return nil, zerr.ErrLocalImgStoreNotFound
}
tempSyncPath := path.Join(localImageStore.RootDir(), repo, constants.SyncBlobUploadDir)
// create session folder
+1 -1
View File
@@ -83,7 +83,7 @@ func New(
service.destination = NewDestinationRegistry(
storeController,
storage.StoreController{
DefaultStore: getImageStore(tmpDir),
DefaultStore: getImageStore(tmpDir, log),
},
metadb,
log,
+10 -2
View File
@@ -83,6 +83,14 @@ func TestInjectSyncUtils(t *testing.T) {
})
}
func TestNilDefaultStore(t *testing.T) {
Convey("Nil default store", t, func() {
ols := NewOciLayoutStorage(storage.StoreController{})
_, err := ols.GetImageReference(testImage, testImageTag)
So(err, ShouldEqual, zerr.ErrLocalImgStoreNotFound)
})
}
func TestSyncInternal(t *testing.T) {
Convey("Verify parseRepositoryReference func", t, func() {
repositoryReference := fmt.Sprintf("%s/%s", host, testImage)
@@ -214,7 +222,7 @@ func TestDestinationRegistry(t *testing.T) {
So(err, ShouldBeNil)
So(imageReference, ShouldNotBeNil)
imgStore := getImageStoreFromImageReference(imageReference, repoName, "1.0")
imgStore := getImageStoreFromImageReference(imageReference, repoName, "1.0", log)
// create a blob/layer
upload, err := imgStore.NewBlobUpload(repoName)
@@ -393,7 +401,7 @@ func TestDestinationRegistry(t *testing.T) {
So(err, ShouldBeNil)
So(imageReference, ShouldNotBeNil)
imgStore := getImageStoreFromImageReference(imageReference, repoName, "2.0")
imgStore := getImageStoreFromImageReference(imageReference, repoName, "2.0", log)
// upload image