Skip to content

Add tests to verify pull secrets are updated correctly for rawdeployment#281

Merged
mwaykole merged 2 commits intoopendatahub-io:mainfrom
VedantMahabaleshwarkar:j-19717
May 9, 2025
Merged

Add tests to verify pull secrets are updated correctly for rawdeployment#281
mwaykole merged 2 commits intoopendatahub-io:mainfrom
VedantMahabaleshwarkar:j-19717

Conversation

@VedantMahabaleshwarkar
Copy link
Copy Markdown
Contributor

@VedantMahabaleshwarkar VedantMahabaleshwarkar commented Apr 29, 2025

Description

Adds tests for JIRAs : https://issues.redhat.com//browse/RHOAIENG-19717 , https://issues.redhat.com/browse/RHOAIENG-20331 which have the same rootcause

How Has This Been Tested?

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

Summary by CodeRabbit

  • New Features

    • Added tests to verify setting, updating, and removing image pull secrets for inference services in a Kubernetes environment.
    • Enhanced inference service creation to support specifying image pull secrets.
  • Tests

    • Introduced fixtures and utilities to support image pull secret management in test scenarios.
    • Added a new test suite to ensure correct handling of image pull secrets in inference service pods.
  • Chores

    • Added constants for original and updated pull secrets to support testing.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 29, 2025

Walkthrough

This update introduces and tests support for managing image pull secrets in Kubernetes inference services. New constants for original and updated pull secrets are defined. Pytest fixtures are added to set up inference services with, update, and remove image pull secrets. A utility function is introduced to verify the presence or absence of image pull secrets in inference service pods. Tests are implemented to check the correct setting, updating, and removal of pull secrets. Additionally, the inference service creation utility is updated to accept image pull secrets as an optional parameter.

Changes

File(s) Change Summary
tests/model_serving/model_server/inference_service_configuration/conftest.py Added pytest fixtures for creating, updating, and removing image pull secrets in inference services.
tests/model_serving/model_server/inference_service_configuration/constants.py Added two string constants: ORIGINAL_PULL_SECRET and UPDATED_PULL_SECRET.
tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py Added a new test class with tests for pull secret set, update, and removal in inference services.
tests/model_serving/model_server/inference_service_configuration/utils.py Added verify_pull_secret function to check image pull secret presence in inference service pods.
utilities/inference_utils.py Updated create_isvc function to accept optional image_pull_secrets parameter and handle it in predictor.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test
    participant Fixture as Pytest Fixture
    participant ISVC as InferenceService
    participant Utils as verify_pull_secret
    participant K8s as Kubernetes Pod

    Test->>Fixture: Request ISVC with pull secret
    Fixture->>ISVC: Create/Update ISVC (with/without pull secret)
    ISVC->>K8s: Deploy pod with imagePullSecrets
    Test->>Utils: verify_pull_secret(ISVC, pull_secret, secret_exists)
    Utils->>K8s: Retrieve pod spec
    Utils-->>Test: Assert presence/absence of pull secret
Loading

Poem

In the warren of code, a secret appears,
Pull secrets for images, now handled with cheers!
Fixtures are hopping, tests leap with delight,
Verifying secrets are tucked in just right.
With carrots in paw, this rabbit will say:
Secure pods are ready—hip hop hooray!
🥕🐇

Suggested labels

lgtm-by-rnetser, lgtm-by-adolfo-ab, lgtm-by-dbasunag


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e1746e and 79e9e3e.

📒 Files selected for processing (5)
  • tests/model_serving/model_server/inference_service_configuration/conftest.py (2 hunks)
  • tests/model_serving/model_server/inference_service_configuration/constants.py (1 hunks)
  • tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py (1 hunks)
  • tests/model_serving/model_server/inference_service_configuration/utils.py (1 hunks)
  • utilities/inference_utils.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/model_serving/model_server/inference_service_configuration/constants.py
  • tests/model_serving/model_server/inference_service_configuration/utils.py
  • utilities/inference_utils.py
  • tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py
  • tests/model_serving/model_server/inference_service_configuration/conftest.py
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions
Copy link
Copy Markdown

