mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
pleg: ensure the cache is updated whenever container are removed
Even though we don't rely on the cache for garbage collection yet, we should keep it up-to-date.
This commit is contained in:
parent
13f6daf980
commit
388689238b
@ -124,17 +124,17 @@ func generateEvent(podID types.UID, cid string, oldState, newState plegContainer
|
||||
case plegContainerExited:
|
||||
return &PodLifecycleEvent{ID: podID, Type: ContainerDied, Data: cid}
|
||||
case plegContainerUnknown:
|
||||
// Don't generate any event if the status is unknown.
|
||||
return nil
|
||||
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. There is no
|
||||
// need to do it again.
|
||||
return nil
|
||||
// We already reported that the container died before.
|
||||
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}
|
||||
}
|
||||
default:
|
||||
@ -204,6 +204,10 @@ func (g *GenericPLEG) relist() {
|
||||
// Update the internal storage and send out the events.
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
g.eventChannel <- events[i]
|
||||
}
|
||||
}
|
||||
|
@ -23,13 +23,14 @@ import (
|
||||
type PodLifeCycleEventType string
|
||||
|
||||
const (
|
||||
ContainerStarted PodLifeCycleEventType = "ContainerStarted"
|
||||
ContainerDied PodLifeCycleEventType = "ContainerDied"
|
||||
NetworkSetupCompleted PodLifeCycleEventType = "NetworkSetupCompleted"
|
||||
NetworkFailed PodLifeCycleEventType = "NetworkFailed"
|
||||
ContainerStarted PodLifeCycleEventType = "ContainerStarted"
|
||||
ContainerDied PodLifeCycleEventType = "ContainerDied"
|
||||
// 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"
|
||||
)
|
||||
|
||||
// PodLifecycleEvent is an event that reflects the change of the pod state.
|
||||
|
Loading…
Reference in New Issue
Block a user