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:
Yu-Ju Hong 2016-02-26 18:41:38 -08:00 committed by Random-Liu
parent 13f6daf980
commit 388689238b
2 changed files with 14 additions and 9 deletions

View File

@ -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]
}
}

View File

@ -25,11 +25,12 @@ type PodLifeCycleEventType string
const (
ContainerStarted PodLifeCycleEventType = "ContainerStarted"
ContainerDied PodLifeCycleEventType = "ContainerDied"
NetworkSetupCompleted PodLifeCycleEventType = "NetworkSetupCompleted"
NetworkFailed PodLifeCycleEventType = "NetworkFailed"
// 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.