Coverage for /Users/ajo/work/jumpstarter/jumpstarter/packages/jumpstarter/jumpstarter/common/condition.py: 29%
17 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:20 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:20 +0200
1# Ported from https://github.com/kubernetes/apimachinery/blob/v0.31.1/pkg/api/meta/conditions.go
3from jumpstarter_protocol import kubernetes_pb2
6def condition_present_and_equal(
7 conditions: list[kubernetes_pb2.Condition], condition_type: str, status: str, reason: str | None = None
8) -> bool:
9 for condition in conditions:
10 if condition.type == condition_type:
11 if reason is None or condition.reason == reason:
12 return condition.status == status
13 return False
16def condition_message(
17 conditions: list[kubernetes_pb2.Condition], condition_type: str, reason: str | None = None
18) -> str | None:
19 for condition in conditions:
20 if condition.type == condition_type:
21 if reason is None or condition.reason == reason:
22 return condition.message
23 return None
26def condition_true(conditions: list[kubernetes_pb2.Condition], condition_type: str) -> bool:
27 return condition_present_and_equal(conditions, condition_type, "True")
30def condition_false(conditions: list[kubernetes_pb2.Condition], condition_type: str) -> bool:
31 return condition_present_and_equal(conditions, condition_type, "False")