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
26a70a52
Commit
26a70a52
authored
Apr 17, 2015
by
Yu-Ju Hong
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6843 from xiang90/cleanup
pkg/kubelet: clean up pod manager
parents
92e66810
28c17262
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
26 deletions
+14
-26
pod_manager.go
pkg/kubelet/pod_manager.go
+14
-26
No files found.
pkg/kubelet/pod_manager.go
View file @
26a70a52
...
...
@@ -72,7 +72,7 @@ type basicPodManager struct {
mirrorPodByFullName
map
[
string
]
*
api
.
Pod
// A mirror pod client to create/delete mirror pods.
mirrorClient
mirrorClient
mirrorClient
}
func
newBasicPodManager
(
apiserverClient
client
.
Interface
)
*
basicPodManager
{
...
...
@@ -179,24 +179,16 @@ func applyUpdates(changed []api.Pod, current []api.Pod) []api.Pod {
return
updated
}
func
(
self
*
basicPodManager
)
convertMapToPods
(
UIDMap
map
[
types
.
UID
]
*
api
.
Pod
)
[]
api
.
Pod
{
pods
:=
make
([]
api
.
Pod
,
0
,
len
(
UIDMap
))
for
_
,
pod
:=
range
UIDMap
{
pods
=
append
(
pods
,
*
pod
)
}
return
pods
}
// GetPods returns the regular pods bound to the kubelet and their spec.
func
(
self
*
basicPodManager
)
GetPods
()
[]
api
.
Pod
{
self
.
lock
.
RLock
()
defer
self
.
lock
.
RUnlock
()
return
self
.
convert
MapToPods
(
self
.
podByUID
)
return
pods
MapToPods
(
self
.
podByUID
)
}
// Returns all pods (including mirror pods).
func
(
self
*
basicPodManager
)
getAllPods
()
[]
api
.
Pod
{
return
append
(
self
.
convertMapToPods
(
self
.
podByUID
),
self
.
convert
MapToPods
(
self
.
mirrorPodByUID
)
...
)
return
append
(
podsMapToPods
(
self
.
podByUID
),
pods
MapToPods
(
self
.
mirrorPodByUID
)
...
)
}
// GetPodsAndMirrorMap returns the a copy of the regular pods and the mirror
...
...
@@ -208,7 +200,7 @@ func (self *basicPodManager) GetPodsAndMirrorMap() ([]api.Pod, map[string]api.Po
for
key
,
pod
:=
range
self
.
mirrorPodByFullName
{
mirrorPods
[
key
]
=
*
pod
}
return
self
.
convert
MapToPods
(
self
.
podByUID
),
mirrorPods
return
pods
MapToPods
(
self
.
podByUID
),
mirrorPods
}
// GetPodByName provides the (non-mirror) pod that matches namespace and name,
...
...
@@ -223,10 +215,8 @@ func (self *basicPodManager) GetPodByName(namespace, name string) (*api.Pod, boo
func
(
self
*
basicPodManager
)
GetPodByFullName
(
podFullName
string
)
(
*
api
.
Pod
,
bool
)
{
self
.
lock
.
RLock
()
defer
self
.
lock
.
RUnlock
()
if
pod
,
ok
:=
self
.
podByFullName
[
podFullName
];
ok
{
return
pod
,
true
}
return
nil
,
false
pod
,
ok
:=
self
.
podByFullName
[
podFullName
]
return
pod
,
ok
}
// If the UID belongs to a mirror pod, maps it to the UID of its static pod.
...
...
@@ -271,16 +261,6 @@ func (self *basicPodManager) DeleteOrphanedMirrorPods() {
}
}
// Creates a mirror pod for the given pod.
func
(
self
*
basicPodManager
)
CreateMirrorPod
(
pod
api
.
Pod
)
error
{
return
self
.
mirrorClient
.
CreateMirrorPod
(
pod
)
}
// Delete a mirror pod by name.
func
(
self
*
basicPodManager
)
DeleteMirrorPod
(
podFullName
string
)
error
{
return
self
.
mirrorClient
.
DeleteMirrorPod
(
podFullName
)
}
// Returns true if mirrorPod is a correct representation of pod; false otherwise.
func
(
self
*
basicPodManager
)
IsMirrorPodOf
(
mirrorPod
,
pod
*
api
.
Pod
)
bool
{
// Check name and namespace first.
...
...
@@ -289,3 +269,11 @@ func (self *basicPodManager) IsMirrorPodOf(mirrorPod, pod *api.Pod) bool {
}
return
api
.
Semantic
.
DeepEqual
(
&
pod
.
Spec
,
&
mirrorPod
.
Spec
)
}
func
podsMapToPods
(
UIDMap
map
[
types
.
UID
]
*
api
.
Pod
)
[]
api
.
Pod
{
pods
:=
make
([]
api
.
Pod
,
0
,
len
(
UIDMap
))
for
_
,
pod
:=
range
UIDMap
{
pods
=
append
(
pods
,
*
pod
)
}
return
pods
}
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