Skip to content

Commit 346edbc

Browse files
authored
Add labels and annotations to ProjectRequest and Namespace (opendatahub-io#184)
* Create size-labeler.yml * Delete .github/workflows/size-labeler.yml * model mesh - add auth tests * xx * feat: unpri and ns refactor * feat: unpri and ns refactor * fix: update imports * fix: address comment
1 parent 059d898 commit 346edbc

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

tests/conftest.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def model_namespace(request: FixtureRequest, admin_client: DynamicClient) -> Gen
5656

5757
if request.param.get("modelmesh-enabled"):
5858
request.getfixturevalue(argname="enabled_modelmesh_in_dsc")
59-
ns_kwargs["labels"] = {"modelmesh-enabled": "true"}
59+
ns_kwargs["model_mesh_enabled"] = True
6060

6161
with create_ns(**ns_kwargs) as ns:
6262
yield ns
@@ -286,3 +286,23 @@ def cluster_monitoring_config(admin_client: DynamicClient) -> Generator[ConfigMa
286286
data=data,
287287
) as cm:
288288
yield cm
289+
290+
291+
@pytest.fixture(scope="class")
292+
def unprivileged_model_namespace(
293+
request: FixtureRequest, unprivileged_client: DynamicClient
294+
) -> Generator[Namespace, Any, Any]:
295+
ns_kwargs = {
296+
"name": request.param["name"],
297+
"unprivileged_client": unprivileged_client,
298+
}
299+
300+
if _annotations := request.param.get("annotations"):
301+
ns_kwargs["ns_annotations"] = _annotations
302+
303+
if request.param.get("modelmesh-enabled"):
304+
request.getfixturevalue(argname="enabled_modelmesh_in_dsc")
305+
ns_kwargs["model_mesh_enabled"] = True
306+
307+
with create_ns(**ns_kwargs) as ns:
308+
yield ns

tests/model_serving/model_server/authentication/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from utilities.inference_utils import create_isvc
1717
from utilities.infra import (
18-
create_ns,
1918
create_isvc_view_role,
2019
get_pods_by_isvc_label,
2120
s3_endpoint_secret,
@@ -329,12 +328,6 @@ def http_s3_caikit_raw_inference_service_2(
329328

330329

331330
# Unprivileged user tests
332-
@pytest.fixture(scope="class")
333-
def unprivileged_model_namespace(
334-
request: FixtureRequest, unprivileged_client: DynamicClient
335-
) -> Generator[Namespace, Any, Any]:
336-
with create_ns(unprivileged_client=unprivileged_client, name=request.param["name"]) as ns:
337-
yield ns
338331

339332

340333
@pytest.fixture(scope="class")

tests/model_serving/model_server/upgrade/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ def model_namespace_scope_session(
5656
admin_client: DynamicClient,
5757
) -> Generator[Namespace, Any, Any]:
5858
with create_ns(
59-
admin_client=admin_client,
60-
name=UPGRADE_NAMESPACE,
61-
labels={"modelmesh-enabled": "true"},
59+
admin_client=admin_client, name=UPGRADE_NAMESPACE, model_mesh_enabled=True, add_dashboard_label=True
6260
) as ns:
6361
yield ns
6462

utilities/infra.py

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from semver import Version
3434
from simple_logger.logger import get_logger
3535

36-
from utilities.constants import Timeout
36+
from utilities.constants import Labels, Timeout
3737
from utilities.exceptions import FailedPodsError
3838
from timeout_sampler import TimeoutExpiredError, TimeoutSampler
3939
from utilities.general import create_isvc_label_selector_str, get_s3_secret_dict
@@ -44,11 +44,14 @@
4444
@contextmanager
4545
def create_ns(
4646
name: str,
47-
admin_client: Optional[DynamicClient] = None,
48-
unprivileged_client: Optional[DynamicClient] = None,
47+
admin_client: DynamicClient | None = None,
48+
unprivileged_client: DynamicClient | None = None,
4949
teardown: bool = True,
5050
delete_timeout: int = Timeout.TIMEOUT_4MIN,
51-
labels: Optional[dict[str, str]] = None,
51+
labels: dict[str, str] | None = None,
52+
ns_annotations: dict[str, str] | None = None,
53+
model_mesh_enabled: bool = False,
54+
add_dashboard_label: bool = False,
5255
) -> Generator[Namespace | Project, Any, Any]:
5356
"""
5457
Create namespace with admin or unprivileged client.
@@ -60,30 +63,39 @@ def create_ns(
6063
teardown (bool): should run resource teardown
6164
delete_timeout (int): delete timeout.
6265
labels (dict[str, str]): labels dict to set for namespace
66+
ns_annotations (dict[str, str]): annotations dict to set for namespace
67+
model_mesh_enabled (bool): if True, model mesh will be enabled in namespace
68+
add_dashboard_label (bool): if True, dashboard label will be added to namespace
6369
6470
Yields:
6571
Namespace | Project: namespace or project
6672
6773
"""
74+
namespace_kwargs = {
75+
"name": name,
76+
"client": admin_client,
77+
"teardown": teardown,
78+
"delete_timeout": delete_timeout,
79+
"label": labels or {},
80+
}
81+
82+
if ns_annotations:
83+
namespace_kwargs["annotations"] = ns_annotations
84+
85+
if model_mesh_enabled:
86+
namespace_kwargs["label"]["modelmesh-enabled"] = "true" # type: ignore
87+
88+
if add_dashboard_label:
89+
namespace_kwargs["label"][Labels.OpenDataHub.DASHBOARD] = "true" # type: ignore
90+
6891
if unprivileged_client:
6992
with ProjectRequest(name=name, client=unprivileged_client, teardown=teardown):
70-
project = Project(
71-
name=name,
72-
client=unprivileged_client,
73-
teardown=teardown,
74-
delete_timeout=delete_timeout,
75-
)
93+
project = Project(**namespace_kwargs)
7694
project.wait_for_status(status=project.Status.ACTIVE, timeout=Timeout.TIMEOUT_2MIN)
7795
yield project
7896

7997
else:
80-
with Namespace(
81-
client=admin_client,
82-
name=name,
83-
label=labels,
84-
teardown=teardown,
85-
delete_timeout=delete_timeout,
86-
) as ns:
98+
with Namespace(**namespace_kwargs) as ns:
8799
ns.wait_for_status(status=Namespace.Status.ACTIVE, timeout=Timeout.TIMEOUT_2MIN)
88100
yield ns
89101

0 commit comments

Comments
 (0)