Skip to content

fix(envtest): ensures consistent env test setup#798

Merged
pierDipi merged 1 commit into
opendatahub-io:release-v0.15from
bartoszmajsak:llm-d/fix/env-test/webhook
Jul 30, 2025
Merged

fix(envtest): ensures consistent env test setup#798
pierDipi merged 1 commit into
opendatahub-io:release-v0.15from
bartoszmajsak:llm-d/fix/env-test/webhook

Conversation

@bartoszmajsak
Copy link
Copy Markdown

@bartoszmajsak bartoszmajsak commented Jul 30, 2025

This PR simplifies EnvTest setup and ensures webhooks and controller are configured and deployed together.

Follow-ups to make this PR focused:

  • improve webhook registration by defining setup func and manifests in a single builder call
  • unify usage of test fixtures (builders) across the tests

Summary by CodeRabbit

  • Tests

    • Simplified test suite setup for controller and webhook tests by introducing a unified environment setup function.
    • Improved test reliability by ensuring explicit gateway references in routing reconciliation tests.
    • Enhanced test environment initialization for controller and webhook testing.
  • Chores

    • Improved internal documentation and prevented duplicate webhook manifest paths in test configuration.

This PR simplifies EnvTest setup and ensures webhooks and controller
are configured and deployed together.

Signed-off-by: Bartosz Majsak <bartosz.majsak@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 30, 2025

Walkthrough

A new test environment setup utility was introduced to streamline controller and webhook integration tests for the LLM Inference Service. Test suite initializations were refactored to use this utility, replacing manual setup logic. A test case was updated to specify explicit gateway references. Webhook manifest path handling was improved to ensure uniqueness.

Changes

Cohort / File(s) Change Summary
Test Environment Utility Addition
pkg/controller/llmisvc/fixture/envtest.go
Introduced SetupTestEnv() to encapsulate controller-runtime test environment setup, including controller and webhook registration, and resource provisioning.
Test Suite Refactoring
pkg/controller/llmisvc/suite_test.go, pkg/controller/llmisvc/webhook/webhook_suite_test.go
Refactored test suite initializations to use the new SetupTestEnv() utility, removing manual environment, controller, and webhook setup logic. Unused imports were also removed.
Test Case Update
pkg/controller/llmisvc/controller_int_test.go
Modified a test to set explicit gateway references in the router spec, affecting HTTPRoute management during reconciliation.
Webhook Manifest Path Handling
pkg/testing/config.go
Updated comment for WithWebhooks. Modified WithWebhookManifests to ensure only unique webhook manifest paths are appended, preventing duplicates.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant SetupTestEnv
    participant ControllerManager
    participant WebhookManager
    participant K8sCluster

    TestSuite->>SetupTestEnv: Call SetupTestEnv()
    SetupTestEnv->>ControllerManager: Register LLMInferenceServiceReconciler
    SetupTestEnv->>WebhookManager: Register webhook validators
    SetupTestEnv->>K8sCluster: Ensure required resources
    SetupTestEnv-->>TestSuite: Return test client
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • israel-hdez
  • pierDipi

Poem

In the warren, tests now bloom anew,
With helpers that make setup a breeze to do.
Webhooks and controllers, all neat in a row,
No more duplicate paths, just a streamlined flow.
🐇 With every hop, our code grows bright—
Integration’s future is looking right!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.2.2)

Error: can't load config: can't unmarshal config by viper (flags, file): 1 error(s) decoding:

  • 'output.formats' expected a map, got 'slice'
    The command is terminated due to an error: can't load config: can't unmarshal config by viper (flags, file): 1 error(s) decoding:

  • 'output.formats' expected a map, got 'slice'

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ 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.
    • @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 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.
    • @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 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.

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.

@bartoszmajsak
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 30, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
pkg/controller/llmisvc/fixture/envtest.go (1)

40-95: Excellent centralized test environment setup implementation.

This new SetupTestEnv() function successfully consolidates all test environment setup logic and achieves the PR's objectives:

Strengths:

  • Comprehensive setup including timeouts, context management, controllers, and webhooks
  • Proper cleanup handling with DeferCleanup and context cancellation
  • Configurable timeout via environment variable with sensible default
  • Consistent webhook manifest handling using the improved deduplication logic
  • Clean separation of controller and webhook setup functions

Minor observation:
The TODO comment on Line 59 indicates the EventRecorder setup is a stub and should be aligned with main.go in the future. This doesn't impact current functionality but should be addressed eventually.

This consolidation eliminates code duplication across test suites and provides a consistent, maintainable foundation for LLMInferenceService testing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4448e90 and b5e4a45.

