Add test for GetImageRef content-based deduplication

Adds TestGetImageRefReturnsImageIdNotRepoDigest to verify that GetImageRef
returns Image.Id instead of RepoDigests. This ensures content-based
deduplication where the same image pulled from different registries is
treated as identical content rather than separate images.

The test prevents regression of the issue fixed in the revert of cb011623c8
where using RepoDigests[0] caused location-dependent identity
(registry.io/image@sha256:...) instead of content-based identity
(sha256:...), breaking deduplication and creating separate pull records
for identical image content.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
Sascha Grunert 2026-01-28 09:19:27 +01:00
parent f866eed44a
commit d088372d98
No known key found for this signature in database
GPG key ID: 09D97D153EF94D93

View file

@ -136,6 +136,37 @@ func TestGetImageRef(t *testing.T) {
assert.Equal(t, image, imageRef)
}
// TestGetImageRefReturnsImageIdNotRepoDigest verifies that GetImageRef returns
// Image.Id instead of RepoDigests to ensure content-based deduplication.
// This prevents the same image pulled from different registries from being
// treated as different images in pull record lookups.
func TestGetImageRefReturnsImageIdNotRepoDigest(t *testing.T) {
tCtx := ktesting.Init(t)
_, fakeImageService, fakeManager, err := createTestRuntimeManager(tCtx)
require.NoError(t, err)
// Simulate an image with both Id and RepoDigests set
// In a real scenario, the same image content pulled from different registries
// would have the same Id but different RepoDigests
imageID := "sha256:abcd1234"
repoDigest1 := "registry1.io/myimage@sha256:abcd1234"
repoDigest2 := "registry2.io/myimage@sha256:abcd1234"
fakeImageService.Lock()
fakeImageService.Images["myimage"] = &runtimeapi.Image{
Id: imageID,
RepoDigests: []string{repoDigest1, repoDigest2},
RepoTags: []string{"myimage:latest"},
Size: 1000,
}
fakeImageService.Unlock()
// GetImageRef should return the content-based Image.Id, not the location-based RepoDigest
imageRef, err := fakeManager.GetImageRef(tCtx, kubecontainer.ImageSpec{Image: "myimage"})
require.NoError(t, err)
assert.Equal(t, imageID, imageRef, "GetImageRef should return Image.Id for content-based deduplication")
}
func TestImageSize(t *testing.T) {
tCtx := ktesting.Init(t)
_, fakeImageService, fakeManager, err := createTestRuntimeManager(tCtx)