From e44335800ed9e0a37a6ab93a4b5c8601aaa0cfc2 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Thu, 26 May 2022 12:52:36 -0700 Subject: [PATCH] CRI: Move reference sorting to reference package Signed-off-by: Maksym Pavlenko --- pkg/cri/store/image/image.go | 3 ++- {pkg/cri/store/image => reference}/sort.go | 6 +++--- {pkg/cri/store/image => reference}/sort_test.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) rename {pkg/cri/store/image => reference}/sort.go (92%) rename {pkg/cri/store/image => reference}/sort_test.go (97%) diff --git a/pkg/cri/store/image/image.go b/pkg/cri/store/image/image.go index 5cd7bb2ed..6b36ea1b1 100644 --- a/pkg/cri/store/image/image.go +++ b/pkg/cri/store/image/image.go @@ -24,6 +24,7 @@ import ( "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/pkg/cri/util" + "github.com/containerd/containerd/reference" imagedigest "github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest/digestset" @@ -205,7 +206,7 @@ func (s *store) add(img Image) error { return nil } // Or else, merge and sort the references. - i.References = sortReferences(util.MergeStringSlices(i.References, img.References)) + i.References = reference.Sort(util.MergeStringSlices(i.References, img.References)) s.images[img.ID] = i return nil } diff --git a/pkg/cri/store/image/sort.go b/reference/sort.go similarity index 92% rename from pkg/cri/store/image/sort.go rename to reference/sort.go index 403d7d220..38c3d0672 100644 --- a/pkg/cri/store/image/sort.go +++ b/reference/sort.go @@ -14,7 +14,7 @@ limitations under the License. */ -package image +package reference import ( "sort" @@ -22,8 +22,8 @@ import ( "github.com/containerd/containerd/reference/docker" ) -// sortReferences sorts references by refRank then string comparison -func sortReferences(references []string) []string { +// Sort sorts references by refRank then string comparison +func Sort(references []string) []string { var prefs []docker.Reference var bad []string diff --git a/pkg/cri/store/image/sort_test.go b/reference/sort_test.go similarity index 97% rename from pkg/cri/store/image/sort_test.go rename to reference/sort_test.go index 00731ec53..f1e68bb95 100644 --- a/pkg/cri/store/image/sort_test.go +++ b/reference/sort_test.go @@ -14,7 +14,7 @@ limitations under the License. */ -package image +package reference import ( "io" @@ -68,7 +68,7 @@ func TestReferenceSorting(t *testing.T) { expected: []string{r2("name-1", "tag"), r2("name-2", "tag"), r2("name-3", "tag")}, }, } { - sorted := sortReferences(tc.unsorted) + sorted := Sort(tc.unsorted) if len(sorted) != len(tc.expected) { t.Errorf("[%d]: Mismatched sized, got %d, expected %d", i, len(sorted), len(tc.expected)) continue