fix: add default resource limits to MCPRemoteProxy#3132
Closed
siddharth-s31 wants to merge 1 commit intostacklok:mainfrom
Closed
fix: add default resource limits to MCPRemoteProxy#3132siddharth-s31 wants to merge 1 commit intostacklok:mainfrom
siddharth-s31 wants to merge 1 commit intostacklok:mainfrom
Conversation
yrobla
reviewed
Dec 22, 2025
Contributor
There was a problem hiding this comment.
thanks for the contribution! generally it looks good but i don't like the way the defaults are hardcoded. Instead we can have 2 different options. Use env vars and modify operator to accept them:
In deploy/charts/operator/values.yaml:
resources:
defaults:
mcpRemoteProxy:
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "200m"
memory: "256Mi"
In deploy/charts/operator/templates/deployment.yaml:
env:
- name: DEFAULT_MCPREMOTEPROXY_CPU_REQUEST
value: {{ .Values.resources.defaults.mcpRemoteProxy.requests.cpu | quote }}
- name: DEFAULT_MCPREMOTEPROXY_MEMORY_REQUEST
value: {{ .Values.resources.defaults.mcpRemoteProxy.requests.memory | quote }}
- name: DEFAULT_MCPREMOTEPROXY_CPU_LIMIT
value: {{ .Values.resources.defaults.mcpRemoteProxy.limits.cpu | quote }}
- name: DEFAULT_MCPREMOTEPROXY_MEMORY_LIMIT
value: {{ .Values.resources.defaults.mcpRemoteProxy.limits.memory | quote }}
In controllerutil/resources.go:
func BuildDefaultProxyRunnerResourceRequirements() corev1.ResourceRequirements {
return corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(getEnvOrDefault("DEFAULT_MCPREMOTEPROXY_CPU_LIMIT", "200m")),
corev1.ResourceMemory: resource.MustParse(getEnvOrDefault("DEFAULT_MCPREMOTEPROXY_MEMORY_LIMIT", "256Mi")),
},
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(getEnvOrDefault("DEFAULT_MCPREMOTEPROXY_CPU_REQUEST", "50m")),
corev1.ResourceMemory: resource.MustParse(getEnvOrDefault("DEFAULT_MCPREMOTEPROXY_MEMORY_REQUEST", "64Mi")),
},
}
}
func getEnvOrDefault(key, defaultValue string) string {
if val := os.Getenv(key); val != "" {
return val
}
return defaultValue
}
Or use a configmap:
Create a well-known ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: toolhive-operator-defaults
namespace: toolhive-system
data:
mcpremoteproxy-resources.yaml: |
requests:
cpu: "50m"
memory: "64Mi"
limits:
cpu: "200m"
memory: "256Mi"
In controller, read it once at startup:
func (r *MCPRemoteProxyReconciler) loadDefaults(ctx context.Context) {
cm := &corev1.ConfigMap{}
err := r.Get(ctx, types.NamespacedName{
Name: "toolhive-operator-defaults",
Namespace: "toolhive-system",
}, cm)
if err != nil {
// Use hardcoded defaults if ConfigMap doesn't exist
return
}
// Parse YAML and cache defaults
}
Contributor
|
Closing due to inactivity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3131
This PR adds default resource limits to
MCPRemoteProxyto prevent containers from consuming unlimited resources, aligning with the pattern established inVirtualMCPServer(#2873).Changes
BuildDefaultProxyRunnerResourceRequirementsandMergeResourceRequirementstocontrollerutil.mcpremoteproxy_deployment.goto apply default resources (50m/200m CPU, 64Mi/256Mi Memory) when creating deployments.mcpremoteproxy_controller.goto correctly detect updates by comparing against merged resource requirements.mcpremoteproxy_deployment_test.goto verify: