Skip to content

Commit

Permalink
[Function] Validate tag name before deploying (#5705)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerShor committed Jun 4, 2024
1 parent 40986af commit 91cecf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mlrun/runtimes/nuclio/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ def status(self, status):
self._status = self._verify_dict(status, "status", NuclioStatus)

def pre_deploy_validation(self):
pass
if self.metadata.tag:
mlrun.utils.validate_tag_name(self.metadata.tag, "function.metadata.tag")

def set_config(self, key, value):
self.spec.config[key] = value
Expand Down
15 changes: 15 additions & 0 deletions tests/runtimes/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from deepdiff import DeepDiff

import mlrun
import mlrun.errors
from mlrun import code_to_function
from mlrun.utils.helpers import resolve_git_reference_from_source
from tests.runtimes.test_base import TestAutoMount
Expand Down Expand Up @@ -204,3 +205,17 @@ def test_update_credentials_from_remote_build(function_kind):

assert function.metadata.credentials.access_key == secret_name
assert function.spec.env == remote_data["spec"]["env"]


@pytest.mark.parametrize(
"tag,expected",
[
("valid_tag", does_not_raise()),
("invalid%$tag", pytest.raises(mlrun.errors.MLRunInvalidArgumentError)),
("too-long-tag" * 10, pytest.raises(mlrun.errors.MLRunInvalidArgumentError)),
],
)
def test_invalid_tags(tag, expected, rundb_mock):
function = mlrun.new_function("test", kind="nuclio", tag=tag)
with expected:
function.pre_deploy_validation()

0 comments on commit 91cecf8

Please sign in to comment.