Skip to content

Conversation

jstourac
Copy link
Member

@jstourac jstourac commented Aug 7, 2025

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.

I also added a small logging information.

How Has This Been Tested?

OC_BINARY_PATH=/home/jstourac/Downloads/openshift-client-linux/oc uv run pytest tests/workbenches/notebook-controller/test_spawning.py -v -s

worked on clusters both with and without internal image registry enabled

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Waiting for the #510.

We should then backport this into 2.23 branch at least.

Backports:

@jstourac jstourac self-assigned this Aug 7, 2025
@jstourac jstourac requested a review from a team as a code owner August 7, 2025 12:20
Copy link
Contributor

coderabbitai bot commented Aug 7, 2025

📝 Walkthrough

Summary by CodeRabbit

  • Tests

    • Simplified internal image registry availability check to a boolean for more reliable, faster test setup.
    • Updated dependent test fixtures to consume the new boolean flag.
    • Added logging during test setup to aid debugging when the registry is unavailable.
  • Documentation

    • Refined fixture docstrings to clearly describe behavior and availability determination.
  • Chores

    • Removed unused imports and legacy logic related to the previous registry check approach.

Walkthrough

Refactored the internal_image_registry test fixture to read the OpenShift imageregistry Config "cluster" via DynamicClient and yield a boolean availability flag; updated dependent fixture typing, imports, logging, and exception handling.

Changes

Cohort / File(s) Change Summary
Test fixtures
tests/workbenches/conftest.py
Refactored internal_image_registry to query imageregistry.operator.openshift.io/v1 Config "cluster" and return Generator[bool, None, None]; updated default_notebook to accept internal_image_registry: bool; added module-level LOGGER = get_logger(__name__); removed unused imports (ClusterOperator, Timeout); broadened exception handling (catching ResourceNotFoundError and general Exception) and added logging and a concise docstring.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jstourac jstourac requested a review from jiridanek August 7, 2025 12:24
Copy link

github-actions bot commented Aug 7, 2025

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee
  • Build image based on the PR

Available user actions:

  • To mark a PR as WIP, add /wip in a comment. To remove it from the PR comment /wip cancel to the PR.
  • To block merging of a PR, add /hold in a comment. To un-block merging of PR comment /hold cancel.
  • To mark a PR as approved, add /lgtm in a comment. To remove, add /lgtm cancel.
    lgtm label removed on each new commit push.
  • To mark PR as verified comment /verified to the PR, to un-verify comment /verified cancel to the PR.
    verified label removed on each new commit push.
  • To Cherry-pick a merged PR /cherry-pick <target_branch_name> to the PR. If <target_branch_name> is valid,
    and the current PR is merged, a cherry-picked PR would be created and linked to the current PR.
  • To build and push image to quay, add /build-push-pr-image in a comment. This would create an image with tag
    pr-<pr_number> to quay repository. This image tag, however would be deleted on PR merge or close action.
Supported labels

{'/cherry-pick', '/build-push-pr-image', '/wip', '/verified', '/lgtm', '/hold'}

jiridanek
jiridanek previously approved these changes Aug 7, 2025
@jstourac jstourac enabled auto-merge (rebase) August 7, 2025 16:14
@jstourac jstourac force-pushed the fixWorkbenchRegistry branch 2 times, most recently from ba8e89f to be8a26d Compare August 11, 2025 10:01
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
tests/workbenches/conftest.py (1)

91-96: Bug: invalid image reference when internal registry is disabled.
Else branch builds only a tag (e.g., ":2025.1"), which is not a valid image reference. This will fail image pulls. Use the full minimal_image instead.

     minimal_image_path = (
         f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
         if internal_image_registry
-        else ":" + minimal_image.rsplit(":", maxsplit=1)[1]
+        else minimal_image
     )

If a different external registry is intended, wire its fully qualified reference here instead of a plain tag.

♻️ Duplicate comments (1)
tests/workbenches/conftest.py (1)

50-51: Prefer using the wrapper’s Config resource over raw DynamicClient.
Now that the wrapper supports the imageregistry Config (per earlier discussion), use it instead of dynamic discovery for better typing and readability.

Example (adjust import to your available wrapper class/module):

# from ocp_resources.<imageregistry_config_module> import Config
cfg = Config(client=admin_client, name="cluster")
management_state = str((getattr(cfg.instance, "spec", {}) or {}).get("managementState", "")).lower()
🧹 Nitpick comments (1)
tests/workbenches/conftest.py (1)

