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
63003619
Commit
63003619
authored
Jan 17, 2017
by
allencloud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify if and else for code
Signed-off-by:
allencloud
<
allen.sun@daocloud.io
>
parent
6fbc554c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
44 deletions
+44
-44
kubelet_node_status.go
pkg/kubelet/kubelet_node_status.go
+44
-44
No files found.
pkg/kubelet/kubelet_node_status.go
View file @
63003619
...
@@ -426,7 +426,8 @@ func (kl *Kubelet) setNodeAddress(node *v1.Node) error {
...
@@ -426,7 +426,8 @@ func (kl *Kubelet) setNodeAddress(node *v1.Node) error {
if
kl
.
externalCloudProvider
{
if
kl
.
externalCloudProvider
{
// We rely on the external cloud provider to supply the addresses.
// We rely on the external cloud provider to supply the addresses.
return
nil
return
nil
}
else
if
kl
.
cloud
!=
nil
{
}
if
kl
.
cloud
!=
nil
{
instances
,
ok
:=
kl
.
cloud
.
Instances
()
instances
,
ok
:=
kl
.
cloud
.
Instances
()
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"failed to get instances from cloud provider"
)
return
fmt
.
Errorf
(
"failed to get instances from cloud provider"
)
...
@@ -603,20 +604,21 @@ func (kl *Kubelet) setNodeStatusVersionInfo(node *v1.Node) {
...
@@ -603,20 +604,21 @@ func (kl *Kubelet) setNodeStatusVersionInfo(node *v1.Node) {
verinfo
,
err
:=
kl
.
cadvisor
.
VersionInfo
()
verinfo
,
err
:=
kl
.
cadvisor
.
VersionInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error getting version info: %v"
,
err
)
glog
.
Errorf
(
"Error getting version info: %v"
,
err
)
}
else
{
return
node
.
Status
.
NodeInfo
.
KernelVersion
=
verinfo
.
KernelVersion
}
node
.
Status
.
NodeInfo
.
OSImage
=
verinfo
.
ContainerOsVersion
runtimeVersion
:=
"Unknown"
node
.
Status
.
NodeInfo
.
KernelVersion
=
verinfo
.
KernelVersion
if
runtimeVer
,
err
:=
kl
.
containerRuntime
.
Version
();
err
==
nil
{
node
.
Status
.
NodeInfo
.
OSImage
=
verinfo
.
ContainerOsVersion
runtimeVersion
=
runtimeVer
.
String
()
}
node
.
Status
.
NodeInfo
.
ContainerRuntimeVersion
=
fmt
.
Sprintf
(
"%s://%s"
,
kl
.
containerRuntime
.
Type
(),
runtimeVersion
)
node
.
Status
.
NodeInfo
.
KubeletVersion
=
version
.
Get
()
.
String
()
runtimeVersion
:=
"Unknown"
// TODO: kube-proxy might be different version from kubelet in the future
if
runtimeVer
,
err
:=
kl
.
containerRuntime
.
Version
();
err
==
nil
{
node
.
Status
.
NodeInfo
.
KubeProxyVersion
=
version
.
Get
()
.
String
()
runtimeVersion
=
runtimeVer
.
String
()
}
}
node
.
Status
.
NodeInfo
.
ContainerRuntimeVersion
=
fmt
.
Sprintf
(
"%s://%s"
,
kl
.
containerRuntime
.
Type
(),
runtimeVersion
)
node
.
Status
.
NodeInfo
.
KubeletVersion
=
version
.
Get
()
.
String
()
// TODO: kube-proxy might be different version from kubelet in the future
node
.
Status
.
NodeInfo
.
KubeProxyVersion
=
version
.
Get
()
.
String
()
}
}
// Set daemonEndpoints for the node.
// Set daemonEndpoints for the node.
...
@@ -631,25 +633,27 @@ func (kl *Kubelet) setNodeStatusImages(node *v1.Node) {
...
@@ -631,25 +633,27 @@ func (kl *Kubelet) setNodeStatusImages(node *v1.Node) {
containerImages
,
err
:=
kl
.
imageManager
.
GetImageList
()
containerImages
,
err
:=
kl
.
imageManager
.
GetImageList
()
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error getting image list: %v"
,
err
)
glog
.
Errorf
(
"Error getting image list: %v"
,
err
)
}
else
{
node
.
Status
.
Images
=
imagesOnNode
// sort the images from max to min, and only set top N images into the node status.
return
sort
.
Sort
(
sliceutils
.
ByImageSize
(
containerImages
))
}
if
maxImagesInNodeStatus
<
len
(
containerImages
)
{
// sort the images from max to min, and only set top N images into the node status.
containerImages
=
containerImages
[
0
:
maxImagesInNodeStatus
]
sort
.
Sort
(
sliceutils
.
ByImageSize
(
containerImages
))
}
if
maxImagesInNodeStatus
<
len
(
containerImages
)
{
containerImages
=
containerImages
[
0
:
maxImagesInNodeStatus
]
}
for
_
,
image
:=
range
containerImages
{
for
_
,
image
:=
range
containerImages
{
names
:=
append
(
image
.
RepoDigests
,
image
.
RepoTags
...
)
names
:=
append
(
image
.
RepoDigests
,
image
.
RepoTags
...
)
// Report up to maxNamesPerImageInNodeStatus names per image.
// Report up to maxNamesPerImageInNodeStatus names per image.
if
len
(
names
)
>
maxNamesPerImageInNodeStatus
{
if
len
(
names
)
>
maxNamesPerImageInNodeStatus
{
names
=
names
[
0
:
maxNamesPerImageInNodeStatus
]
names
=
names
[
0
:
maxNamesPerImageInNodeStatus
]
}
imagesOnNode
=
append
(
imagesOnNode
,
v1
.
ContainerImage
{
Names
:
names
,
SizeBytes
:
image
.
Size
,
})
}
}
imagesOnNode
=
append
(
imagesOnNode
,
v1
.
ContainerImage
{
Names
:
names
,
SizeBytes
:
image
.
Size
,
})
}
}
node
.
Status
.
Images
=
imagesOnNode
node
.
Status
.
Images
=
imagesOnNode
}
}
...
@@ -779,14 +783,12 @@ func (kl *Kubelet) setNodeMemoryPressureCondition(node *v1.Node) {
...
@@ -779,14 +783,12 @@ func (kl *Kubelet) setNodeMemoryPressureCondition(node *v1.Node) {
condition
.
LastTransitionTime
=
currentTime
condition
.
LastTransitionTime
=
currentTime
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasInsufficientMemory"
)
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasInsufficientMemory"
)
}
}
}
else
{
}
else
if
condition
.
Status
!=
v1
.
ConditionFalse
{
if
condition
.
Status
!=
v1
.
ConditionFalse
{
condition
.
Status
=
v1
.
ConditionFalse
condition
.
Status
=
v1
.
ConditionFalse
condition
.
Reason
=
"KubeletHasSufficientMemory"
condition
.
Reason
=
"KubeletHasSufficientMemory"
condition
.
Message
=
"kubelet has sufficient memory available"
condition
.
Message
=
"kubelet has sufficient memory available"
condition
.
LastTransitionTime
=
currentTime
condition
.
LastTransitionTime
=
currentTime
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasSufficientMemory"
)
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasSufficientMemory"
)
}
}
}
if
newCondition
{
if
newCondition
{
...
@@ -837,14 +839,12 @@ func (kl *Kubelet) setNodeDiskPressureCondition(node *v1.Node) {
...
@@ -837,14 +839,12 @@ func (kl *Kubelet) setNodeDiskPressureCondition(node *v1.Node) {
condition
.
LastTransitionTime
=
currentTime
condition
.
LastTransitionTime
=
currentTime
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasDiskPressure"
)
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasDiskPressure"
)
}
}
}
else
{
}
else
if
condition
.
Status
!=
v1
.
ConditionFalse
{
if
condition
.
Status
!=
v1
.
ConditionFalse
{
condition
.
Status
=
v1
.
ConditionFalse
condition
.
Status
=
v1
.
ConditionFalse
condition
.
Reason
=
"KubeletHasNoDiskPressure"
condition
.
Reason
=
"KubeletHasNoDiskPressure"
condition
.
Message
=
"kubelet has no disk pressure"
condition
.
Message
=
"kubelet has no disk pressure"
condition
.
LastTransitionTime
=
currentTime
condition
.
LastTransitionTime
=
currentTime
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasNoDiskPressure"
)
kl
.
recordNodeStatusEvent
(
v1
.
EventTypeNormal
,
"NodeHasNoDiskPressure"
)
}
}
}
if
newCondition
{
if
newCondition
{
...
...
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