Skip to content

Commit

Permalink
Fix missing args when instantiating function from runtime (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedingber committed Oct 22, 2020
1 parent c576a3b commit 377db0c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mlrun/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ def new_function(
:return: function object
"""
# don't override given dict
if runtime and isinstance(runtime, dict):
runtime = deepcopy(runtime)
kind, runtime = _process_runtime(command, runtime, kind)
command = get_in(runtime, "spec.command", command)
name = name or get_in(runtime, "metadata.name", "")
Expand Down Expand Up @@ -509,6 +512,9 @@ def _process_runtime(command, runtime, kind):
if runtime and isinstance(runtime, dict):
kind = kind or runtime.get("kind", "")
command = command or get_in(runtime, "spec.command", "")
runtime_args = get_in(runtime, "spec.args", [])
if runtime_args:
command = f"{command} {' '.join(runtime_args)}"
if "://" in command and command.startswith("http"):
kind = kind or RuntimeKinds.remote
if not runtime:
Expand Down
34 changes: 34 additions & 0 deletions tests/runtimes/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from deepdiff import DeepDiff

import mlrun


def test_new_function_from_runtime():
runtime = {
"kind": "job",
"metadata": {
"name": "spark-submit",
"project": "default",
"categories": [],
"tag": "",
"hash": "7b3064c6b334535a5d949ebe9cfc61a094f98c78",
"updated": "2020-10-21T22:40:35.042132+00:00",
},
"spec": {
"command": "spark-submit",
"args": [
"--class",
"org.apache.spark.examples.SparkPi",
"/spark/examples/jars/spark-examples_2.11-2.4.4.jar",
],
"image": "iguazio/shell:3.0_b5533_20201020062229",
"mode": "pass",
"volumes": [],
"volume_mounts": [],
"env": [],
"description": "",
"build": {"commands": []},
},
}
function = mlrun.new_function(runtime=runtime)
assert DeepDiff(runtime, function.to_dict(), ignore_order=True,) == {}

0 comments on commit 377db0c

Please sign in to comment.