📒 Files selected for processing (5)
  • pkg/controller/llmisvc/controller_int_test.go (1 hunks)
  • pkg/controller/llmisvc/fixture/envtest.go (1 hunks)
  • pkg/controller/llmisvc/suite_test.go (1 hunks)
  • pkg/controller/llmisvc/webhook/webhook_suite_test.go (1 hunks)
  • pkg/testing/config.go (2 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: hdefazio
PR: opendatahub-io/kserve#658
File: pkg/controller/v1beta1/inferenceservice/rawkube_controller_test.go:1873-1886
Timestamp: 2025-06-12T22:10:15.375Z
Learning: If a review comment is raised on code that was not introduced or changed by the current PR, and the user points this out, acknowledge it and clarify that no action is required from the PR author.
pkg/controller/llmisvc/suite_test.go (1)

Learnt from: israel-hdez
PR: #738
File: pkg/apis/serving/v1beta1/configmap.go:0-0
Timestamp: 2025-07-17T16:19:36.771Z
Learning: In pkg/apis/serving/v1beta1/configmap.go, the GetStorageInitializerConfigs function was moved from another package to prevent circular imports, which explains why it may contain existing patterns rather than being newly written code.

pkg/controller/llmisvc/controller_int_test.go (1)

Learnt from: bartoszmajsak
PR: #757
File: pkg/controller/llmisvc/router_discovery.go:45-49
Timestamp: 2025-07-21T17:40:11.003Z
Learning: In the KServe LLMInferenceService controller, the DiscoverURLs function in router_discovery.go intentionally returns nil, nil for missing Gateways rather than errors. This allows the reconciler to continue processing and update status conditions through the separate validation logic in ref_validation.go, preventing reconciliation loops that would occur if errors were returned.

pkg/controller/llmisvc/fixture/envtest.go (1)

Learnt from: israel-hdez
PR: #738
File: pkg/apis/serving/v1beta1/configmap.go:0-0
Timestamp: 2025-07-17T16:19:36.771Z
Learning: In pkg/apis/serving/v1beta1/configmap.go, the GetStorageInitializerConfigs function was moved from another package to prevent circular imports, which explains why it may contain existing patterns rather than being newly written code.

🧬 Code Graph Analysis (2)
pkg/controller/llmisvc/suite_test.go (1)
pkg/controller/llmisvc/fixture/envtest.go (1)
  • SetupTestEnv (40-95)
pkg/controller/llmisvc/webhook/webhook_suite_test.go (1)
pkg/controller/llmisvc/fixture/envtest.go (1)
  • SetupTestEnv (40-95)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: Build
  • GitHub Check: build (3.12)
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: test
  • GitHub Check: precommit-check
  • GitHub Check: test
  • GitHub Check: build (3.9)
  • GitHub Check: build (3.11)
  • GitHub Check: build (3.10)
🔇 Additional comments (5)
pkg/testing/config.go (2)

86-86: LGTM! Comment correction.

The comment now correctly describes the WithWebhooks method instead of incorrectly referencing "WithWebhookManifests."


190-199: Excellent deduplication implementation.

The webhook manifest path deduplication logic is well-implemented:

  • Uses a seen map to track existing paths efficiently
  • Prevents duplicate entries that could cause envtest configuration issues
  • Maintains order of existing paths while adding only new ones

This enhancement supports the PR's goal of consistent test environment setup.

pkg/controller/llmisvc/controller_int_test.go (1)

305-312: Good test improvement - explicit gateway references.

The test now explicitly specifies gateway references in the GatewaySpec, making the test more deterministic and clearly aligned with the test case name "should delete managed HTTPRoute when ref is defined."

This change improves test clarity by removing reliance on default gateway behavior.

pkg/controller/llmisvc/suite_test.go (1)

37-37: Excellent consolidation of test environment setup.

The replacement of complex manual setup with fixture.SetupTestEnv() perfectly achieves the PR's goal of consistent and simplified test environment configuration. This eliminates code duplication and centralizes the setup logic for better maintainability.

The SetupTestEnv() function properly handles all aspects of environment setup including timeouts, context management, controller/webhook registration, and cleanup.

pkg/controller/llmisvc/webhook/webhook_suite_test.go (1)

38-38: Consistent test environment consolidation.

Similar to the controller test suite, this change successfully consolidates webhook test environment setup into the centralized fixture.SetupTestEnv() function. This ensures consistent test environment configuration across both controller and webhook test suites, improving maintainability and reducing code duplication.

@bartoszmajsak bartoszmajsak requested a review from hdefazio July 30, 2025 10:47
Comment on lines +82 to +83
envTest := testing.NewEnvTest(webhookManifests).
WithWebhooks(webhooks).
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is one of the follow-ups I mentioned in the PR description.

Suggested change
envTest := testing.NewEnvTest(webhookManifests).
WithWebhooks(webhooks).
envTest := testing.NewEnvTest().
WithWebhooks(webhook, webhookManifests).

Copy link
Copy Markdown
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jul 30, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bartoszmajsak, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [bartoszmajsak,pierDipi]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pierDipi pierDipi merged commit 5bd42ef into opendatahub-io:release-v0.15 Jul 30, 2025
28 of 33 checks passed
@github-project-automation github-project-automation Bot moved this from New/Backlog to Done in ODH Model Serving Planning Jul 30, 2025
@bartoszmajsak bartoszmajsak deleted the llm-d/fix/env-test/webhook branch July 30, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants