Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
Signed-off-by: chrismark <chrismarkou92@gmail.com>
  • Loading branch information
ChrsMark committed Jul 22, 2020
1 parent 12277bb commit f62ca1e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions libbeat/autodiscover/providers/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (p *pod) OnUpdate(obj interface{}) {
switch pod.Status.Phase {
case kubernetes.PodSucceeded, kubernetes.PodFailed:
// If Pod is in a phase where all containers in the have terminated emit a stop event
p.logger.Debugf("Watcher Pod update (terminating): %+v", obj)
p.logger.Debugf("Watcher Pod update (terminated): %+v", obj)
time.AfterFunc(p.config.CleanupTimeout, func() { p.emit(pod, "stop") })
return
case kubernetes.PodPending:
Expand All @@ -148,14 +148,18 @@ func (p *pod) OnUpdate(obj interface{}) {

// here handle the case when a Pod is in `Terminating` phase.
// In this case the pod is neither `PodSucceeded` nor `PodFailed` and
// hence a stop/start sequence will take place. However we need to
// handle this as just a stop event with a cleanup timeout so as to
// to give time to any leftover log lines to be collected while the pod is
// in `Terminating` phase.
// hence requires special handling.
if pod.GetObjectMeta().GetDeletionTimestamp() != nil {
p.logger.Debugf("Watcher Pod update (being terminated): %+v", obj)
p.logger.Debugf("Watcher Pod update (terminating): %+v", obj)
// Pod is terminating, don't reload its configuration and ignore the event
// if some pod is still running, we will receive more events when containers
// terminate.
for _, container := range pod.Status.ContainerStatuses {
if container.State.Running != nil {
return
}
}
time.AfterFunc(p.config.CleanupTimeout, func() { p.emit(pod, "stop") })
return
}

p.logger.Debugf("Watcher Pod update: %+v", obj)
Expand Down

0 comments on commit f62ca1e

Please sign in to comment.