From 8d2f85709bee3d55e60c7a45a9c794838683a453 Mon Sep 17 00:00:00 2001 From: urihoenig Date: Thu, 10 Dec 2020 00:38:44 +0200 Subject: [PATCH] [Builder] Support extra & verbose flags (#586) --- mlrun/builder.py | 2 ++ mlrun/model.py | 2 ++ mlrun/run.py | 1 + mlrun/runtimes/base.py | 2 +- mlrun/runtimes/kubejob.py | 19 ++++++++++++++++--- mlrun/runtimes/sparkjob.py | 6 +++++- tests/runtimes/test_run.py | 3 +++ 7 files changed, 30 insertions(+), 5 deletions(-) diff --git a/mlrun/builder.py b/mlrun/builder.py index e66dbd41e07..c6fecfc66e0 100644 --- a/mlrun/builder.py +++ b/mlrun/builder.py @@ -262,6 +262,8 @@ def build_runtime(runtime, with_mlrun, interactive=False): interactive=interactive, name=name, with_mlrun=with_mlrun, + extra=build.extra, + verbose=runtime.verbose, ) runtime.status.build_pod = None if status == "skipped": diff --git a/mlrun/model.py b/mlrun/model.py index 1370aedfa24..037db928bff 100644 --- a/mlrun/model.py +++ b/mlrun/model.py @@ -274,6 +274,7 @@ def __init__( image=None, base_image=None, commands=None, + extra=None, secret=None, code_origin=None, registry=None, @@ -285,6 +286,7 @@ def __init__( self.image = image #: image self.base_image = base_image #: base_image self.commands = commands or [] #: commands + self.extra = extra #: extra self.secret = secret #: secret self.registry = registry #: registry self.build_pod = None diff --git a/mlrun/run.py b/mlrun/run.py index d9e3ddae504..bdbbd6b6948 100644 --- a/mlrun/run.py +++ b/mlrun/run.py @@ -684,6 +684,7 @@ def resolve_nuclio_subkind(kind): build.code_origin = code_origin build.base_image = get_in(spec, "spec.build.baseImage") build.commands = get_in(spec, "spec.build.commands") + build.extra = get_in(spec, "spec.build.extra") if embed_code: build.functionSourceCode = get_in(spec, "spec.build.functionSourceCode") else: diff --git a/mlrun/runtimes/base.py b/mlrun/runtimes/base.py index dfb2e9a3f28..11f6409f5b5 100644 --- a/mlrun/runtimes/base.py +++ b/mlrun/runtimes/base.py @@ -123,7 +123,7 @@ class BaseRuntime(ModelObj): kind = "base" _is_nested = False _is_remote = False - _dict_fields = ["kind", "metadata", "spec", "status"] + _dict_fields = ["kind", "metadata", "spec", "status", "verbose"] def __init__(self, metadata=None, spec=None): self._metadata = None diff --git a/mlrun/runtimes/kubejob.py b/mlrun/runtimes/kubejob.py index 5a736691f50..b3c6898aae4 100644 --- a/mlrun/runtimes/kubejob.py +++ b/mlrun/runtimes/kubejob.py @@ -80,7 +80,13 @@ def is_deployed(self): return False def build_config( - self, image="", base_image=None, commands: list = None, secret=None, source=None + self, + image="", + base_image=None, + commands: list = None, + secret=None, + source=None, + extra=None, ): if image: self.spec.build.image = image @@ -89,6 +95,8 @@ def build_config( raise ValueError("commands must be a string list") self.spec.build.commands = self.spec.build.commands or [] self.spec.build.commands += commands + if extra: + self.spec.build.extra = extra if secret: self.spec.build.secret = secret if base_image: @@ -108,7 +116,12 @@ def deploy(self, watch=True, with_mlrun=True, skip_deployed=False, is_kfp=False) return True build = self.spec.build - if not build.source and not build.commands and not with_mlrun: + if ( + not build.source + and not build.commands + and not build.extra + and not with_mlrun + ): if not self.spec.image: raise ValueError( "noting to build and image is not specified, " @@ -118,7 +131,7 @@ def deploy(self, watch=True, with_mlrun=True, skip_deployed=False, is_kfp=False) self.save(versioned=False) return True - if not build.source and not build.commands and with_mlrun: + if not build.source and not build.commands and not build.extra and with_mlrun: logger.info( "running build to add mlrun package, set " "with_mlrun=False to skip if its already in the image" diff --git a/mlrun/runtimes/sparkjob.py b/mlrun/runtimes/sparkjob.py index 4e21f98f409..ea200af393c 100644 --- a/mlrun/runtimes/sparkjob.py +++ b/mlrun/runtimes/sparkjob.py @@ -462,7 +462,11 @@ def _get_driver(self, name, namespace=None): @property def is_deployed(self): - if not self.spec.build.source and not self.spec.build.commands: + if ( + not self.spec.build.source + and not self.spec.build.commands + and not self.spec.build.extra + ): return True return super().is_deployed diff --git a/tests/runtimes/test_run.py b/tests/runtimes/test_run.py index e432c6c8cd9..e5434a1be8b 100644 --- a/tests/runtimes/test_run.py +++ b/tests/runtimes/test_run.py @@ -29,7 +29,9 @@ def test_new_function_from_runtime(): "description": "", "build": {"commands": []}, }, + "verbose": False, } + function = mlrun.new_function(runtime=runtime) assert DeepDiff(runtime, function.to_dict(), ignore_order=True,) == {} @@ -60,6 +62,7 @@ def test_new_function_args_without_command(): "description": "", "build": {"commands": []}, }, + "verbose": False, } function = mlrun.new_function(runtime=runtime) assert DeepDiff(runtime, function.to_dict(), ignore_order=True,) == {}