17-19: Consolidate constants imports and usage for consistency.
You import Labels directly but still use constants.Labels elsewhere. Suggest switching all uses to the direct Labels import and drop the utilities.constants module import to reduce duplication.

Diff to remove the extra module import:

-from utilities import constants

Outside-of-range change to use the direct Labels import (keeps behavior):

-        label={constants.Labels.OpenDataHub.DASHBOARD: "true"},
+        label={Labels.OpenDataHub.DASHBOARD: "true"},
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5ef556 and be8a26d.

📒 Files selected for processing (1)
  • tests/workbenches/conftest.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
📚 Learning: 2025-06-05T10:05:17.642Z
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.

Applied to files:

  • tests/workbenches/conftest.py
🧬 Code Graph Analysis (1)
tests/workbenches/conftest.py (2)
utilities/constants.py (1)
  • Labels (180-209)
tests/conftest.py (1)
  • admin_client (66-67)
🔇 Additional comments (2)
tests/workbenches/conftest.py (2)

6-6: Good move adopting the shared module logger.
Keeps logging consistent across tests. No issues.

Also applies to: 21-21


74-74: Fixture type update is correct.
Updating default_notebook to accept internal_image_registry: bool matches the refactored fixture. Good.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
tests/workbenches/conftest.py (1)

91-96: Bug: invalid image reference when registry is unavailable

Else branch builds ":{tag}" (e.g., ":2025.1"), which is not a valid container image reference. Use the imagestream/tag value (minimal_image) instead.

-    minimal_image_path = (
-        f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
-        if internal_image_registry
-        else ":" + minimal_image.rsplit(":", maxsplit=1)[1]
-    )
+    minimal_image_path = (
+        f"{INTERNAL_IMAGE_REGISTRY_PATH}/{py_config['applications_namespace']}/{minimal_image}"
+        if internal_image_registry
+        else minimal_image
+    )
♻️ Duplicate comments (2)
tests/workbenches/conftest.py (2)

46-52: Prefer openshift-python-wrapper resource over raw DynamicClient (once available)

Per prior review, wrapper support for imageregistry Config landed; consider switching to the wrapper resource (Config(name="cluster")) for consistency and stronger typing once a release is available.


53-60: Harden spec extraction and tighten exception handling

Avoid AttributeError if spec is missing and log stack traces on unexpected errors.

Apply:

-        management_state = config_instance.spec.get("managementState", "").lower()
-        is_available = management_state == "managed"
-
-        LOGGER.info(f"Image registry management state: {management_state}, available: {is_available}")
-        yield is_available
-    except (ResourceNotFoundError, Exception) as e:
-        LOGGER.warning(f"Failed to check image registry config: {e}")
-        yield False
+        spec = getattr(config_instance, "spec", None) or {}
+        management_state = str(spec.get("managementState", "")).lower()
+        is_available = management_state == "managed"
+
+        LOGGER.info(f"Image registry management state: {management_state}, available: {is_available}")
+        yield is_available
+    except ResourceNotFoundError as e:
+        LOGGER.warning(f"Image registry config not found: {e}")
+        yield False
+    except Exception:
+        LOGGER.exception("Failed to check image registry config")
+        yield False
🧹 Nitpick comments (1)
tests/workbenches/conftest.py (1)

17-17: Use Labels consistently (avoid mixed imports)

You now import Labels directly but still reference constants.Labels elsewhere. Consider standardizing on one style for consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be8a26d and 6a9dc1e.

📒 Files selected for processing (1)
  • tests/workbenches/conftest.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
📚 Learning: 2025-06-05T10:05:17.642Z
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.

Applied to files:

  • tests/workbenches/conftest.py
🧬 Code Graph Analysis (1)
tests/workbenches/conftest.py (2)
utilities/constants.py (1)
  • Labels (180-209)
tests/conftest.py (1)
  • admin_client (66-67)
🔇 Additional comments (4)
tests/workbenches/conftest.py (4)

6-6: Logger import LGTM

Using simple_logger’s get_logger aligns with project conventions.


21-21: Module-level LOGGER initialization LGTM

Good addition; keeps log statements consistent and contextual.


74-75: Param type update in default_notebook LGTM

Matches the fixture’s new boolean contract.


