From c8506822085bae264baaa681f7cf23fcd4ccecfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 16:57:17 +0100 Subject: [PATCH 1/4] Remove clearly dead code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Should not change behavior. Signed-off-by: Miloslav Trmač --- libpod/storage.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libpod/storage.go b/libpod/storage.go index 52d5e1e8f7..e8bc8204bc 100644 --- a/libpod/storage.go +++ b/libpod/storage.go @@ -97,10 +97,7 @@ func (r *storageService) CreateContainerStorage(ctx context.Context, systemConte return ContainerInfo{}, err } - // Update the image name and ID. - if imageName == "" && len(img.Names) > 0 { - imageName = img.Names[0] - } + // Update the image ID. imageID = img.ID } From e9587f5e3710818cb0dbf54fd452a86adc45fd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 18:24:28 +0100 Subject: [PATCH 2/4] Don't re-assign imageID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By construction in callers, imageID is always a full ID, so this assignment is always a no-op. Signed-off-by: Miloslav Trmač --- libpod/storage.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/libpod/storage.go b/libpod/storage.go index e8bc8204bc..e602182514 100644 --- a/libpod/storage.go +++ b/libpod/storage.go @@ -80,10 +80,6 @@ func (r *storageService) CreateContainerStorage(ctx context.Context, systemConte if err != nil { return ContainerInfo{}, err } - _, img, err := istorage.ResolveReference(ref) - if err != nil { - return ContainerInfo{}, err - } // Pull out a copy of the image's configuration. image, err := ref.NewImage(ctx, systemContext) if err != nil { @@ -96,9 +92,6 @@ func (r *storageService) CreateContainerStorage(ctx context.Context, systemConte if err != nil { return ContainerInfo{}, err } - - // Update the image ID. - imageID = img.ID } // Build metadata to store with the container. From ff80e40adfa7e103bb13fd9e4a5703396cffed43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 18:26:38 +0100 Subject: [PATCH 3/4] Use NewStoreReference instead of ParseStoreReference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By construction, imageID is a full image ID, so avoid heuristics by using a more specific API. Signed-off-by: Miloslav Trmač --- libpod/storage.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libpod/storage.go b/libpod/storage.go index e602182514..33fd95357b 100644 --- a/libpod/storage.go +++ b/libpod/storage.go @@ -71,12 +71,11 @@ func (metadata *RuntimeContainerMetadata) SetMountLabel(mountLabel string) { func (r *storageService) CreateContainerStorage(ctx context.Context, systemContext *types.SystemContext, imageName, imageID, containerName, containerID string, options storage.ContainerOptions) (_ ContainerInfo, retErr error) { var imageConfig *v1.Image if imageName != "" { - var ref types.ImageReference if containerName == "" { return ContainerInfo{}, define.ErrEmptyID } // Check if we have the specified image. - ref, err := istorage.Transport.ParseStoreReference(r.store, imageID) + ref, err := istorage.Transport.NewStoreReference(r.store, nil, imageID) if err != nil { return ContainerInfo{}, err } From ae9b63fbf0c888a6f8f64f5ce1ec0faf35c70c74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 20 Nov 2023 19:04:16 +0100 Subject: [PATCH 4/4] Check for imageID, not imageName MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are only using imageID on that branch, so it is more consistent. Should not change behavior; in callers, either both are set or neither. [NO NEW TESTS NEEDED] Signed-off-by: Miloslav Trmač --- libpod/storage.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libpod/storage.go b/libpod/storage.go index 33fd95357b..3f667c3199 100644 --- a/libpod/storage.go +++ b/libpod/storage.go @@ -66,11 +66,12 @@ func (metadata *RuntimeContainerMetadata) SetMountLabel(mountLabel string) { metadata.MountLabel = mountLabel } -// CreateContainerStorage creates the storage end of things. We already have the container spec created +// CreateContainerStorage creates the storage end of things. We already have the container spec created. +// imageID and imageName must both be either empty or non-empty. // TO-DO We should be passing in an Image object in the future. func (r *storageService) CreateContainerStorage(ctx context.Context, systemContext *types.SystemContext, imageName, imageID, containerName, containerID string, options storage.ContainerOptions) (_ ContainerInfo, retErr error) { var imageConfig *v1.Image - if imageName != "" { + if imageID != "" { if containerName == "" { return ContainerInfo{}, define.ErrEmptyID }