Skip to content

Conversation

@amirejaz
Copy link
Contributor

@amirejaz amirejaz commented Dec 4, 2025

Summary

Implements resolution of CompositeToolRefs in the VirtualMCPServer converter. The converter now fetches referenced VirtualMCPCompositeToolDefinition resources from Kubernetes, converts them to CompositeToolConfig entries, and merges them with inline CompositeTools.

Fixes #2774

Changes

  • Converter: Added k8sClient field to Converter struct to enable fetching Kubernetes resources
  • NewConverter: Updated to accept k8sClient as required parameter (non-variadic)
  • convertAllCompositeTools: New method that orchestrates conversion of both inline and referenced tools
  • convertReferencedCompositeTools: Fetches and converts referenced VirtualMCPCompositeToolDefinition resources
  • convertCompositeToolDefinition: Converts VirtualMCPCompositeToolDefinition CRD to CompositeToolConfig
  • validateCompositeToolNames: Validates for duplicate tool names across all composite tools
  • Controller: Updated to pass r.Client to converter for resource fetching

Testing

  • ✅ Unit tests for converter logic with fake Kubernetes clients
  • ✅ Integration tests for controller reconciliation flow
  • ✅ End-to-end tests verifying ConfigMap generation with referenced tools
  • ✅ Error handling tests for missing resources and duplicate names
  • ✅ Manual testing on Kind cluster with ko deployment

Verification

Tested manually on Kind cluster:

  • Referenced tools are fetched from Kubernetes
  • Inline and referenced tools are merged correctly
  • Multiple referenced tools work as expected
  • Error handling works for missing resources
  • ConfigMap contains all composite tools (inline + referenced)

Large PR Justification

This PR implements CompositeToolRefs support for VirtualMCPServer, which requires coordinated changes across API definitions, controller validation, converter logic, watch mechanisms, and integration tests. The changes follow the established GroupRef validation pattern and must be atomic to maintain consistency across all layers.

@github-actions github-actions bot added the size/L Large PR: 600-999 lines changed label Dec 4, 2025
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.39%. Comparing base (7906ead) to head (5e87b4a).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
...perator/controllers/virtualmcpserver_controller.go 27.65% 30 Missing and 4 partials ⚠️
cmd/thv-operator/pkg/vmcpconfig/converter.go 89.83% 9 Missing and 3 partials ⚠️
...v-operator/pkg/virtualmcpserverstatus/collector.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2885      +/-   ##
==========================================
- Coverage   56.41%   56.39%   -0.02%     
==========================================
  Files         322      322              
  Lines       31638    31758     +120     
==========================================
+ Hits        17848    17911      +63     
- Misses      12252    12311      +59     
+ Partials     1538     1536       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements resolution of CompositeToolRefs in the VirtualMCPServer converter, enabling users to reference shared VirtualMCPCompositeToolDefinition resources instead of only defining composite tools inline. The implementation adds Kubernetes resource fetching capabilities to the converter and properly merges inline and referenced tools while validating for duplicate names.

Key changes:

  • Added Kubernetes client to the Converter struct to enable fetching referenced resources
  • Implemented orchestration logic to merge inline CompositeTools with referenced CompositeToolRefs
  • Added comprehensive validation to detect duplicate tool names across inline and referenced tools

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cmd/thv-operator/pkg/vmcpconfig/converter.go Added k8sClient field, new methods for fetching/converting referenced tools, and validation logic
cmd/thv-operator/pkg/vmcpconfig/converter_test.go Added comprehensive unit tests covering successful resolution, merging, error cases, and nil client handling
cmd/thv-operator/controllers/virtualmcpserver_vmcpconfig.go Updated converter instantiation to pass r.Client for resource fetching
cmd/thv-operator/controllers/virtualmcpserver_vmcpconfig_test.go Added end-to-end integration tests verifying ConfigMap generation with referenced tools

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@amirejaz
Copy link
Contributor Author

amirejaz commented Dec 4, 2025

will address copilot feedback and fix ci

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

good work, some nits inline

@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Dec 4, 2025
@github-actions github-actions bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Dec 4, 2025
@amirejaz amirejaz requested a review from Copilot December 4, 2025 12:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/L Large PR: 600-999 lines changed labels Dec 4, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Large PR Detected

This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.

How to unblock this PR:

Add a section to your PR description with the following format:

## Large PR Justification

[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformation

Alternative:

Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.

See our Contributing Guidelines for more details.


This review will be automatically dismissed once you add the justification section.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Dec 4, 2025
@amirejaz amirejaz requested a review from jhrozek December 4, 2025 13:36
@jhrozek
Copy link
Contributor

jhrozek commented Dec 4, 2025

@amirejaz there is a conflict now

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Dec 4, 2025
@github-actions github-actions bot dismissed their stale review December 4, 2025 14:08

Large PR justification has been provided. Thank you!

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@github-actions github-actions bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Dec 4, 2025
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

Two comments for later, but overall LGTM

@amirejaz amirejaz merged commit 9fc4513 into main Dec 5, 2025
41 of 42 checks passed
@amirejaz amirejaz deleted the composite-tool-refs-resolution branch December 5, 2025 10:53
carlos-gn pushed a commit to carlos-gn/toolhive that referenced this pull request Dec 8, 2025
…tacklok#2885)

* Implement CompositeToolRefs resolution in VirtualMCPServer converter

* fix tests by passing workload names

* refactor and address feedback

* fix linting

* fix operator tests integration

* update mocks

* fix operator tests integration

* remove unnecessary comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement CompositeToolRefs resolution in VirtualMCPServer converter

3 participants