From 3e58e3a9ad5c4d9287f6ae3b51f89cdd4564d522 Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:30:44 -0400 Subject: [PATCH] feat(waiter): add native wait support for Job resources (#1202) 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 Co-authored-by: Claude Opus 4.6 --- .../20260805-add-job-wait-condition.yaml | 4 +++ plugins/module_utils/k8s/waiter.py | 25 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/20260805-add-job-wait-condition.yaml diff --git a/changelogs/fragments/20260805-add-job-wait-condition.yaml b/changelogs/fragments/20260805-add-job-wait-condition.yaml new file mode 100644 index 00000000..cf15b7da --- /dev/null +++ b/changelogs/fragments/20260805-add-job-wait-condition.yaml @@ -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)." diff --git a/plugins/module_utils/k8s/waiter.py b/plugins/module_utils/k8s/waiter.py index 8bfb7634..ed65c44e 100644 --- a/plugins/module_utils/k8s/waiter.py +++ b/plugins/module_utils/k8s/waiter.py @@ -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, }