Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slices.Compact instead of own logic #1681

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions pkg/validate/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"runtime"
"slices"
"sort"
"time"

Expand Down Expand Up @@ -146,7 +147,6 @@ var _ = framework.KubeDescribe("Image Manager", func() {
// Make sure test image does not exist.
removeImageList(c, testDifferentTagDifferentImageList)
ids := pullImageList(c, testDifferentTagDifferentImageList, testImagePodSandbox)
ids = removeDuplicates(ids)
Expect(ids).To(HaveLen(3), "3 image ids should be returned")

defer removeImageList(c, testDifferentTagDifferentImageList)
Expand All @@ -168,7 +168,8 @@ var _ = framework.KubeDescribe("Image Manager", func() {
// Make sure test image does not exist.
removeImageList(c, testDifferentTagSameImageList)
ids := pullImageList(c, testDifferentTagSameImageList, testImagePodSandbox)
ids = removeDuplicates(ids)
slices.Sort(ids)
ids = slices.Compact(ids)
Expect(ids).To(HaveLen(1), "Only 1 image id should be returned")

defer removeImageList(c, testDifferentTagSameImageList)
Expand Down Expand Up @@ -216,8 +217,7 @@ func testPullPublicImage(c internalapi.ImageManagerService, imageName string, po
}

// pullImageList pulls the images listed in the imageList.
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) []string {
ids := []string{}
func pullImageList(c internalapi.ImageManagerService, imageList []string, podConfig *runtimeapi.PodSandboxConfig) (ids []string) {
for _, imageName := range imageList {
ids = append(ids, framework.PullPublicImage(c, imageName, podConfig))
}
Expand All @@ -243,17 +243,3 @@ func removeImage(c internalapi.ImageManagerService, imageName string) {
framework.ExpectNoError(err, "failed to remove image: %v", err)
}
}

// removeDuplicates remove duplicates strings from a list.
func removeDuplicates(ss []string) []string {
encountered := map[string]bool{}
result := []string{}
for _, s := range ss {
if encountered[s] {
continue
}
encountered[s] = true
result = append(result, s)
}
return result
}
Loading