@@ -41,7 +41,7 @@ def service_name(self) -> str:
41
41
def with_replicas (self , min_replicas : int , max_replicas : T .Optional [int ] = None ) -> T .Self :
42
42
if max_replicas is not None :
43
43
if min_replicas > max_replicas :
44
- raise ValueError (f' min_replicas cannot be larger than max_replicas: { min_replicas } > { max_replicas } ' )
44
+ raise ValueError (f" min_replicas cannot be larger than max_replicas: { min_replicas } > { max_replicas } " )
45
45
self ._replicas = (min_replicas , max_replicas )
46
46
else :
47
47
self ._replicas = min_replicas
@@ -77,7 +77,7 @@ def with_toleration(self, key: str, value: str = "", effect: TaintEffect = Taint
77
77
self ._tolerations .append ((key , value , effect ))
78
78
return self
79
79
80
- def _build (self , meta : k8s .ObjectMeta , chart : Chart ) -> k8s .KubeDeployment :
80
+ def _build (self , meta : k8s .ObjectMeta , chart : Chart ) -> k8s .KubeDeployment : # noqa: PLR0912
81
81
pod_meta : T .MutableMapping [str , T .Any ] = {}
82
82
if self ._pod_annotations :
83
83
pod_meta ["annotations" ] = self ._pod_annotations
@@ -96,7 +96,8 @@ def _build(self, meta: k8s.ObjectMeta, chart: Chart) -> k8s.KubeDeployment:
96
96
if self ._service_account_role is not None :
97
97
sa = self ._build_service_account (chart )
98
98
rb = self ._build_role_binding_for_service_account (
99
- chart , sa ,
99
+ chart ,
100
+ sa ,
100
101
self ._service_account_role ,
101
102
self ._service_account_role_is_cluster_role ,
102
103
)
@@ -112,23 +113,22 @@ def _build(self, meta: k8s.ObjectMeta, chart: Chart) -> k8s.KubeDeployment:
112
113
self ._build_service (chart )
113
114
114
115
if len (self ._tolerations ) > 0 :
115
- optional ["tolerations" ] = [
116
- {"key" : t [0 ], "value" : t [1 ], "effect" : t [2 ]} for t in self ._tolerations
117
- ]
116
+ optional ["tolerations" ] = [{"key" : t [0 ], "value" : t [1 ], "effect" : t [2 ]} for t in self ._tolerations ]
118
117
119
118
vols : VolumeDefsWithObject = dict ()
120
119
for c in self ._containers :
121
120
vols = {** vols , ** c .build_volumes (chart )}
122
121
123
122
if vols :
124
123
optional ["volumes" ] = []
125
- for ( defn , obj ) in vols .values ():
124
+ for defn , obj in vols .values ():
126
125
optional ["volumes" ].append (defn )
127
126
if obj is not None :
128
127
self ._deps .append (obj )
129
128
130
129
depl = k8s .KubeDeployment (
131
- chart , f"{ self ._tag } depl" ,
130
+ chart ,
131
+ f"{ self ._tag } depl" ,
132
132
metadata = meta ,
133
133
spec = k8s .DeploymentSpec (
134
134
selector = k8s .LabelSelector (match_labels = self ._selector ),
@@ -139,15 +139,17 @@ def _build(self, meta: k8s.ObjectMeta, chart: Chart) -> k8s.KubeDeployment:
139
139
containers = [c .build () for c in self ._containers ],
140
140
** optional ,
141
141
),
142
- )
143
- )
142
+ ),
143
+ ),
144
144
)
145
145
146
146
for i in range (len (self ._containers )):
147
- depl .add_json_patch (JsonPatch .add (
148
- f"/spec/template/spec/containers/{ i } /env/-" ,
149
- {"name" : "POD_OWNER" , "value" : depl .name },
150
- ))
147
+ depl .add_json_patch (
148
+ JsonPatch .add (
149
+ f"/spec/template/spec/containers/{ i } /env/-" ,
150
+ {"name" : "POD_OWNER" , "value" : depl .name },
151
+ )
152
+ )
151
153
152
154
return depl
153
155
@@ -158,12 +160,12 @@ def _build_service_account(self, chart: Chart) -> k8s.KubeServiceAccount:
158
160
def _build_service (self , chart : Chart ) -> k8s .KubeService :
159
161
assert self ._service_ports
160
162
return k8s .KubeService (
161
- chart , "service" ,
163
+ chart ,
164
+ "service" ,
162
165
metadata = {"name" : self ._service_name },
163
166
spec = k8s .ServiceSpec (
164
167
ports = [
165
- k8s .ServicePort (port = p , target_port = k8s .IntOrString .from_number (p ))
166
- for p in self ._service_ports
168
+ k8s .ServicePort (port = p , target_port = k8s .IntOrString .from_number (p )) for p in self ._service_ports
167
169
],
168
170
selector = self ._selector ,
169
171
),
@@ -176,12 +178,13 @@ def _build_role_binding_for_service_account(
176
178
role_name : str ,
177
179
is_cluster_role : bool ,
178
180
) -> T .Union [k8s .KubeClusterRoleBinding , k8s .KubeRoleBinding ]:
179
-
180
- subjects = [k8s .Subject (
181
- kind = "ServiceAccount" ,
182
- name = service_account .name ,
183
- namespace = chart .namespace ,
184
- )]
181
+ subjects = [
182
+ k8s .Subject (
183
+ kind = "ServiceAccount" ,
184
+ name = service_account .name ,
185
+ namespace = chart .namespace ,
186
+ )
187
+ ]
185
188
role_ref = k8s .RoleRef (
186
189
api_group = "rbac.authorization.k8s.io" ,
187
190
kind = "ClusterRole" if is_cluster_role else "Role" ,
0 commit comments