Skip to content

Commit 7f7f1ed

Browse files
committed
fix(workbenches): the way we check internal image registry state
The original method wasn't reliable for our infrastructure as we have the imageregistry ClusterOperator present in all our clusters by default. What differs is the actual management status of them, so this new approach should work fine for us now.
1 parent 4d32559 commit 7f7f1ed

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

tests/workbenches/conftest.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from pytest_testconfig import config as py_config
55

6-
6+
from simple_logger.logger import get_logger
77
from tests.workbenches.utils import get_username
88

99
from kubernetes.dynamic import DynamicClient
@@ -13,13 +13,14 @@
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
17-
16+
from ocp_resources.config_imageregistry_operator_openshift_io import Config
1817

19-
from utilities.constants import Labels, Timeout
18+
from utilities.constants import Labels
2019
from utilities import constants
2120
from utilities.constants import INTERNAL_IMAGE_REGISTRY_PATH
2221

22+
LOGGER = get_logger(name=__name__)
23+
2324

2425
@pytest.fixture(scope="function")
2526
def users_persistent_volume_claim(
@@ -40,21 +41,20 @@ def users_persistent_volume_claim(
4041
@pytest.fixture(scope="function")
4142
def internal_image_registry(
4243
admin_client: DynamicClient,
43-
) -> Generator[ClusterOperator | None, None, None]:
44+
) -> Generator[bool, None, None]:
45+
"""Check if internal image registry is available by checking the imageregistry config managementState"""
4446
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
47+
# Access the imageregistry.operator.openshift.io/v1 Config resource named "cluster"
48+
config_instance = Config(client=admin_client, name="cluster")
49+
50+
management_state = config_instance.instance.spec.get("managementState", "").lower()
51+
is_available = management_state == "managed"
52+
53+
LOGGER.info(f"Image registry management state: {management_state}, available: {is_available}")
54+
yield is_available
55+
except (ResourceNotFoundError, Exception) as e:
56+
LOGGER.warning(f"Failed to check image registry config: {e}")
57+
yield False
5858

5959

6060
@pytest.fixture(scope="function")
@@ -68,7 +68,7 @@ def minimal_image() -> Generator[str, None, None]:
6868
def default_notebook(
6969
request: pytest.FixtureRequest,
7070
admin_client: DynamicClient,
71-
internal_image_registry: ClusterOperator | None,
71+
internal_image_registry: bool,
7272
minimal_image: str,
7373
) -> Generator[Notebook, None, None]:
7474
"""Returns a new Notebook CR for a given namespace, name, and image"""

0 commit comments

Comments
 (0)