def container_dict(self): # Container part container = OrderedDict({"image": self.image, "command": self.command}) if utils.non_empty(self.args): container["args"] = self._convert_args_to_input_parameters( self.args) if utils.non_empty(self.env): container["env"] = utils.convert_dict_to_env_list(self.env) if self.secret is not None: if not isinstance(self.secret, Secret): raise ValueError( "Parameter secret should be an instance of Secret") if self.env is None: container["env"] = self.secret.to_env_list() else: container["env"].extend(self.secret.to_env_list()) if self.resources is not None: container["resources"] = { "requests": self.resources, # To fix the mojibake issue when dump yaml for one object "limits": copy.deepcopy(self.resources), } if self.image_pull_policy is not None: container["imagePullPolicy"] = utils.config_image_pull_policy( self.image_pull_policy) if self.volume_mounts is not None: container["volumeMounts"] = [ vm.to_dict() for vm in self.volume_mounts ] if self.working_dir is not None: container["workingDir"] = self.working_dir return container
def script_dict(self): script = OrderedDict({"image": self.image, "command": [self.command]}) source_code_string = None if callable(self.source): source_code_string = utils.body(self.source) elif isinstance(self.source, str): source_code_string = self.source else: raise ValueError("unsupported source code type: %s" % type(self.source)) script["source"] = (source_code_string if self.command.lower() == "python" else self.source) if utils.non_empty(self.env): script["env"] = utils.convert_dict_to_env_list(self.env) if self.secret is not None: if not isinstance(self.secret, Secret): raise ValueError( "Parameter secret should be an instance of Secret") if self.env is None: script["env"] = self.secret.to_env_list() else: script["env"].extend(self.secret.to_env_list()) if self.resources is not None: script["resources"] = { "requests": self.resources, # To fix the mojibake issue when dump yaml for one object "limits": copy.deepcopy(self.resources), } if self.image_pull_policy is not None: script["imagePullPolicy"] = utils.config_image_pull_policy( self.image_pull_policy) return script
def _verify_script_body(self, script_to_check, image, command, source, env): if env is None: env = utils.convert_dict_to_env_list({ "NVIDIA_VISIBLE_DEVICES": "", "NVIDIA_DRIVER_CAPABILITIES": "", }) else: env.append( utils.convert_dict_to_env_list({ "NVIDIA_VISIBLE_DEVICES": "", "NVIDIA_DRIVER_CAPABILITIES": "", })) self.assertEqual(script_to_check.get("image", None), image) self.assertEqual(script_to_check.get("command", None), command) self.assertEqual(script_to_check.get("source", None), source) self.assertEqual(script_to_check.get("env", None), env)