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
49f48340
Commit
49f48340
authored
Aug 11, 2015
by
CJ Cullen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12560 from yujuhong/sync_pods
kubelet: refactor SyncPods for better readability
parents
72ff1177
56f4605f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
19 deletions
+38
-19
kubelet.go
pkg/kubelet/kubelet.go
+38
-19
No files found.
pkg/kubelet/kubelet.go
View file @
49f48340
...
@@ -89,7 +89,6 @@ var (
...
@@ -89,7 +89,6 @@ var (
// SyncHandler is an interface implemented by Kubelet, for testability
// SyncHandler is an interface implemented by Kubelet, for testability
type
SyncHandler
interface
{
type
SyncHandler
interface
{
// Syncs current state to match the specified pods. SyncPodType specified what
// Syncs current state to match the specified pods. SyncPodType specified what
// type of sync is occurring per pod. StartTime specifies the time at which
// type of sync is occurring per pod. StartTime specifies the time at which
// syncing began (for use in monitoring).
// syncing began (for use in monitoring).
...
@@ -1422,42 +1421,56 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP
...
@@ -1422,42 +1421,56 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP
metrics
.
SyncPodsLatency
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
metrics
.
SyncPodsLatency
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
}()
}()
// Remove obsolete entries in podStatus where the pod is no longer considered bound to this node.
kl
.
removeOrphanedPodStatuses
(
allPods
)
podFullNames
:=
make
(
map
[
string
]
bool
)
for
_
,
pod
:=
range
allPods
{
podFullNames
[
kubecontainer
.
GetPodFullName
(
pod
)]
=
true
}
kl
.
statusManager
.
RemoveOrphanedStatuses
(
podFullNames
)
// Handles pod admission.
// Handles pod admission.
pods
:=
kl
.
admitPods
(
allPods
,
podSyncTypes
)
pods
:=
kl
.
admitPods
(
allPods
,
podSyncTypes
)
glog
.
V
(
4
)
.
Infof
(
"Desired pods: %s"
,
kubeletUtil
.
FormatPodNames
(
pods
))
glog
.
V
(
4
)
.
Infof
(
"Desired pods: %s"
,
kubeletUtil
.
FormatPodNames
(
pods
))
var
err
error
// Send updates to pod workers.
desiredPods
:=
make
(
map
[
types
.
UID
]
empty
)
kl
.
dispatchWork
(
pods
,
podSyncTypes
,
mirrorPods
,
start
)
// Clean up unwanted/orphaned resources.
runningPods
,
err
:=
kl
.
runtimeCache
.
GetPods
()
if
err
:=
kl
.
cleanupPods
(
allPods
,
pods
);
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error listing containers: %#v"
,
err
)
return
err
return
err
}
}
return
nil
}
// removeOrphanedPodStatuses removes obsolete entries in podStatus where
// the pod is no longer considered bound to this node.
// TODO(yujuhong): consider using pod UID as they key in the status manager
// to avoid returning the wrong status.
func
(
kl
*
Kubelet
)
removeOrphanedPodStatuses
(
pods
[]
*
api
.
Pod
)
{
podFullNames
:=
make
(
map
[
string
]
bool
)
for
_
,
pod
:=
range
pods
{
podFullNames
[
kubecontainer
.
GetPodFullName
(
pod
)]
=
true
}
kl
.
statusManager
.
RemoveOrphanedStatuses
(
podFullNames
)
}
// dispatchWork dispatches pod updates to workers.
func
(
kl
*
Kubelet
)
dispatchWork
(
pods
[]
*
api
.
Pod
,
podSyncTypes
map
[
types
.
UID
]
SyncPodType
,
mirrorPods
map
[
string
]
*
api
.
Pod
,
start
time
.
Time
)
{
// Check for any containers that need starting
// Check for any containers that need starting
for
_
,
pod
:=
range
pods
{
for
_
,
pod
:=
range
pods
{
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
uid
:=
pod
.
UID
desiredPods
[
uid
]
=
empty
{}
// Run the sync in an async manifest worker.
// Run the sync in an async manifest worker.
kl
.
podWorkers
.
UpdatePod
(
pod
,
mirrorPods
[
podFullName
],
func
()
{
kl
.
podWorkers
.
UpdatePod
(
pod
,
mirrorPods
[
podFullName
],
func
()
{
metrics
.
PodWorkerLatency
.
WithLabelValues
(
podSyncTypes
[
pod
.
UID
]
.
String
())
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
metrics
.
PodWorkerLatency
.
WithLabelValues
(
podSyncTypes
[
pod
.
UID
]
.
String
())
.
Observe
(
metrics
.
SinceInMicroseconds
(
start
))
})
})
// Note the number of containers for new pods.
// Note the number of containers for new pods.
if
val
,
ok
:=
podSyncTypes
[
pod
.
UID
];
ok
&&
(
val
==
SyncPodCreate
)
{
if
val
,
ok
:=
podSyncTypes
[
pod
.
UID
];
ok
&&
(
val
==
SyncPodCreate
)
{
metrics
.
ContainersPerPodCount
.
Observe
(
float64
(
len
(
pod
.
Spec
.
Containers
)))
metrics
.
ContainersPerPodCount
.
Observe
(
float64
(
len
(
pod
.
Spec
.
Containers
)))
}
}
}
}
}
// cleanupPods performs a series of cleanup work, including terminating pod
// workers, killing unwanted pods, and removing orphaned volumes/pod
// directories.
func
(
kl
*
Kubelet
)
cleanupPods
(
allPods
[]
*
api
.
Pod
,
admittedPods
[]
*
api
.
Pod
)
error
{
desiredPods
:=
make
(
map
[
types
.
UID
]
empty
)
for
_
,
pod
:=
range
admittedPods
{
desiredPods
[
pod
.
UID
]
=
empty
{}
}
// Stop the workers for no-longer existing pods.
// Stop the workers for no-longer existing pods.
kl
.
podWorkers
.
ForgetNonExistingPodWorkers
(
desiredPods
)
kl
.
podWorkers
.
ForgetNonExistingPodWorkers
(
desiredPods
)
...
@@ -1468,6 +1481,12 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP
...
@@ -1468,6 +1481,12 @@ func (kl *Kubelet) SyncPods(allPods []*api.Pod, podSyncTypes map[types.UID]SyncP
return
nil
return
nil
}
}
runningPods
,
err
:=
kl
.
runtimeCache
.
GetPods
()
if
err
!=
nil
{
glog
.
Errorf
(
"Error listing containers: %#v"
,
err
)
return
err
}
// Kill containers associated with unwanted pods.
// Kill containers associated with unwanted pods.
err
=
kl
.
killUnwantedPods
(
desiredPods
,
runningPods
)
err
=
kl
.
killUnwantedPods
(
desiredPods
,
runningPods
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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