mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-11-23 07:30:19 +00:00
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:
co-authored by
Bikouo Aubin
Claude Opus 4.6
parent
477bb79305
commit
79e98c3d6e
@@ -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)."
|
||||||
@@ -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:
|
def daemonset_ready(daemonset: ResourceInstance) -> bool:
|
||||||
return bool(
|
return bool(
|
||||||
daemonset.status
|
daemonset.status
|
||||||
@@ -89,18 +101,18 @@ def custom_condition(condition: Dict, resource: ResourceInstance) -> bool:
|
|||||||
if not matches:
|
if not matches:
|
||||||
return False
|
return False
|
||||||
# There should never be more than one condition of a specific type
|
# There should never be more than one condition of a specific type
|
||||||
match: ResourceField = matches[0]
|
match_condition: ResourceField = matches[0]
|
||||||
if match.status == "Unknown":
|
if match_condition.status == "Unknown":
|
||||||
if match.status == condition["status"]:
|
if match_condition.status == condition["status"]:
|
||||||
if "reason" not in condition:
|
if "reason" not in condition:
|
||||||
return True
|
return True
|
||||||
if condition["reason"]:
|
if condition["reason"]:
|
||||||
return match.reason == condition["reason"]
|
return match_condition.reason == condition["reason"]
|
||||||
return False
|
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 status == boolean(condition["status"], strict=False):
|
||||||
if condition.get("reason"):
|
if condition.get("reason"):
|
||||||
return match.reason == condition["reason"]
|
return match_condition.reason == condition["reason"]
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -143,6 +155,7 @@ RESOURCE_PREDICATES = {
|
|||||||
"DaemonSet": daemonset_ready,
|
"DaemonSet": daemonset_ready,
|
||||||
"Deployment": deployment_ready,
|
"Deployment": deployment_ready,
|
||||||
"Pod": pod_ready,
|
"Pod": pod_ready,
|
||||||
|
"Job": job_complete,
|
||||||
"StatefulSet": statefulset_ready,
|
"StatefulSet": statefulset_ready,
|
||||||
"ClusterOperator": cluster_operator_ready,
|
"ClusterOperator": cluster_operator_ready,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user