43-45: internal_image_registry fixture usage verified
All downstream references have been updated to expect a bool, and no tests or type hints remain targeting the old resource object. No further changes required.

• tests/workbenches/conftest.py: lines 74, 94–96

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.
@jstourac jstourac force-pushed the fixWorkbenchRegistry branch from 6a9dc1e to bcbe77d Compare August 11, 2025 20:28
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (3)
tests/workbenches/conftest.py (3)

6-6: Good switch to module-level LOGGER via simple_logger.

Resolves the prior suggestion to standardize logging.

Also applies to: 22-22


16-16: Correct usage of the ocp_resources wrapper for imageregistry Config.

Using Config(name="cluster") from the wrapper is the right approach and aligns with prior feedback.


47-57: Fix spec extraction (AttributeError risk) and tighten exception handling.

config_instance.instance.spec is a ResourceInstance field, not a dict; calling .get will likely raise AttributeError. Also, split exception handling and log stack traces for unexpected errors.

Apply:

-        # Access the imageregistry.operator.openshift.io/v1 Config resource named "cluster"
-        config_instance = Config(client=admin_client, name="cluster")
-
-        management_state = config_instance.instance.spec.get("managementState", "").lower()
-        is_available = management_state == "managed"
-
-        LOGGER.info(f"Image registry management state: {management_state}, available: {is_available}")
-        yield is_available
-    except (ResourceNotFoundError, Exception) as e:
-        LOGGER.warning(f"Failed to check image registry config: {e}")
-        yield False
+        # Access the imageregistry.operator.openshift.io/v1 Config resource named "cluster"
+        config_instance = Config(client=admin_client, name="cluster")
+
+        # Ensure the resource exists and safely extract spec
+        if not config_instance.exists:
+            LOGGER.warning("Image registry Config 'cluster' not found")
+            yield False
+            return
+
+        cfg = getattr(getattr(config_instance, "instance", None), "to_dict", lambda: {})()
+        spec = (cfg or {}).get("spec", {}) or {}
+        management_state = str(spec.get("managementState", "")).lower()
+        is_available = management_state == "managed"
+
+        LOGGER.info(f"Image registry management state: {management_state}, available: {is_available}")
+        yield is_available
+    except ResourceNotFoundError as e:
+        LOGGER.warning(f"Image registry config not found: {e}")
+        yield False
+    except Exception:
+        # Include stack trace for unexpected failures
+        LOGGER.exception("Failed to check image registry config")
+        yield False
🧹 Nitpick comments (1)
tests/workbenches/conftest.py (1)

18-18: Consistency nit: unify Labels import usage across the file.

You import Labels directly but still reference constants.Labels elsewhere. Pick one style for readability (prefer the direct Labels import).

Example change outside this hunk:

  • Line 33: replace constants.Labels.OpenDataHub.DASHBOARD with Labels.OpenDataHub.DASHBOARD
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a9dc1e and bcbe77d.

📒 Files selected for processing (1)
  • tests/workbenches/conftest.py (4 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.
📚 Learning: 2025-06-05T10:05:17.642Z
Learnt from: adolfo-ab
PR: opendatahub-io/opendatahub-tests#334
File: tests/model_explainability/trustyai_service/test_trustyai_service.py:52-65
Timestamp: 2025-06-05T10:05:17.642Z
Learning: For TrustyAI image validation tests: operator image tests require admin_client, related_images_refs, and trustyai_operator_configmap fixtures, while service image tests would require different fixtures like trustyai_service_with_pvc_storage, model_namespace, and current_client_token.

Applied to files:

  • tests/workbenches/conftest.py
🔇 Additional comments (2)
tests/workbenches/conftest.py (2)

71-73: Consumer fixture signature updated to bool — LGTM.

default_notebook now depends on a boolean flag. This aligns with the new internal_image_registry contract.


44-46: internal_image_registry fixture returns bool – all call sites align
Verified that internal_image_registry is only used as a boolean in tests/workbenches/conftest.py (e.g. if internal_image_registry) and no attribute‐style calls remain. Approving the change.

@jstourac
Copy link
Member Author

ready for another review round, thanks guys!

@jstourac jstourac disabled auto-merge August 12, 2025 17:48
@jstourac jstourac merged commit 7f7f1ed into opendatahub-io:main Aug 12, 2025
11 checks passed
Copy link

Status of building tag latest: success.
Status of pushing tag latest to image registry: success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants