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
7ffa4e17
Commit
7ffa4e17
authored
Aug 06, 2018
by
Krzysztof Jastrzebski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce latency to node ready after CIDR is assigned.
parent
e9de06d4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
6 deletions
+57
-6
kubelet.go
pkg/kubelet/kubelet.go
+44
-1
kubelet_network.go
pkg/kubelet/kubelet_network.go
+7
-4
kubelet_node_status.go
pkg/kubelet/kubelet_node_status.go
+6
-1
No files found.
pkg/kubelet/kubelet.go
View file @
7ffa4e17
...
...
@@ -692,7 +692,9 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
klet
.
pleg
=
pleg
.
NewGenericPLEG
(
klet
.
containerRuntime
,
plegChannelCapacity
,
plegRelistPeriod
,
klet
.
podCache
,
clock
.
RealClock
{})
klet
.
runtimeState
=
newRuntimeState
(
maxWaitForContainerRuntime
)
klet
.
runtimeState
.
addHealthCheck
(
"PLEG"
,
klet
.
pleg
.
Healthy
)
klet
.
updatePodCIDR
(
kubeCfg
.
PodCIDR
)
if
err
:=
klet
.
updatePodCIDR
(
kubeCfg
.
PodCIDR
);
err
!=
nil
{
glog
.
Errorf
(
"Pod CIDR update failed %v"
,
err
)
}
// setup containerGC
containerGC
,
err
:=
kubecontainer
.
NewContainerGC
(
klet
.
containerRuntime
,
containerGCPolicy
,
klet
.
sourcesReady
)
...
...
@@ -1011,6 +1013,18 @@ type Kubelet struct {
// as it takes time to gather all necessary node information.
nodeStatusUpdateFrequency
time
.
Duration
// syncNodeStatusMux is a lock on updating the node status, because this path is not thread-safe.
// This lock is used by Kublet.syncNodeStatus function and shouldn't be used anywhere else.
syncNodeStatusMux
sync
.
Mutex
// updatePodCIDRMux is a lock on updating pod CIDR, because this path is not thread-safe.
// This lock is used by Kublet.syncNodeStatus function and shouldn't be used anywhere else.
updatePodCIDRMux
sync
.
Mutex
// updateRuntimeMux is a lock on updating runtime, because this path is not thread-safe.
// This lock is used by Kublet.updateRuntimeUp function and shouldn't be used anywhere else.
updateRuntimeMux
sync
.
Mutex
// Generates pod events.
pleg
pleg
.
PodLifecycleEventGenerator
...
...
@@ -1347,6 +1361,7 @@ func (kl *Kubelet) Run(updates <-chan kubetypes.PodUpdate) {
if
kl
.
kubeClient
!=
nil
{
// Start syncing node status immediately, this may set up things the runtime needs to run.
go
wait
.
Until
(
kl
.
syncNodeStatus
,
kl
.
nodeStatusUpdateFrequency
,
wait
.
NeverStop
)
go
kl
.
fastStatusUpdateOnce
()
}
go
wait
.
Until
(
kl
.
updateRuntimeUp
,
5
*
time
.
Second
,
wait
.
NeverStop
)
...
...
@@ -2079,6 +2094,9 @@ func (kl *Kubelet) LatestLoopEntryTime() time.Time {
// and returns an error if the status check fails. If the status check is OK,
// update the container runtime uptime in the kubelet runtimeState.
func
(
kl
*
Kubelet
)
updateRuntimeUp
()
{
kl
.
updateRuntimeMux
.
Lock
()
defer
kl
.
updateRuntimeMux
.
Unlock
()
s
,
err
:=
kl
.
containerRuntime
.
Status
()
if
err
!=
nil
{
glog
.
Errorf
(
"Container runtime sanity check failed: %v"
,
err
)
...
...
@@ -2153,6 +2171,31 @@ func (kl *Kubelet) cleanUpContainersInPod(podID types.UID, exitedContainerID str
}
}
// fastStatusUpdateOnce starts a loop that checks the internal node indexer cache for when a CIDR
// is applied and tries to update pod CIDR immediately. After pod CIDR is updated it fires off
// a runtime update and a node status update. Function returns after one successful node status update.
// Function is executed only during Kubelet start which improves latency to ready node by updating
// pod CIDR, runtime status and node statuses ASAP.
func
(
kl
*
Kubelet
)
fastStatusUpdateOnce
()
{
for
{
time
.
Sleep
(
100
*
time
.
Millisecond
)
node
,
err
:=
kl
.
GetNode
()
if
err
!=
nil
{
glog
.
Errorf
(
err
.
Error
())
continue
}
if
node
.
Spec
.
PodCIDR
!=
""
{
if
err
:=
kl
.
updatePodCIDR
(
node
.
Spec
.
PodCIDR
);
err
!=
nil
{
glog
.
Errorf
(
"Pod CIDR update failed %v"
,
err
)
continue
}
kl
.
updateRuntimeUp
()
kl
.
syncNodeStatus
()
return
}
}
}
// isSyncPodWorthy filters out events that are not worthy of pod syncing
func
isSyncPodWorthy
(
event
*
pleg
.
PodLifecycleEvent
)
bool
{
// ContatnerRemoved doesn't affect pod state
...
...
pkg/kubelet/kubelet_network.go
View file @
7ffa4e17
...
...
@@ -56,22 +56,25 @@ func (kl *Kubelet) providerRequiresNetworkingConfiguration() bool {
// updatePodCIDR updates the pod CIDR in the runtime state if it is different
// from the current CIDR.
func
(
kl
*
Kubelet
)
updatePodCIDR
(
cidr
string
)
{
func
(
kl
*
Kubelet
)
updatePodCIDR
(
cidr
string
)
error
{
kl
.
updatePodCIDRMux
.
Lock
()
defer
kl
.
updatePodCIDRMux
.
Unlock
()
podCIDR
:=
kl
.
runtimeState
.
podCIDR
()
if
podCIDR
==
cidr
{
return
return
nil
}
// kubelet -> generic runtime -> runtime shim -> network plugin
// docker/non-cri implementations have a passthrough UpdatePodCIDR
if
err
:=
kl
.
getRuntime
()
.
UpdatePodCIDR
(
cidr
);
err
!=
nil
{
glog
.
Errorf
(
"Failed to update pod CIDR: %v"
,
err
)
return
return
fmt
.
Errorf
(
"failed to update pod CIDR: %v"
,
err
)
}
glog
.
Infof
(
"Setting Pod CIDR: %v -> %v"
,
podCIDR
,
cidr
)
kl
.
runtimeState
.
setPodCIDR
(
cidr
)
return
nil
}
// syncNetworkUtil ensures the network utility are present on host.
...
...
pkg/kubelet/kubelet_node_status.go
View file @
7ffa4e17
...
...
@@ -351,6 +351,9 @@ func (kl *Kubelet) initialNode() (*v1.Node, error) {
// It synchronizes node status to master, registering the kubelet first if
// necessary.
func
(
kl
*
Kubelet
)
syncNodeStatus
()
{
kl
.
syncNodeStatusMux
.
Lock
()
defer
kl
.
syncNodeStatusMux
.
Unlock
()
if
kl
.
kubeClient
==
nil
||
kl
.
heartbeatClient
==
nil
{
return
}
...
...
@@ -402,7 +405,9 @@ func (kl *Kubelet) tryUpdateNodeStatus(tryNumber int) error {
}
if
node
.
Spec
.
PodCIDR
!=
""
{
kl
.
updatePodCIDR
(
node
.
Spec
.
PodCIDR
)
if
err
:=
kl
.
updatePodCIDR
(
node
.
Spec
.
PodCIDR
);
err
!=
nil
{
glog
.
Errorf
(
err
.
Error
())
}
}
kl
.
setNodeStatus
(
node
)
...
...
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