From d088372d98fea4cf7ef9a233cdbb507d1da249bf Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 28 Jan 2026 09:19:27 +0100 Subject: [PATCH] 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 cb011623c84 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 --- .../kuberuntime/kuberuntime_image_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_image_test.go b/pkg/kubelet/kuberuntime/kuberuntime_image_test.go index be7911cb83f..4e0221a09f9 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_image_test.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_image_test.go @@ -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)