feat(waiter): add native wait support for Job resources (#1202) (#1211)

Add a `job_complete` predicate that waits for Job resources to reach
either `Complete` or `Failed` condition, removing the need for custom
wait_condition workarounds.

Also rename shadowed `match` variable to `match_condition` in
`custom_condition` to avoid masking the Python built-in.

Fixes ansible-collections/kubernetes.core#1201


(cherry picked from commit 3e58e3a9ad)

Co-authored-by: Bikouo Aubin <79859644+abikouo@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
patchback[bot]
2026-08-10 16:49:59 +02:00
committed by GitHub
co-authored by Bikouo Aubin Claude Opus 4.6
parent 477bb79305
commit 79e98c3d6e
2 changed files with 23 additions and 6 deletions
@@ -0,0 +1,4 @@
---
minor_changes:
- "waiter - Add ``job_complete`` predicate to support waiting for Job resources
to reach ``Complete`` or ``Failed`` condition (https://github.com/ansible-collections/kubernetes.core/issues/1201)."
+19 -6
View File
@@ -47,6 +47,18 @@ def pod_ready(pod: ResourceInstance) -> bool:
)
def job_complete(job: ResourceInstance) -> bool:
return bool(
job.status
and job.status.conditions
and any(
condition["type"] in ("Complete", "Failed")
and boolean(condition["status"], strict=False)
for condition in job.status.conditions
)
)
def daemonset_ready(daemonset: ResourceInstance) -> bool:
return bool(
daemonset.status
@@ -89,18 +101,18 @@ def custom_condition(condition: Dict, resource: ResourceInstance) -> bool:
if not matches:
return False
# There should never be more than one condition of a specific type
match: ResourceField = matches[0]
if match.status == "Unknown":
if match.status == condition["status"]:
match_condition: ResourceField = matches[0]
if match_condition.status == "Unknown":
if match_condition.status == condition["status"]:
if "reason" not in condition:
return True
if condition["reason"]:
return match.reason == condition["reason"]
return match_condition.reason == condition["reason"]
return False
status = True if match.status == "True" else False
status = True if match_condition.status == "True" else False
if status == boolean(condition["status"], strict=False):
if condition.get("reason"):
return match.reason == condition["reason"]
return match_condition.reason == condition["reason"]
return True
return False
@@ -143,6 +155,7 @@ RESOURCE_PREDICATES = {
"DaemonSet": daemonset_ready,
"Deployment": deployment_ready,
"Pod": pod_ready,
"Job": job_complete,
"StatefulSet": statefulset_ready,
"ClusterOperator": cluster_operator_ready,
}