Skip to content

Commit aa266bf

Browse files
committed
RHOAIENG-22057: fix(workbenches): check for internal image registry and adjust the image path accordingly
1 parent 0b19568 commit aa266bf

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

tests/workbenches/conftest.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
from ocp_resources.persistent_volume_claim import PersistentVolumeClaim
1414
from ocp_resources.route import Route
1515
from ocp_resources.notebook import Notebook
16+
from ocp_resources.cluster_operator import ClusterOperator
1617

1718

18-
from utilities.constants import Labels
19+
from utilities.constants import Labels, Timeout
1920
from utilities import constants
2021
from utilities.constants import INTERNAL_IMAGE_REGISTRY_PATH
2122

@@ -36,17 +37,38 @@ def users_persistent_volume_claim(
3637
yield pvc
3738

3839

40+
@pytest.fixture(scope="function")
41+
def internal_image_registry(
42+
admin_client: DynamicClient,
43+
) -> Generator[ClusterOperator | None, None, None]:
44+
try:
45+
image_registry = ClusterOperator(
46+
client=admin_client,
47+
name="image-registry",
48+
ensure_exists=True,
49+
)
50+
image_registry.wait_for_condition(
51+
condition=ClusterOperator.Condition.AVAILABLE,
52+
status=ClusterOperator.Condition.Status.TRUE,
53+
timeout=Timeout.TIMEOUT_30SEC,
54+
)
55+
yield image_registry
56+
except ResourceNotFoundError:
57+
yield None
58+
59+
3960
@pytest.fixture(scope="function")
4061
def minimal_image() -> Generator[str, None, None]:
4162
"""Provides a full image name of a minimal workbench image"""
4263
image_name = "jupyter-minimal-notebook" if py_config.get("distribution") == "upstream" else "s2i-minimal-notebook"
43-
yield f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{image_name}:{'2024.2'}"
64+
yield f"{image_name}:{'2024.2'}"
4465

4566

4667
@pytest.fixture(scope="function")
4768
def default_notebook(
4869
request: pytest.FixtureRequest,
4970
admin_client: DynamicClient,
71+
internal_image_registry: ClusterOperator | None,
5072
minimal_image: str,
5173
) -> Generator[Notebook, None, None]:
5274
"""Returns a new Notebook CR for a given namespace, name, and image"""
@@ -62,6 +84,13 @@ def default_notebook(
6284
# Set the correct username
6385
username = get_username(dyn_client=admin_client)
6486

87+
# Set the image path based on internal image registry status
88+
minimal_image_path = (
89+
f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
90+
if internal_image_registry
91+
else ":" + minimal_image.rsplit(":", maxsplit=1)[1]
92+
)
93+
6594
probe_config = {
6695
"failureThreshold": 3,
6796
"httpGet": {
@@ -83,6 +112,7 @@ def default_notebook(
83112
"notebooks.opendatahub.io/inject-oauth": "true",
84113
"opendatahub.io/accelerator-name": "",
85114
"opendatahub.io/service-mesh": "false",
115+
"notebooks.opendatahub.io/last-image-selection": minimal_image,
86116
},
87117
"labels": {
88118
Labels.Openshift.APP: name,
@@ -114,9 +144,9 @@ def default_notebook(
114144
" "
115145
f'--ServerApp.tornado_settings={{"user":"{username}","hub_host":"https://{route.host}","hub_prefix":"/projects/{namespace}"}}', # noqa: E501 line too long
116146
},
117-
{"name": "JUPYTER_IMAGE", "value": minimal_image},
147+
{"name": "JUPYTER_IMAGE", "value": minimal_image_path},
118148
],
119-
"image": minimal_image,
149+
"image": minimal_image_path,
120150
"imagePullPolicy": "Always",
121151
"livenessProbe": probe_config,
122152
"name": name,

0 commit comments

Comments
 (0)