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 to_dict(self): dt = OrderedDict() if utils.non_empty(self.nameservers): dt.update({"nameservers": self.nameservers}) if utils.non_empty(self.options): dt.update({"options": self.get_options_to_dict()}) if utils.non_empty(self.searches): dt.update({"searches": self.searches}) return dt
def to_dict(self): d = OrderedDict({"name": self.name}) if self.template is not None: d.update({"template": self.template}) if self.when is not None: d.update({"when": self.when}) if utils.non_empty(self.arguments): d.update({"arguments": self.arguments}) if utils.non_empty(self.with_items): d.update({"withItems": self.with_items}) return d
def to_dict(self): template = Template.to_dict(self) if utils.non_empty(self.args): template["inputs"] = {"parameters": self.args} template["resource"] = self.resource_dict() # Append outputs to this template # return the resource job name, job ID, and job object by default job_outputs = [ OrderedDict({ "name": "job-name", "valueFrom": { "jsonPath": '"{.metadata.name}"' }, }), OrderedDict({ "name": "job-id", "valueFrom": { "jsonPath": '"{.metadata.uid}"' }, }), OrderedDict({ "name": "job-obj", "valueFrom": { "jqFilter": '"."' } }), ] template["outputs"] = {"parameters": job_outputs} return template
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 test_non_empty(self): self.assertFalse(utils.non_empty(None)) self.assertFalse(utils.non_empty([])) self.assertFalse(utils.non_empty({})) self.assertTrue(utils.non_empty(["a"])) self.assertTrue(utils.non_empty({"a": "b"}))