瀏覽代碼

Merge pull request #39288 from dohse/do-not-order-uid-gid-mappings

Stop sorting uid and gid ranges in id maps
Sebastiaan van Stijn 6 年之前
父節點
當前提交
bd89b3f553
共有 2 個文件被更改,包括 28 次插入3 次删除
  1. 0 3
      pkg/idtools/idtools.go
  2. 28 0
      pkg/idtools/idtools_test.go

+ 0 - 3
pkg/idtools/idtools.go

@@ -4,7 +4,6 @@ import (
 	"bufio"
 	"bufio"
 	"fmt"
 	"fmt"
 	"os"
 	"os"
-	"sort"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 )
 )
@@ -203,8 +202,6 @@ func (i *IdentityMapping) GIDs() []IDMap {
 func createIDMap(subidRanges ranges) []IDMap {
 func createIDMap(subidRanges ranges) []IDMap {
 	idMap := []IDMap{}
 	idMap := []IDMap{}
 
 
-	// sort the ranges by lowest ID first
-	sort.Sort(subidRanges)
 	containerID := 0
 	containerID := 0
 	for _, idrange := range subidRanges {
 	for _, idrange := range subidRanges {
 		idMap = append(idMap, IDMap{
 		idMap = append(idMap, IDMap{

+ 28 - 0
pkg/idtools/idtools_test.go

@@ -0,0 +1,28 @@
+package idtools // import "github.com/docker/docker/pkg/idtools"
+
+import (
+	"testing"
+
+	"gotest.tools/assert"
+)
+
+func TestCreateIDMapOrder(t *testing.T) {
+	subidRanges := ranges{
+		{100000, 1000},
+		{1000, 1},
+	}
+
+	idMap := createIDMap(subidRanges)
+	assert.DeepEqual(t, idMap, []IDMap{
+		{
+			ContainerID: 0,
+			HostID:      100000,
+			Size:        1000,
+		},
+		{
+			ContainerID: 1000,
+			HostID:      1000,
+			Size:        1,
+		},
+	})
+}