CRI: Move reference sorting to reference package

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko 2022-05-26 12:52:36 -07:00
parent b5366f8d7e
commit e44335800e
3 changed files with 7 additions and 6 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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