diff --git a/internal/cri/server/images/image_status_test.go b/internal/cri/server/images/image_status_test.go index e4405be78..a0db783cc 100644 --- a/internal/cri/server/images/image_status_test.go +++ b/internal/cri/server/images/image_status_test.go @@ -26,7 +26,6 @@ import ( runtime "k8s.io/cri-api/pkg/apis/runtime/v1" imagestore "github.com/containerd/containerd/v2/internal/cri/store/image" - "github.com/containerd/containerd/v2/internal/cri/util" ) func TestImageStatus(t *testing.T) { @@ -74,22 +73,6 @@ func TestImageStatus(t *testing.T) { assert.Equal(t, expected, resp.GetImage()) } -func TestParseImageReferences(t *testing.T) { - refs := []string{ - "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", - "gcr.io/library/busybox:1.2", - "sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", - "arbitrary-ref", - } - expectedTags := []string{ - "gcr.io/library/busybox:1.2", - } - expectedDigests := []string{"gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582"} - tags, digests := util.ParseImageReferences(refs) - assert.Equal(t, expectedTags, tags) - assert.Equal(t, expectedDigests, digests) -} - // TestGetUserFromImage tests the logic of getting image uid or user name of image user. func TestGetUserFromImage(t *testing.T) { newI64 := func(i int64) *int64 { return &i } diff --git a/internal/cri/server/podsandbox/helpers.go b/internal/cri/server/podsandbox/helpers.go index 8354f6c8c..29c6accce 100644 --- a/internal/cri/server/podsandbox/helpers.go +++ b/internal/cri/server/podsandbox/helpers.go @@ -110,24 +110,6 @@ func buildLabels(configLabels, imageConfigLabels map[string]string, containerTyp return labels } -// parseImageReferences parses a list of arbitrary image references and returns -// the repotags and repodigests -func parseImageReferences(refs []string) ([]string, []string) { - var tags, digests []string - for _, ref := range refs { - parsed, err := docker.ParseAnyReference(ref) - if err != nil { - continue - } - if _, ok := parsed.(docker.Canonical); ok { - digests = append(digests, parsed.String()) - } else if _, ok := parsed.(docker.Tagged); ok { - tags = append(tags, parsed.String()) - } - } - return tags, digests -} - // getPassthroughAnnotations filters requested pod annotations by comparing // against permitted annotations for the given runtime. func getPassthroughAnnotations(podAnnotations map[string]string, diff --git a/internal/cri/server/podsandbox/helpers_test.go b/internal/cri/server/podsandbox/helpers_test.go index af4112169..f78754503 100644 --- a/internal/cri/server/podsandbox/helpers_test.go +++ b/internal/cri/server/podsandbox/helpers_test.go @@ -99,22 +99,6 @@ func TestBuildLabels(t *testing.T) { assert.Equal(t, "b", configLabels["a"], "change in new labels should not affect original label") } -func TestParseImageReferences(t *testing.T) { - refs := []string{ - "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", - "gcr.io/library/busybox:1.2", - "sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", - "arbitrary-ref", - } - expectedTags := []string{ - "gcr.io/library/busybox:1.2", - } - expectedDigests := []string{"gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582"} - tags, digests := parseImageReferences(refs) - assert.Equal(t, expectedTags, tags) - assert.Equal(t, expectedDigests, digests) -} - func TestEnvDeduplication(t *testing.T) { for _, test := range []struct { desc string diff --git a/internal/cri/util/references_test.go b/internal/cri/util/references_test.go new file mode 100644 index 000000000..0f12bee13 --- /dev/null +++ b/internal/cri/util/references_test.go @@ -0,0 +1,39 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package util + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestParseImageReferences(t *testing.T) { + refs := []string{ + "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", + "gcr.io/library/busybox:1.2", + "sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582", + "arbitrary-ref", + } + expectedTags := []string{ + "gcr.io/library/busybox:1.2", + } + expectedDigests := []string{"gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582"} + tags, digests := ParseImageReferences(refs) + assert.Equal(t, expectedTags, tags) + assert.Equal(t, expectedDigests, digests) +}