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
6dce4d87
Commit
6dce4d87
authored
Feb 28, 2019
by
wojtekt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix secret/configmap management for terminated pods
parent
4b1282d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
6 deletions
+61
-6
pod_manager.go
pkg/kubelet/pod/pod_manager.go
+26
-6
cache_based_manager_test.go
pkg/kubelet/util/manager/cache_based_manager_test.go
+31
-0
manager.go
pkg/kubelet/util/manager/manager.go
+4
-0
No files found.
pkg/kubelet/pod/pod_manager.go
View file @
6dce4d87
...
...
@@ -168,20 +168,40 @@ func (pm *basicManager) UpdatePod(pod *v1.Pod) {
}
}
func
isPodInTerminatedState
(
pod
*
v1
.
Pod
)
bool
{
return
pod
.
Status
.
Phase
==
v1
.
PodFailed
||
pod
.
Status
.
Phase
==
v1
.
PodSucceeded
}
// updatePodsInternal replaces the given pods in the current state of the
// manager, updating the various indices. The caller is assumed to hold the
// lock.
func
(
pm
*
basicManager
)
updatePodsInternal
(
pods
...*
v1
.
Pod
)
{
for
_
,
pod
:=
range
pods
{
if
pm
.
secretManager
!=
nil
{
// TODO: Consider detecting only status update and in such case do
// not register pod, as it doesn't really matter.
pm
.
secretManager
.
RegisterPod
(
pod
)
if
isPodInTerminatedState
(
pod
)
{
// Pods that are in terminated state and no longer running can be
// ignored as they no longer require access to secrets.
// It is especially important in watch-based manager, to avoid
// unnecessary watches for terminated pods waiting for GC.
pm
.
secretManager
.
UnregisterPod
(
pod
)
}
else
{
// TODO: Consider detecting only status update and in such case do
// not register pod, as it doesn't really matter.
pm
.
secretManager
.
RegisterPod
(
pod
)
}
}
if
pm
.
configMapManager
!=
nil
{
// TODO: Consider detecting only status update and in such case do
// not register pod, as it doesn't really matter.
pm
.
configMapManager
.
RegisterPod
(
pod
)
if
isPodInTerminatedState
(
pod
)
{
// Pods that are in terminated state and no longer running can be
// ignored as they no longer require access to configmaps.
// It is especially important in watch-based manager, to avoid
// unnecessary watches for terminated pods waiting for GC.
pm
.
configMapManager
.
UnregisterPod
(
pod
)
}
else
{
// TODO: Consider detecting only status update and in such case do
// not register pod, as it doesn't really matter.
pm
.
configMapManager
.
RegisterPod
(
pod
)
}
}
podFullName
:=
kubecontainer
.
GetPodFullName
(
pod
)
// This logic relies on a static pod and its mirror to have the same name.
...
...
pkg/kubelet/util/manager/cache_based_manager_test.go
View file @
6dce4d87
...
...
@@ -429,6 +429,37 @@ func TestCacheInvalidation(t *testing.T) {
fakeClient
.
ClearActions
()
}
func
TestRegisterIdempotence
(
t
*
testing
.
T
)
{
fakeClient
:=
&
fake
.
Clientset
{}
fakeClock
:=
clock
.
NewFakeClock
(
time
.
Now
())
store
:=
newSecretStore
(
fakeClient
,
fakeClock
,
noObjectTTL
,
time
.
Minute
)
manager
:=
newCacheBasedSecretManager
(
store
)
s1
:=
secretsToAttach
{
imagePullSecretNames
:
[]
string
{
"s1"
},
}
refs
:=
func
(
ns
,
name
string
)
int
{
store
.
lock
.
Lock
()
defer
store
.
lock
.
Unlock
()
item
,
ok
:=
store
.
items
[
objectKey
{
ns
,
name
}]
if
!
ok
{
return
0
}
return
item
.
refCount
}
manager
.
RegisterPod
(
podWithSecrets
(
"ns1"
,
"name1"
,
s1
))
assert
.
Equal
(
t
,
1
,
refs
(
"ns1"
,
"s1"
))
manager
.
RegisterPod
(
podWithSecrets
(
"ns1"
,
"name1"
,
s1
))
assert
.
Equal
(
t
,
1
,
refs
(
"ns1"
,
"s1"
))
manager
.
UnregisterPod
(
podWithSecrets
(
"ns1"
,
"name1"
,
s1
))
assert
.
Equal
(
t
,
0
,
refs
(
"ns1"
,
"s1"
))
manager
.
UnregisterPod
(
podWithSecrets
(
"ns1"
,
"name1"
,
s1
))
assert
.
Equal
(
t
,
0
,
refs
(
"ns1"
,
"s1"
))
}
func
TestCacheRefcounts
(
t
*
testing
.
T
)
{
fakeClient
:=
&
fake
.
Clientset
{}
fakeClock
:=
clock
.
NewFakeClock
(
time
.
Now
())
...
...
pkg/kubelet/util/manager/manager.go
View file @
6dce4d87
...
...
@@ -32,10 +32,14 @@ type Manager interface {
// i.e. should not block on network operations.
// RegisterPod registers all objects referenced from a given pod.
//
// NOTE: All implementations of RegisterPod should be idempotent.
RegisterPod
(
pod
*
v1
.
Pod
)
// UnregisterPod unregisters objects referenced from a given pod that are not
// used by any other registered pod.
//
// NOTE: All implementations of UnregisterPod should be idempotent.
UnregisterPod
(
pod
*
v1
.
Pod
)
}
...
...
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