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
a58c774c
Commit
a58c774c
authored
Jul 13, 2016
by
Ron Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Including ContainerRemoved in PLEG event reporting
parent
f27a8034
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
24 deletions
+35
-24
kubelet.go
pkg/kubelet/kubelet.go
+16
-8
generic.go
pkg/kubelet/pleg/generic.go
+13
-15
generic_test.go
pkg/kubelet/pleg/generic_test.go
+5
-0
pleg.go
pkg/kubelet/pleg/pleg.go
+1
-1
No files found.
pkg/kubelet/kubelet.go
View file @
a58c774c
...
...
@@ -2335,15 +2335,17 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
}
case
e
:=
<-
plegCh
:
// PLEG event for a pod; sync it.
pod
,
ok
:=
kl
.
podManager
.
GetPodByUID
(
e
.
ID
)
if
!
ok
{
// If the pod no longer exists, ignore the event.
glog
.
V
(
4
)
.
Infof
(
"SyncLoop (PLEG): ignore irrelevant event: %#v"
,
e
)
break
if
isSyncPodWorthy
(
e
)
{
// PLEG event for a pod; sync it.
pod
,
ok
:=
kl
.
podManager
.
GetPodByUID
(
e
.
ID
)
if
!
ok
{
// If the pod no longer exists, ignore the event.
glog
.
V
(
4
)
.
Infof
(
"SyncLoop (PLEG): ignore irrelevant event: %#v"
,
e
)
break
}
glog
.
V
(
2
)
.
Infof
(
"SyncLoop (PLEG): %q, event: %#v"
,
format
.
Pod
(
pod
),
e
)
handler
.
HandlePodSyncs
([]
*
api
.
Pod
{
pod
})
}
glog
.
V
(
2
)
.
Infof
(
"SyncLoop (PLEG): %q, event: %#v"
,
format
.
Pod
(
pod
),
e
)
handler
.
HandlePodSyncs
([]
*
api
.
Pod
{
pod
})
case
<-
syncCh
:
// Sync pods waiting for sync
podsToSync
:=
kl
.
getPodsToSync
()
...
...
@@ -3563,3 +3565,9 @@ func (kl *Kubelet) ListenAndServe(address net.IP, port uint, tlsOptions *server.
func
(
kl
*
Kubelet
)
ListenAndServeReadOnly
(
address
net
.
IP
,
port
uint
)
{
server
.
ListenAndServeKubeletReadOnlyServer
(
kl
,
kl
.
resourceAnalyzer
,
address
,
port
,
kl
.
containerRuntime
)
}
// Filter out events that are not worthy of pod syncing
func
isSyncPodWorthy
(
event
*
pleg
.
PodLifecycleEvent
)
bool
{
// ContatnerRemoved doesn't affect pod state
return
event
.
Type
!=
pleg
.
ContainerRemoved
}
pkg/kubelet/pleg/generic.go
View file @
a58c774c
...
...
@@ -134,29 +134,25 @@ func (g *GenericPLEG) Healthy() (bool, error) {
return
true
,
nil
}
func
generateEvent
(
podID
types
.
UID
,
cid
string
,
oldState
,
newState
plegContainerState
)
*
PodLifecycleEvent
{
func
generateEvent
s
(
podID
types
.
UID
,
cid
string
,
oldState
,
newState
plegContainerState
)
[]
*
PodLifecycleEvent
{
if
newState
==
oldState
{
return
nil
}
glog
.
V
(
4
)
.
Infof
(
"GenericPLEG: %v/%v: %v -> %v"
,
podID
,
cid
,
oldState
,
newState
)
switch
newState
{
case
plegContainerRunning
:
return
&
PodLifecycleEvent
{
ID
:
podID
,
Type
:
ContainerStarted
,
Data
:
cid
}
return
[]
*
PodLifecycleEvent
{{
ID
:
podID
,
Type
:
ContainerStarted
,
Data
:
cid
}
}
case
plegContainerExited
:
return
&
PodLifecycleEvent
{
ID
:
podID
,
Type
:
ContainerDied
,
Data
:
cid
}
return
[]
*
PodLifecycleEvent
{{
ID
:
podID
,
Type
:
ContainerDied
,
Data
:
cid
}
}
case
plegContainerUnknown
:
return
&
PodLifecycleEvent
{
ID
:
podID
,
Type
:
ContainerChanged
,
Data
:
cid
}
return
[]
*
PodLifecycleEvent
{{
ID
:
podID
,
Type
:
ContainerChanged
,
Data
:
cid
}
}
case
plegContainerNonExistent
:
// We report "ContainerDied" when container was stopped OR removed. We
// may want to distinguish the two cases in the future.
switch
oldState
{
case
plegContainerExited
:
// We already reported that the container died before.
return
&
PodLifecycleEvent
{
ID
:
podID
,
Type
:
ContainerRemoved
,
Data
:
cid
}
return
[]
*
PodLifecycleEvent
{{
ID
:
podID
,
Type
:
ContainerRemoved
,
Data
:
cid
}
}
default
:
// TODO: We may want to generate a ContainerRemoved event as well.
// It's ok now because no one relies on the ContainerRemoved event.
return
&
PodLifecycleEvent
{
ID
:
podID
,
Type
:
ContainerDied
,
Data
:
cid
}
return
[]
*
PodLifecycleEvent
{{
ID
:
podID
,
Type
:
ContainerDied
,
Data
:
cid
},
{
ID
:
podID
,
Type
:
ContainerRemoved
,
Data
:
cid
}}
}
default
:
panic
(
fmt
.
Sprintf
(
"unrecognized container state: %v"
,
newState
))
...
...
@@ -208,8 +204,10 @@ func (g *GenericPLEG) relist() {
// Get all containers in the old and the new pod.
allContainers
:=
getContainersFromPods
(
oldPod
,
pod
)
for
_
,
container
:=
range
allContainers
{
e
:=
computeEvent
(
oldPod
,
pod
,
&
container
.
ID
)
updateEvents
(
eventsByPodID
,
e
)
events
:=
computeEvents
(
oldPod
,
pod
,
&
container
.
ID
)
for
_
,
e
:=
range
events
{
updateEvents
(
eventsByPodID
,
e
)
}
}
}
...
...
@@ -250,7 +248,7 @@ func (g *GenericPLEG) relist() {
g
.
podRecords
.
update
(
pid
)
for
i
:=
range
events
{
// Filter out events that are not reliable and no other components use yet.
if
events
[
i
]
.
Type
==
ContainerChanged
||
events
[
i
]
.
Type
==
ContainerRemoved
{
if
events
[
i
]
.
Type
==
ContainerChanged
{
continue
}
g
.
eventChannel
<-
events
[
i
]
...
...
@@ -297,7 +295,7 @@ func getContainersFromPods(pods ...*kubecontainer.Pod) []*kubecontainer.Containe
return
containers
}
func
computeEvent
(
oldPod
,
newPod
*
kubecontainer
.
Pod
,
cid
*
kubecontainer
.
ContainerID
)
*
PodLifecycleEvent
{
func
computeEvent
s
(
oldPod
,
newPod
*
kubecontainer
.
Pod
,
cid
*
kubecontainer
.
ContainerID
)
[]
*
PodLifecycleEvent
{
var
pid
types
.
UID
if
oldPod
!=
nil
{
pid
=
oldPod
.
ID
...
...
@@ -306,7 +304,7 @@ func computeEvent(oldPod, newPod *kubecontainer.Pod, cid *kubecontainer.Containe
}
oldState
:=
getContainerState
(
oldPod
,
cid
)
newState
:=
getContainerState
(
newPod
,
cid
)
return
generateEvent
(
pid
,
cid
.
ID
,
oldState
,
newState
)
return
generateEvent
s
(
pid
,
cid
.
ID
,
oldState
,
newState
)
}
func
(
g
*
GenericPLEG
)
cacheEnabled
()
bool
{
...
...
pkg/kubelet/pleg/generic_test.go
View file @
a58c774c
...
...
@@ -146,8 +146,10 @@ func TestRelisting(t *testing.T) {
pleg
.
relist
()
// Only report containers that transitioned to running or exited status.
expected
=
[]
*
PodLifecycleEvent
{
{
ID
:
"1234"
,
Type
:
ContainerRemoved
,
Data
:
"c1"
},
{
ID
:
"1234"
,
Type
:
ContainerDied
,
Data
:
"c2"
},
{
ID
:
"1234"
,
Type
:
ContainerStarted
,
Data
:
"c3"
},
{
ID
:
"4567"
,
Type
:
ContainerRemoved
,
Data
:
"c1"
},
{
ID
:
"4567"
,
Type
:
ContainerStarted
,
Data
:
"c4"
},
}
...
...
@@ -199,6 +201,8 @@ func testReportMissingContainers(t *testing.T, numRelists int) {
pleg
.
relist
()
expected
:=
[]
*
PodLifecycleEvent
{
{
ID
:
"1234"
,
Type
:
ContainerDied
,
Data
:
"c2"
},
{
ID
:
"1234"
,
Type
:
ContainerRemoved
,
Data
:
"c2"
},
{
ID
:
"1234"
,
Type
:
ContainerRemoved
,
Data
:
"c3"
},
}
actual
:=
getEventsFromChannel
(
ch
)
verifyEvents
(
t
,
expected
,
actual
)
...
...
@@ -228,6 +232,7 @@ func testReportMissingPods(t *testing.T, numRelists int) {
pleg
.
relist
()
expected
:=
[]
*
PodLifecycleEvent
{
{
ID
:
"1234"
,
Type
:
ContainerDied
,
Data
:
"c2"
},
{
ID
:
"1234"
,
Type
:
ContainerRemoved
,
Data
:
"c2"
},
}
actual
:=
getEventsFromChannel
(
ch
)
verifyEvents
(
t
,
expected
,
actual
)
...
...
pkg/kubelet/pleg/pleg.go
View file @
a58c774c
...
...
@@ -25,11 +25,11 @@ type PodLifeCycleEventType string
const
(
ContainerStarted
PodLifeCycleEventType
=
"ContainerStarted"
ContainerDied
PodLifeCycleEventType
=
"ContainerDied"
ContainerRemoved
PodLifeCycleEventType
=
"ContainerRemoved"
// PodSync is used to trigger syncing of a pod when the observed change of
// the state of the pod cannot be captured by any single event above.
PodSync
PodLifeCycleEventType
=
"PodSync"
// Do not use the events below because they are disabled in GenericPLEG.
ContainerRemoved
PodLifeCycleEventType
=
"ContainerRemoved"
ContainerChanged
PodLifeCycleEventType
=
"ContainerChanged"
)
...
...
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