Skip to content

Commit

Permalink
[SDK] Support string values in min/max replicas (#2606)
Browse files Browse the repository at this point in the history
* Support string values

* Support string values

* Add as_number helper
  • Loading branch information
GiladShapira94 committed Nov 22, 2022
1 parent 9c1b8c5 commit edc00df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 17 additions & 5 deletions mlrun/runtimes/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from ..lists import RunList
from ..model import RunObject
from ..platforms.iguazio import mount_v3io, parse_path, split_path, v3io_cred
from ..utils import enrich_image_url, get_in, logger, update_in
from ..utils import as_number, enrich_image_url, get_in, logger, update_in
from .base import FunctionStatus, RunError
from .constants import NuclioIngressAddTemplatedIngressModes
from .pod import KubeResource, KubeResourceSpec
Expand Down Expand Up @@ -1276,11 +1276,23 @@ def compile_function_config(
)

if function.spec.replicas:
nuclio_spec.set_config("spec.minReplicas", function.spec.replicas)
nuclio_spec.set_config("spec.maxReplicas", function.spec.replicas)

nuclio_spec.set_config(
"spec.minReplicas", as_number("spec.Replicas", function.spec.replicas)
)
nuclio_spec.set_config(
"spec.maxReplicas", as_number("spec.Replicas", function.spec.replicas)
)

else:
nuclio_spec.set_config("spec.minReplicas", function.spec.min_replicas)
nuclio_spec.set_config("spec.maxReplicas", function.spec.max_replicas)
nuclio_spec.set_config(
"spec.minReplicas",
as_number("spec.minReplicas", function.spec.min_replicas),
)
nuclio_spec.set_config(
"spec.maxReplicas",
as_number("spec.maxReplicas", function.spec.max_replicas),
)

if function.spec.service_account:
nuclio_spec.set_config("spec.serviceAccount", function.spec.service_account)
Expand Down
6 changes: 6 additions & 0 deletions mlrun/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,3 +1100,9 @@ def is_relative_path(path):
if not path:
return False
return not (path.startswith("/") or ":\\" in path or "://" in path)


def as_number(field_name, field_value):
if isinstance(field_value, str) and not field_value.isnumeric():
raise ValueError(f"{field_name} must be numeric (str/int types)")
return int(field_value)

0 comments on commit edc00df

Please sign in to comment.