The following are automatically added/executed:

  • PR size label.
  • Run pre-commit
  • Run tox
  • Add PR author as the PR assignee

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.
Supported labels

{'/wip', '/hold', '/lgtm', '/verified'}

@VedantMahabaleshwarkar VedantMahabaleshwarkar changed the title J 19717 Add tests to verify pull secrets are updated correctly for rawdeployment May 1, 2025
@VedantMahabaleshwarkar VedantMahabaleshwarkar marked this pull request as ready for review May 1, 2025 17:29
@VedantMahabaleshwarkar VedantMahabaleshwarkar requested a review from a team as a code owner May 1, 2025 17:29
Copy link
Copy Markdown
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

🧹 Nitpick comments (3)
tests/model_serving/model_server/inference_service_configuration/constants.py (1)

14-15: Pull secret constants for testing

These constants provide test values for the original and updated pull secrets. The # pragma: allowlist-secret comments appropriately prevent false positives in security scans.

Consider using UPPER_SNAKE_CASE naming convention for consistency with other constants in this file:

-original_pull_secret = "pull-secret-1"  # pragma: allowlist-secret
-updated_pull_secret = "updated-pull-secret"  # pragma: allowlist-secret
+ORIGINAL_PULL_SECRET = "pull-secret-1"  # pragma: allowlist-secret
+UPDATED_PULL_SECRET = "updated-pull-secret"  # pragma: allowlist-secret
tests/model_serving/model_server/inference_service_configuration/utils.py (1)

113-139: Well-implemented verification utility for pull secrets

This function provides a clean way to verify that pull secrets are correctly applied to inference services. The assertions have helpful error messages to aid debugging.

Consider handling the case where no pods are found and verifying all pods instead of just the first one:

 def verify_pull_secret(isvc: InferenceService, pull_secret: str, secret_exists: bool) -> None:
     """
     Verify that the ImagePullSecret in the InferenceService pods match the expected values.
 
     Args:
         isvc (InferenceService): InferenceService object.
         pull_secret (str): Pull secret to verify
         secret_exists (bool): False if the pull secret should not exist in the pod.
 
     Raises:
         AssertionError: If the imagePullSecrets do not match the expected presence or name.
     """
-    pod = get_pods_by_isvc_label(
+    pods = get_pods_by_isvc_label(
         client=isvc.client,
         isvc=isvc,
-    )[0]
-    image_pull_secrets = pod.instance.spec.imagePullSecrets or []
-
-    secrets = [s.name for s in image_pull_secrets]
-
-    if secret_exists:
-        assert secrets, "Expected imagePullSecrets to exist, but none were found."
-        assert pull_secret in secrets, f"Expected pull secret '{pull_secret}' not found in imagePullSecrets: {secrets}"
-    else:
-        assert pull_secret not in secrets, (
-            f"Did not expect pull secret '{pull_secret}', but found in imagePullSecrets: {secrets}"
-        )
+    )
+    
+    assert pods, f"No pods found for inference service {isvc.name}"
+    
+    for pod in pods:
+        image_pull_secrets = pod.instance.spec.imagePullSecrets or []
+        secrets = [s.name for s in image_pull_secrets]
+        
+        if secret_exists:
+            assert secrets, f"Expected imagePullSecrets to exist in pod {pod.name}, but none were found."
+            assert pull_secret in secrets, f"Expected pull secret '{pull_secret}' not found in pod {pod.name} imagePullSecrets: {secrets}"
+        else:
+            assert pull_secret not in secrets, (
+                f"Did not expect pull secret '{pull_secret}', but found in pod {pod.name} imagePullSecrets: {secrets}"
+            )
tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py (1)

40-41: Add a docstring for consistency

The test correctly verifies the removal of pull secrets, but is missing a docstring unlike the other tests.

Add a docstring for consistency with the other test methods:

 def test_remove_pull_secret(self, updated_isvc_remove_pull_secret):
+    """Verify that removing the pull secret is correctly reflected in the pod"""
     verify_pull_secret(isvc=updated_isvc_remove_pull_secret, pull_secret=updated_pull_secret, secret_exists=False)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 560f952 and c8a1c79.

