-
Notifications
You must be signed in to change notification settings - Fork 43
/
pod_disruption_budget_schemas.py
84 lines (66 loc) · 2.82 KB
/
pod_disruption_budget_schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from acto.schema import BaseSchema, ObjectSchema
from .base import K8sAnyOfSchema, K8sObjectSchema
class LabelSelectorSchema(K8sObjectSchema):
fields = {
'matchLabels': K8sObjectSchema,
'matchExpressions': K8sObjectSchema
}
def __init__(self, schema_obj: BaseSchema) -> None:
super().__init__(schema_obj)
for field, field_schema in LabelSelectorSchema.fields.items():
if field in schema_obj.properties:
self.properties[field] = field_schema(schema_obj.properties[field])
def Match(schema: ObjectSchema) -> bool:
if not K8sObjectSchema.Match(schema):
return False
for field, field_schema in LabelSelectorSchema.fields.items():
if field not in schema.properties:
return False
elif not field_schema.Match(schema.properties[field]):
return False
return True
def __str__(self) -> str:
return "LabelSelectorSchema"
class PodDisruptionBudgetSpecSchema(K8sObjectSchema):
fields = {
'minAvailable': K8sAnyOfSchema,
'maxUnavailable': K8sAnyOfSchema,
'selector': K8sObjectSchema
}
def __init__(self, schema_obj: BaseSchema) -> None:
super().__init__(schema_obj)
for field, field_schema in PodDisruptionBudgetSpecSchema.fields.items():
if field in schema_obj.properties:
self.properties[field] = field_schema(schema_obj.properties[field])
def Match(schema: ObjectSchema) -> bool:
if not K8sObjectSchema.Match(schema):
return False
for field, field_schema in PodDisruptionBudgetSpecSchema.fields.items():
if field not in schema.properties:
return False
elif not field_schema.Match(schema.properties[field]):
return False
return True
def __str__(self) -> str:
return "PodDisruptionBudgetSpecSchema"
class PodDisruptionBudgetSchema(K8sObjectSchema):
fields = {
'metadata': K8sObjectSchema,
'spec': PodDisruptionBudgetSpecSchema
}
def __init__(self, schema_obj: BaseSchema) -> None:
super().__init__(schema_obj)
for field, field_schema in PodDisruptionBudgetSchema.fields.items():
if field in schema_obj.properties:
self.properties[field] = field_schema(schema_obj.properties[field])
def Match(schema: ObjectSchema) -> bool:
if not K8sObjectSchema.Match(schema):
return False
for field, field_schema in PodDisruptionBudgetSchema.fields.items():
if field not in schema.properties:
return False
elif not field_schema.Match(schema.properties[field]):
return False
return True
def __str__(self) -> str:
return "PodDisruptionBudgetSchema"