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
032a8863
Commit
032a8863
authored
May 08, 2016
by
Harry Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only store top N images in status
parent
f538d601
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
kubelet.go
pkg/kubelet/kubelet.go
+18
-0
kubelet_test.go
pkg/kubelet/kubelet_test.go
+13
-12
No files found.
pkg/kubelet/kubelet.go
View file @
032a8863
...
@@ -151,6 +151,9 @@ const (
...
@@ -151,6 +151,9 @@ const (
// Maximum period to wait for pod volume setup operations
// Maximum period to wait for pod volume setup operations
maxWaitForVolumeOps
=
20
*
time
.
Minute
maxWaitForVolumeOps
=
20
*
time
.
Minute
// maxImagesInStatus is the number of max images we store in image status.
maxImagesInNodeStatus
=
50
)
)
// SyncHandler is an interface implemented by Kubelet, for testability
// SyncHandler is an interface implemented by Kubelet, for testability
...
@@ -3096,6 +3099,12 @@ func (kl *Kubelet) setNodeStatusImages(node *api.Node) {
...
@@ -3096,6 +3099,12 @@ func (kl *Kubelet) setNodeStatusImages(node *api.Node) {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error getting image list: %v"
,
err
)
glog
.
Errorf
(
"Error getting image list: %v"
,
err
)
}
else
{
}
else
{
// sort the images from max to min, and only set top N images into the node status.
sort
.
Sort
(
ByImageSize
(
containerImages
))
if
maxImagesInNodeStatus
<
len
(
containerImages
)
{
containerImages
=
containerImages
[
0
:
maxImagesInNodeStatus
-
1
]
}
for
_
,
image
:=
range
containerImages
{
for
_
,
image
:=
range
containerImages
{
imagesOnNode
=
append
(
imagesOnNode
,
api
.
ContainerImage
{
imagesOnNode
=
append
(
imagesOnNode
,
api
.
ContainerImage
{
Names
:
append
(
image
.
RepoTags
,
image
.
RepoDigests
...
),
Names
:
append
(
image
.
RepoTags
,
image
.
RepoDigests
...
),
...
@@ -3112,6 +3121,15 @@ func (kl *Kubelet) setNodeStatusGoRuntime(node *api.Node) {
...
@@ -3112,6 +3121,15 @@ func (kl *Kubelet) setNodeStatusGoRuntime(node *api.Node) {
node
.
Status
.
NodeInfo
.
Architecture
=
goRuntime
.
GOARCH
node
.
Status
.
NodeInfo
.
Architecture
=
goRuntime
.
GOARCH
}
}
type
ByImageSize
[]
kubecontainer
.
Image
// Sort from max to min
func
(
a
ByImageSize
)
Less
(
i
,
j
int
)
bool
{
return
a
[
i
]
.
Size
>
a
[
j
]
.
Size
}
func
(
a
ByImageSize
)
Len
()
int
{
return
len
(
a
)
}
func
(
a
ByImageSize
)
Swap
(
i
,
j
int
)
{
a
[
i
],
a
[
j
]
=
a
[
j
],
a
[
i
]
}
// Set status for the node.
// Set status for the node.
func
(
kl
*
Kubelet
)
setNodeStatusInfo
(
node
*
api
.
Node
)
{
func
(
kl
*
Kubelet
)
setNodeStatusInfo
(
node
*
api
.
Node
)
{
kl
.
setNodeStatusMachineInfo
(
node
)
kl
.
setNodeStatusMachineInfo
(
node
)
...
...
pkg/kubelet/kubelet_test.go
View file @
032a8863
...
@@ -2436,13 +2436,13 @@ func TestUpdateNewNodeStatus(t *testing.T) {
...
@@ -2436,13 +2436,13 @@ func TestUpdateNewNodeStatus(t *testing.T) {
},
},
Images
:
[]
api
.
ContainerImage
{
Images
:
[]
api
.
ContainerImage
{
{
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
SizeBytes
:
456
,
SizeBytes
:
456
,
},
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
},
},
},
},
}
}
...
@@ -2685,15 +2685,16 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
...
@@ -2685,15 +2685,16 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
{
Type
:
api
.
NodeLegacyHostIP
,
Address
:
"127.0.0.1"
},
{
Type
:
api
.
NodeLegacyHostIP
,
Address
:
"127.0.0.1"
},
{
Type
:
api
.
NodeInternalIP
,
Address
:
"127.0.0.1"
},
{
Type
:
api
.
NodeInternalIP
,
Address
:
"127.0.0.1"
},
},
},
// images will be sorted from max to min in node status.
Images
:
[]
api
.
ContainerImage
{
Images
:
[]
api
.
ContainerImage
{
{
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
SizeBytes
:
456
,
SizeBytes
:
456
,
},
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
},
},
},
},
}
}
...
@@ -2970,13 +2971,13 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) {
...
@@ -2970,13 +2971,13 @@ func TestUpdateNodeStatusWithRuntimeStateError(t *testing.T) {
},
},
Images
:
[]
api
.
ContainerImage
{
Images
:
[]
api
.
ContainerImage
{
{
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
Names
:
[]
string
{
"gcr.io/google_containers:v3"
,
"gcr.io/google_containers:v4"
},
SizeBytes
:
456
,
SizeBytes
:
456
,
},
},
{
Names
:
[]
string
{
"gcr.io/google_containers:v1"
,
"gcr.io/google_containers:v2"
},
SizeBytes
:
123
,
},
},
},
},
},
}
}
...
...
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