📒 Files selected for processing (5)
  • tests/model_serving/model_server/inference_service_configuration/conftest.py (2 hunks)
  • tests/model_serving/model_server/inference_service_configuration/constants.py (1 hunks)
  • tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py (1 hunks)
  • tests/model_serving/model_server/inference_service_configuration/utils.py (1 hunks)
  • utilities/inference_utils.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/model_serving/model_server/inference_service_configuration/utils.py (1)
utilities/infra.py (1)
  • get_pods_by_isvc_label (445-472)
tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py (3)
tests/model_serving/model_server/inference_service_configuration/utils.py (1)
  • verify_pull_secret (113-139)
utilities/constants.py (3)
  • ModelFormat (12-19)
  • ModelName (22-27)
  • RuntimeTemplates (65-73)
tests/model_serving/model_server/inference_service_configuration/conftest.py (3)
  • model_car_raw_inference_service_with_pull_secret (78-95)
  • updated_isvc_pull_secret (99-109)
  • updated_isvc_remove_pull_secret (113-129)
🔇 Additional comments (9)
utilities/inference_utils.py (2)

537-537: Good enhancement to support image pull secrets

This new parameter allows specifying image pull secrets when creating inference services. The type hint clearly indicates the expected format and makes it optional.


612-613: Correctly transforms pull secrets for Kubernetes

The implementation correctly transforms the list of secret names into the format expected by Kubernetes for imagePullSecrets.

tests/model_serving/model_server/inference_service_configuration/test_isvc_pull_secret_updates.py (3)

11-28: Well-structured test parameterization

Good job setting up the test with a parameterized fixture that uses a real OCI image, which provides a realistic test scenario for testing pull secrets.


30-34: Good initial test for pull secret verification

This test properly verifies that the pull secret is correctly set when the inference service is initially created.


36-38: Good test for verifying pull secret updates

This test correctly verifies that updating the pull secret is properly reflected in the pod.

tests/model_serving/model_server/inference_service_configuration/conftest.py (4)

7-10: Required imports added for new fixtures.

These imports are correctly added to support the new fixtures that manage inference services with image pull secrets.


15-16: New constants imported for pull secret testing.

The original_pull_secret and updated_pull_secret constants are properly imported from the constants file to be used in the fixtures.


98-110: Properly implemented fixture for updating pull secret.

This fixture correctly updates the inference service to use the new pull secret value. The implementation uses the context manager pattern appropriately to ensure proper resource management.


112-129: Correctly implemented fixture for removing pull secret.

This fixture properly removes the pull secret by explicitly setting imagePullSecrets to None. The code is well-structured and the comment on line 124 adds clarity about the intent to remove the field completely.

@mwaykole
Copy link
Copy Markdown
Member

mwaykole commented May 2, 2025

hey @VedantMahabaleshwarkar, how much time does the test take to run?
if it's quick, please add smoke marker or add sanity marker if test takes more then 5 min

@VedantMahabaleshwarkar
Copy link
Copy Markdown
Contributor Author

hey @VedantMahabaleshwarkar, how much time does the test take to run?
if it's quick, please add smoke marker or add sanity marker if test takes more then 5 min

less than 2 minutes from my testing

@mwaykole
Copy link
Copy Markdown
Member

mwaykole commented May 6, 2025

less than 2 minutes from my testing
@VedantMahabaleshwarkar, please add a smoke marker else look good

Signed-off-by: Vedant Mahabaleshwarkar <vmahabal@redhat.com>
Copy link
Copy Markdown
Member

@andresllh andresllh left a comment

Choose a reason for hiding this comment

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

/lgtm

@mwaykole mwaykole enabled auto-merge (squash) May 9, 2025 15:10
@mwaykole mwaykole requested a review from dbasunag May 9, 2025 15:13
@mwaykole mwaykole merged commit bfcf992 into opendatahub-io:main May 9, 2025
9 checks passed
@github-actions
Copy link
Copy Markdown

github-actions bot commented May 9, 2025

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.

6 participants