Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8792f99b
Commit
8792f99b
authored
Jun 04, 2018
by
Silvery Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the handling of untagged images
parent
73970a50
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
17 deletions
+57
-17
image_locality.go
pkg/scheduler/algorithm/priorities/image_locality.go
+15
-1
image_locality_test.go
pkg/scheduler/algorithm/priorities/image_locality_test.go
+35
-10
node_info_test.go
pkg/scheduler/cache/node_info_test.go
+7
-6
No files found.
pkg/scheduler/algorithm/priorities/image_locality.go
View file @
8792f99b
...
@@ -18,10 +18,12 @@ package priorities
...
@@ -18,10 +18,12 @@ package priorities
import
(
import
(
"fmt"
"fmt"
"strings"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
schedulercache
"k8s.io/kubernetes/pkg/scheduler/cache"
schedulercache
"k8s.io/kubernetes/pkg/scheduler/cache"
"k8s.io/kubernetes/pkg/util/parsers"
)
)
// This is a reasonable size range of all container images. 90%ile of images on dockerhub drops into this range.
// This is a reasonable size range of all container images. 90%ile of images on dockerhub drops into this range.
...
@@ -74,10 +76,22 @@ func totalImageSize(nodeInfo *schedulercache.NodeInfo, containers []v1.Container
...
@@ -74,10 +76,22 @@ func totalImageSize(nodeInfo *schedulercache.NodeInfo, containers []v1.Container
imageSizes
:=
nodeInfo
.
ImageSizes
()
imageSizes
:=
nodeInfo
.
ImageSizes
()
for
_
,
container
:=
range
containers
{
for
_
,
container
:=
range
containers
{
if
size
,
ok
:=
imageSizes
[
container
.
Image
];
ok
{
if
size
,
ok
:=
imageSizes
[
normalizedImageName
(
container
.
Image
)
];
ok
{
total
+=
size
total
+=
size
}
}
}
}
return
total
return
total
}
}
// normalizedImageName returns the CRI compliant name for a given image.
// TODO: cover the corner cases of missed matches, e.g,
// 1. Using Docker as runtime and docker.io/library/test:tag in pod spec, but only test:tag will present in node status
// 2. Using the implicit registry, i.e., test:tag or library/test:tag in pod spec but only docker.io/library/test:tag
// in node status; note that if users consistently use one registry format, this should not happen.
func
normalizedImageName
(
name
string
)
string
{
if
strings
.
LastIndex
(
name
,
":"
)
<=
strings
.
LastIndex
(
name
,
"/"
)
{
name
=
name
+
":"
+
parsers
.
DefaultImageTag
}
return
name
}
pkg/scheduler/algorithm/priorities/image_locality_test.go
View file @
8792f99b
...
@@ -17,14 +17,17 @@ limitations under the License.
...
@@ -17,14 +17,17 @@ limitations under the License.
package
priorities
package
priorities
import
(
import
(
"crypto/sha256"
"reflect"
"reflect"
"sort"
"sort"
"testing"
"testing"
"encoding/hex"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
schedulercache
"k8s.io/kubernetes/pkg/scheduler/cache"
schedulercache
"k8s.io/kubernetes/pkg/scheduler/cache"
"k8s.io/kubernetes/pkg/util/parsers"
)
)
func
TestImageLocalityPriority
(
t
*
testing
.
T
)
{
func
TestImageLocalityPriority
(
t
*
testing
.
T
)
{
...
@@ -65,7 +68,7 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -65,7 +68,7 @@ func TestImageLocalityPriority(t *testing.T) {
Images
:
[]
v1
.
ContainerImage
{
Images
:
[]
v1
.
ContainerImage
{
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/40
"
,
"gcr.io/40
:"
+
parsers
.
DefaultImageTag
,
"gcr.io/40:v1"
,
"gcr.io/40:v1"
,
"gcr.io/40:v1"
,
"gcr.io/40:v1"
,
},
},
...
@@ -73,14 +76,14 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -73,14 +76,14 @@ func TestImageLocalityPriority(t *testing.T) {
},
},
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/140
"
,
"gcr.io/140
:"
+
parsers
.
DefaultImageTag
,
"gcr.io/140:v1"
,
"gcr.io/140:v1"
,
},
},
SizeBytes
:
int64
(
140
*
mb
),
SizeBytes
:
int64
(
140
*
mb
),
},
},
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/2000
"
,
"gcr.io/2000
:"
+
parsers
.
DefaultImageTag
,
},
},
SizeBytes
:
int64
(
2000
*
mb
),
SizeBytes
:
int64
(
2000
*
mb
),
},
},
...
@@ -91,13 +94,13 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -91,13 +94,13 @@ func TestImageLocalityPriority(t *testing.T) {
Images
:
[]
v1
.
ContainerImage
{
Images
:
[]
v1
.
ContainerImage
{
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/250
"
,
"gcr.io/250
:"
+
parsers
.
DefaultImageTag
,
},
},
SizeBytes
:
int64
(
250
*
mb
),
SizeBytes
:
int64
(
250
*
mb
),
},
},
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/10
"
,
"gcr.io/10
:"
+
parsers
.
DefaultImageTag
,
"gcr.io/10:v1"
,
"gcr.io/10:v1"
,
},
},
SizeBytes
:
int64
(
10
*
mb
),
SizeBytes
:
int64
(
10
*
mb
),
...
@@ -116,11 +119,11 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -116,11 +119,11 @@ func TestImageLocalityPriority(t *testing.T) {
// Pod: gcr.io/40 gcr.io/250
// Pod: gcr.io/40 gcr.io/250
// Node1
// Node1
// Image: gcr.io/40 40MB
// Image: gcr.io/40
:latest
40MB
// Score: (40M-23M)/97.7M + 1 = 1
// Score: (40M-23M)/97.7M + 1 = 1
// Node2
// Node2
// Image: gcr.io/250 250MB
// Image: gcr.io/250
:latest
250MB
// Score: (250M-23M)/97.7M + 1 = 3
// Score: (250M-23M)/97.7M + 1 = 3
pod
:
&
v1
.
Pod
{
Spec
:
test40250
},
pod
:
&
v1
.
Pod
{
Spec
:
test40250
},
nodes
:
[]
*
v1
.
Node
{
makeImageNode
(
"machine1"
,
node401402000
),
makeImageNode
(
"machine2"
,
node25010
)},
nodes
:
[]
*
v1
.
Node
{
makeImageNode
(
"machine1"
,
node401402000
),
makeImageNode
(
"machine2"
,
node25010
)},
...
@@ -131,7 +134,7 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -131,7 +134,7 @@ func TestImageLocalityPriority(t *testing.T) {
// Pod: gcr.io/40 gcr.io/140
// Pod: gcr.io/40 gcr.io/140
// Node1
// Node1
// Image: gcr.io/40
40MB, gcr.io/140
140MB
// Image: gcr.io/40
:latest 40MB, gcr.io/140:latest
140MB
// Score: (40M+140M-23M)/97.7M + 1 = 2
// Score: (40M+140M-23M)/97.7M + 1 = 2
// Node2
// Node2
...
@@ -146,11 +149,11 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -146,11 +149,11 @@ func TestImageLocalityPriority(t *testing.T) {
// Pod: gcr.io/2000 gcr.io/10
// Pod: gcr.io/2000 gcr.io/10
// Node1
// Node1
// Image: gcr.io/2000 2000MB
// Image: gcr.io/2000
:latest
2000MB
// Score: 2000 > max score = 10
// Score: 2000 > max score = 10
// Node2
// Node2
// Image: gcr.io/10 10MB
// Image: gcr.io/10
:latest
10MB
// Score: 10 < min score = 0
// Score: 10 < min score = 0
pod
:
&
v1
.
Pod
{
Spec
:
testMinMax
},
pod
:
&
v1
.
Pod
{
Spec
:
testMinMax
},
nodes
:
[]
*
v1
.
Node
{
makeImageNode
(
"machine1"
,
node401402000
),
makeImageNode
(
"machine2"
,
node25010
)},
nodes
:
[]
*
v1
.
Node
{
makeImageNode
(
"machine1"
,
node401402000
),
makeImageNode
(
"machine2"
,
node25010
)},
...
@@ -177,9 +180,31 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -177,9 +180,31 @@ func TestImageLocalityPriority(t *testing.T) {
}
}
}
}
func
TestNormalizedImageName
(
t
*
testing
.
T
)
{
for
_
,
testCase
:=
range
[]
struct
{
Input
string
Output
string
}{
{
Input
:
"root"
,
Output
:
"root:latest"
},
{
Input
:
"root:tag"
,
Output
:
"root:tag"
},
{
Input
:
"gcr.io:5000/root"
,
Output
:
"gcr.io:5000/root:latest"
},
{
Input
:
"root@"
+
getImageFakeDigest
(
"root"
),
Output
:
"root@"
+
getImageFakeDigest
(
"root"
)},
}
{
image
:=
normalizedImageName
(
testCase
.
Input
)
if
image
!=
testCase
.
Output
{
t
.
Errorf
(
"expected image reference: %q, got %q"
,
testCase
.
Output
,
image
)
}
}
}
func
makeImageNode
(
node
string
,
status
v1
.
NodeStatus
)
*
v1
.
Node
{
func
makeImageNode
(
node
string
,
status
v1
.
NodeStatus
)
*
v1
.
Node
{
return
&
v1
.
Node
{
return
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
node
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
node
},
Status
:
status
,
Status
:
status
,
}
}
}
}
func
getImageFakeDigest
(
fakeContent
string
)
string
{
hash
:=
sha256
.
Sum256
([]
byte
(
fakeContent
))
return
"sha256:"
+
hex
.
EncodeToString
(
hash
[
:
])
}
pkg/scheduler/cache/node_info_test.go
View file @
8792f99b
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/scheduler/util"
"k8s.io/kubernetes/pkg/scheduler/util"
"k8s.io/kubernetes/pkg/util/parsers"
)
)
func
TestNewResource
(
t
*
testing
.
T
)
{
func
TestNewResource
(
t
*
testing
.
T
)
{
...
@@ -250,14 +251,14 @@ func TestImageSizes(t *testing.T) {
...
@@ -250,14 +251,14 @@ func TestImageSizes(t *testing.T) {
Images
:
[]
v1
.
ContainerImage
{
Images
:
[]
v1
.
ContainerImage
{
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/10
"
,
"gcr.io/10
:"
+
parsers
.
DefaultImageTag
,
"gcr.io/10:v1"
,
"gcr.io/10:v1"
,
},
},
SizeBytes
:
int64
(
10
*
1024
*
1024
),
SizeBytes
:
int64
(
10
*
1024
*
1024
),
},
},
{
{
Names
:
[]
string
{
Names
:
[]
string
{
"gcr.io/50
"
,
"gcr.io/50
:"
+
parsers
.
DefaultImageTag
,
"gcr.io/50:v1"
,
"gcr.io/50:v1"
,
},
},
SizeBytes
:
int64
(
50
*
1024
*
1024
),
SizeBytes
:
int64
(
50
*
1024
*
1024
),
...
@@ -268,10 +269,10 @@ func TestImageSizes(t *testing.T) {
...
@@ -268,10 +269,10 @@ func TestImageSizes(t *testing.T) {
ni
.
updateImageSizes
()
ni
.
updateImageSizes
()
expected
:=
map
[
string
]
int64
{
expected
:=
map
[
string
]
int64
{
"gcr.io/10
"
:
10
*
1024
*
1024
,
"gcr.io/10
:"
+
parsers
.
DefaultImageTag
:
10
*
1024
*
1024
,
"gcr.io/10:v1"
:
10
*
1024
*
1024
,
"gcr.io/10:v1"
:
10
*
1024
*
1024
,
"gcr.io/50
"
:
50
*
1024
*
1024
,
"gcr.io/50
:"
+
parsers
.
DefaultImageTag
:
50
*
1024
*
1024
,
"gcr.io/50:v1"
:
50
*
1024
*
1024
,
"gcr.io/50:v1"
:
50
*
1024
*
1024
,
}
}
imageSizes
:=
ni
.
ImageSizes
()
imageSizes
:=
ni
.
ImageSizes
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment