Keep monitoring blockers visible in provisioner diagnostics
This commit is contained in:
parent
82276a32c6
commit
df750f2809
|
|
@ -83,8 +83,13 @@ def diagnostics(args):
|
|||
items = kubectl(args, "-n", args.namespace, "get", resource, "-o", "json")["items"]
|
||||
if resource == "events":
|
||||
items = sorted(items, key=lambda x: x.get("lastTimestamp") or x["metadata"].get("creationTimestamp", ""))
|
||||
for item in items[-15:]:
|
||||
print(f"event {item.get('reason')}: {item.get('message')}", file=sys.stderr)
|
||||
# Background audit events can fill the diagnostic tail and
|
||||
# hide actual scheduling, admission, mount, or container errors.
|
||||
items = [item for item in items if item.get("type") == "Warning"
|
||||
and item.get("reason") != "PolicyViolation"]
|
||||
for item in items[-10:]:
|
||||
target = item.get("involvedObject", {}).get("name", "")
|
||||
print(f"event {target} {item.get('reason')}: {item.get('message', '')[:1000]}", file=sys.stderr)
|
||||
continue
|
||||
for item in items:
|
||||
name = item["metadata"]["name"]
|
||||
|
|
@ -94,11 +99,23 @@ def diagnostics(args):
|
|||
status = item.get("status", {})
|
||||
record = {"name": name, "phase": status.get("phase")}
|
||||
if resource == "pods":
|
||||
conditions = status.get("conditions", [])
|
||||
if status.get("phase") in ("Succeeded", "Failed") or any(
|
||||
c.get("type") == "Ready" and c.get("status") == "True"
|
||||
for c in conditions
|
||||
):
|
||||
continue
|
||||
record.update(
|
||||
node=spec.get("nodeName"),
|
||||
selector=spec.get("nodeSelector"),
|
||||
priority=spec.get("priorityClassName"),
|
||||
conditions=status.get("conditions"),
|
||||
revision=item["metadata"].get("labels", {}).get("controller-revision-hash"),
|
||||
conditions=[{"type": c.get("type"), "reason": c.get("reason"),
|
||||
"message": c.get("message")}
|
||||
for c in conditions if c.get("status") != "True"],
|
||||
containers=[{"name": c.get("name"), "state": c.get("state")}
|
||||
for c in status.get("initContainerStatuses", [])
|
||||
+ status.get("containerStatuses", []) if not c.get("ready")],
|
||||
requests=[c.get("resources", {}).get("requests", {}) for c in spec.get("containers", [])],
|
||||
)
|
||||
else:
|
||||
|
|
@ -142,6 +159,10 @@ def main():
|
|||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
diagnostics(args)
|
||||
# Terraform can retain only the tail of provisioner output. Keep
|
||||
# the actual blockers after the longer diagnostic details.
|
||||
for error in errors:
|
||||
print("BLOCKED " + error, file=sys.stderr)
|
||||
print("Monitoring readiness timed out; PVC placement and resource requests were preserved.", file=sys.stderr)
|
||||
return 1
|
||||
time.sleep(min(5, remaining))
|
||||
|
|
|
|||
Loading…
Reference in New Issue