Keep invalid container states from dropping host heartbeats
This commit is contained in:
+3
-3
@@ -32,7 +32,7 @@ import urllib.parse
|
||||
import urllib.request
|
||||
import uuid
|
||||
|
||||
VERSION = "1.4.11"
|
||||
VERSION = "1.4.12"
|
||||
LABEL = "io.electric-cherry"
|
||||
MAX_FILE = 32 * 1024 * 1024
|
||||
MANIFEST_MAX_ENTRIES = 10000
|
||||
@@ -1054,7 +1054,7 @@ class Agent:
|
||||
raise AgentError("Container ownership or generation does not match")
|
||||
state = info.get("State", {})
|
||||
status = state.get("Status", "unknown")
|
||||
healthy = state.get("Running") is True and state.get("Health", {}).get("Status", "healthy") == "healthy"
|
||||
healthy = state.get("Status") == "running" and state.get("Running") is True and state.get("Health", {}).get("Status", "healthy") == "healthy"
|
||||
if status == "running" and not healthy:
|
||||
status = state.get("Health", {}).get("Status", "unknown")
|
||||
return {"exists": True, "running": state.get("Running") is True, "healthy": healthy, "state": status, "containerId": info.get("Id"), "instanceId": instance_id, "generation": generation, "startedAt": state.get("StartedAt"), "creationOperation": labels.get(LABEL + ".operation"), "specSha256": labels.get(LABEL + ".spec-sha256")}
|
||||
@@ -1152,7 +1152,7 @@ class Agent:
|
||||
if not any(mount.get("Type") == "bind" and mount.get("Source") == expected and mount.get("Destination") == "/home/plutainer/app" for mount in info.get("Mounts", [])):
|
||||
continue
|
||||
state = info.get("State", {})
|
||||
healthy = state.get("Running") is True and state.get("Health", {}).get("Status", "healthy") == "healthy"
|
||||
healthy = state.get("Status") == "running" and state.get("Running") is True and state.get("Health", {}).get("Status", "healthy") == "healthy"
|
||||
status = state.get("Status", "unknown")
|
||||
if status == "running" and not healthy:
|
||||
status = state.get("Health", {}).get("Status", "unknown")
|
||||
|
||||
@@ -583,7 +583,7 @@ class AgentTests(unittest.TestCase):
|
||||
self.assertNotIn("instanceResourcesError", inventory)
|
||||
|
||||
def test_heartbeat_states_share_inspection_and_include_stopped_and_unhealthy_containers(self):
|
||||
for status, running, health in (("exited", False, "healthy"), ("running", True, "unhealthy"), ("running", True, "healthy")):
|
||||
for status, running, health in (("exited", False, "healthy"), ("running", True, "unhealthy"), ("running", True, "healthy"), ("restarting", True, "healthy"), ("paused", True, "healthy")):
|
||||
info = self.resource_container()
|
||||
info["State"].update({"Status": status, "Running": running, "Health": {"Status": health}})
|
||||
observations = []
|
||||
@@ -593,7 +593,9 @@ class AgentTests(unittest.TestCase):
|
||||
self.assertEqual(observations[0]["instanceId"], INSTANCE)
|
||||
self.assertEqual(observations[0]["generation"], 1)
|
||||
self.assertEqual(observations[0]["state"], health if running and health != "healthy" else status)
|
||||
self.assertEqual(observations[0]["healthy"], running and health == "healthy")
|
||||
self.assertEqual(observations[0]["healthy"], status == "running" and running and health == "healthy")
|
||||
self.docker.containers[self.agent.container_name(INSTANCE, 1)] = info
|
||||
self.assertEqual(self.agent.inspect(INSTANCE, 1)["healthy"], observations[0]["healthy"])
|
||||
self.assertIn("observedAt", observations[0])
|
||||
self.assertEqual(sum(args.args[:2] == ("container", "inspect") for args in docker.call_args_list), 1)
|
||||
info["Mounts"][0]["Source"] = "/foreign/app"
|
||||
|
||||
Reference in New Issue
Block a user