From 69f8ddc1234d4c141e87a6dd51fe4469d2718517 Mon Sep 17 00:00:00 2001 From: Fabio Kung Date: Thu, 6 Apr 2017 14:42:10 -0700 Subject: [PATCH] ensure heath monitor status updates are propagated initHealthMonitor and updateHealthMonitor can cause container state to be changed (State.Health). Signed-off-by: Fabio Kung Upstream-commit: 04bd768a889f94a4dc6ad25e2a014dffd0a4e04e Component: engine --- components/engine/container/health.go | 7 ++++--- components/engine/daemon/monitor.go | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/engine/container/health.go b/components/engine/container/health.go index 6e3cd12f3b..31c5600d25 100644 --- a/components/engine/container/health.go +++ b/components/engine/container/health.go @@ -13,9 +13,8 @@ type Health struct { // String returns a human-readable description of the health-check state func (s *Health) String() string { - // This happens when the container is being shutdown and the monitor has stopped - // or the monitor has yet to be setup. - if s.stop == nil { + // This happens when the monitor has yet to be setup. + if s.Status == "" { return types.Unhealthy } @@ -44,6 +43,8 @@ func (s *Health) CloseMonitorChannel() { logrus.Debug("CloseMonitorChannel: waiting for probe to stop") close(s.stop) s.stop = nil + // unhealthy when the monitor has stopped for compatibility reasons + s.Status = types.Unhealthy logrus.Debug("CloseMonitorChannel done") } } diff --git a/components/engine/daemon/monitor.go b/components/engine/daemon/monitor.go index 4f9cc37a04..5156d9a8e1 100644 --- a/components/engine/daemon/monitor.go +++ b/components/engine/daemon/monitor.go @@ -39,6 +39,9 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error { return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.") } daemon.updateHealthMonitor(c) + if err := c.CheckpointTo(daemon.containersReplica); err != nil { + return err + } daemon.LogContainerEvent(c, "oom") case libcontainerd.StateExit: @@ -119,30 +122,30 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error { c.HasBeenStartedBefore = true daemon.setStateCounter(c) + daemon.initHealthMonitor(c) if err := c.CheckpointTo(daemon.containersReplica); err != nil { c.Reset(false) return err } - daemon.initHealthMonitor(c) daemon.LogContainerEvent(c, "start") case libcontainerd.StatePause: // Container is already locked in this case c.Paused = true daemon.setStateCounter(c) + daemon.updateHealthMonitor(c) if err := c.CheckpointTo(daemon.containersReplica); err != nil { return err } - daemon.updateHealthMonitor(c) daemon.LogContainerEvent(c, "pause") case libcontainerd.StateResume: // Container is already locked in this case c.Paused = false daemon.setStateCounter(c) + daemon.updateHealthMonitor(c) if err := c.CheckpointTo(daemon.containersReplica); err != nil { return err } - daemon.updateHealthMonitor(c) daemon.LogContainerEvent(c, "unpause") } return nil