@@ -134,7 +134,7 @@ def get_command_using_train_func(
134
134
pip_index_url : str = constants .DEFAULT_PIP_INDEX_URL ,
135
135
) -> Tuple [List [str ], List [str ]]:
136
136
"""
137
- Get container args and command using the given training function and parameters.
137
+ Get container args and command from the given training function and parameters.
138
138
"""
139
139
# Check if function is callable.
140
140
if not callable (train_func ):
@@ -179,7 +179,7 @@ def get_command_using_train_func(
179
179
+ exec_script
180
180
)
181
181
182
- # Return container command and args execution script to the container arguments .
182
+ # Return container command and args to execute training function .
183
183
return ["bash" , "-c" ], [exec_script ]
184
184
185
185
@@ -202,19 +202,18 @@ def get_container_spec(
202
202
raise ValueError ("Container name or base image cannot be none" )
203
203
204
204
# Create initial container spec.
205
- container_spec = models .V1Container (name = name , image = base_image )
205
+ container_spec = models .V1Container (
206
+ name = name , image = base_image , args = args , volume_mounts = volume_mounts
207
+ )
206
208
207
- # If Training function is set, convert training function to the container args and command .
209
+ # If training function is set, override container command and args to execute the function .
208
210
if train_func is not None :
209
211
container_spec .command , container_spec .args = get_command_using_train_func (
210
212
train_func = train_func ,
211
213
train_func_parameters = train_func_parameters ,
212
214
packages_to_install = packages_to_install ,
213
215
pip_index_url = pip_index_url ,
214
216
)
215
- # Otherwise, get container args from the input.
216
- else :
217
- container_spec .args = args
218
217
219
218
# Convert dict to the Kubernetes container resources if that is required.
220
219
if isinstance (resources , dict ):
@@ -228,34 +227,33 @@ def get_container_spec(
228
227
limits = resources ,
229
228
)
230
229
231
- # Assign the rest container spec. If the value is None, container doesn't have that spec.
230
+ # Add resources to the container spec.
232
231
container_spec .resources = resources
233
- container_spec .volume_mounts = volume_mounts
234
232
235
233
return container_spec
236
234
237
235
238
236
def get_pod_template_spec (
239
237
containers : List [models .V1Container ],
240
238
init_containers : Optional [List [models .V1Container ]] = None ,
241
- volumes_spec : Optional [List [models .V1Volume ]] = None ,
239
+ volumes : Optional [List [models .V1Volume ]] = None ,
242
240
) -> models .V1PodTemplateSpec :
243
241
"""
244
242
Get Pod template spec for the given parameters.
245
243
"""
246
244
247
- # Create initial Pod template spec.
245
+ # Create Pod template spec. If the value is None, Pod doesn't have that parameter
248
246
pod_template_spec = models .V1PodTemplateSpec (
249
247
metadata = models .V1ObjectMeta (
250
248
annotations = {constants .ISTIO_SIDECAR_INJECTION : "false" }
251
249
),
252
- spec = models .V1PodSpec (containers = [containers ]),
250
+ spec = models .V1PodSpec (
251
+ init_containers = init_containers ,
252
+ containers = containers ,
253
+ volumes = volumes ,
254
+ ),
253
255
)
254
256
255
- # Assign the rest Pod spec. If the value is None, container doesn't have that spec.
256
- pod_template_spec .spec .init_containers = init_containers
257
- pod_template_spec .spec .volumes = volumes_spec
258
-
259
257
return pod_template_spec
260
258
261
259
0 commit comments