Skip to content

Commit efd021d

Browse files
authored
Merge branch 'main' into fix_ci
2 parents 53df277 + b879b4a commit efd021d

File tree

8 files changed

+367
-390
lines changed

8 files changed

+367
-390
lines changed

cmd/thv-operator/controllers/mcpremoteproxy_runconfig.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1"
1717
ctrlutil "github.com/stacklok/toolhive/cmd/thv-operator/pkg/controllerutil"
18+
runconfig "github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig"
1819
configMapChecksum "github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig/configmap/checksum"
1920
"github.com/stacklok/toolhive/pkg/runner"
2021
transporttypes "github.com/stacklok/toolhive/pkg/transport/types"
@@ -169,7 +170,7 @@ func (r *MCPRemoteProxyReconciler) createRunConfigFromMCPRemoteProxy(
169170
}
170171

171172
// Add telemetry configuration if specified
172-
addTelemetryConfigOptions(&options, proxy.Spec.Telemetry, proxy.Name)
173+
runconfig.AddTelemetryConfigOptions(&options, proxy.Spec.Telemetry, proxy.Name)
173174

174175
// Add authorization configuration if specified
175176
ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout)
@@ -192,7 +193,7 @@ func (r *MCPRemoteProxyReconciler) createRunConfigFromMCPRemoteProxy(
192193
}
193194

194195
// Add audit configuration if specified
195-
addAuditConfigOptions(&options, proxy.Spec.Audit)
196+
runconfig.AddAuditConfigOptions(&options, proxy.Spec.Audit)
196197

197198
// Use the RunConfigBuilder for operator context
198199
// Deployer is nil for remote proxies because they connect to external services

cmd/thv-operator/controllers/mcpremoteproxy_runconfig_test.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -164,76 +164,6 @@ func TestCreateRunConfigFromMCPRemoteProxy(t *testing.T) {
164164
assert.Contains(t, config.AuthzConfig.Cedar.Policies[0], "tools/list")
165165
},
166166
},
167-
{
168-
name: "with audit enabled",
169-
proxy: &mcpv1alpha1.MCPRemoteProxy{
170-
ObjectMeta: metav1.ObjectMeta{
171-
Name: "audit-proxy",
172-
Namespace: "default",
173-
},
174-
Spec: mcpv1alpha1.MCPRemoteProxySpec{
175-
RemoteURL: "https://mcp.example.com",
176-
Port: 8080,
177-
OIDCConfig: mcpv1alpha1.OIDCConfigRef{
178-
Type: mcpv1alpha1.OIDCConfigTypeInline,
179-
Inline: &mcpv1alpha1.InlineOIDCConfig{
180-
Issuer: "https://auth.example.com",
181-
Audience: "mcp-proxy",
182-
},
183-
},
184-
Audit: &mcpv1alpha1.AuditConfig{
185-
Enabled: true,
186-
},
187-
},
188-
},
189-
expectError: false,
190-
validate: func(t *testing.T, config *runner.RunConfig) {
191-
t.Helper()
192-
assert.Equal(t, "audit-proxy", config.Name)
193-
assert.NotNil(t, config.AuditConfig)
194-
},
195-
},
196-
{
197-
name: "with telemetry configuration",
198-
proxy: &mcpv1alpha1.MCPRemoteProxy{
199-
ObjectMeta: metav1.ObjectMeta{
200-
Name: "telemetry-proxy",
201-
Namespace: "default",
202-
},
203-
Spec: mcpv1alpha1.MCPRemoteProxySpec{
204-
RemoteURL: "https://mcp.example.com",
205-
Port: 8080,
206-
OIDCConfig: mcpv1alpha1.OIDCConfigRef{
207-
Type: mcpv1alpha1.OIDCConfigTypeInline,
208-
Inline: &mcpv1alpha1.InlineOIDCConfig{
209-
Issuer: "https://auth.example.com",
210-
Audience: "mcp-proxy",
211-
},
212-
},
213-
Telemetry: &mcpv1alpha1.TelemetryConfig{
214-
OpenTelemetry: &mcpv1alpha1.OpenTelemetryConfig{
215-
Enabled: true,
216-
Endpoint: "http://otel-collector:4317",
217-
ServiceName: "salesforce-proxy",
218-
Insecure: true,
219-
Tracing: &mcpv1alpha1.OpenTelemetryTracingConfig{
220-
Enabled: true,
221-
SamplingRate: "0.1",
222-
},
223-
},
224-
},
225-
},
226-
},
227-
expectError: false,
228-
validate: func(t *testing.T, config *runner.RunConfig) {
229-
t.Helper()
230-
assert.Equal(t, "telemetry-proxy", config.Name)
231-
assert.NotNil(t, config.TelemetryConfig)
232-
assert.Equal(t, "otel-collector:4317", config.TelemetryConfig.Endpoint)
233-
assert.Equal(t, "salesforce-proxy", config.TelemetryConfig.ServiceName)
234-
assert.True(t, config.TelemetryConfig.TracingEnabled)
235-
},
236-
},
237167
{
238168
name: "with trust proxy headers",
239169
proxy: &mcpv1alpha1.MCPRemoteProxy{

cmd/thv-operator/controllers/mcpserver_runconfig.go

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"os"
8-
"strconv"
98
"strings"
109
"time"
1110

@@ -15,6 +14,7 @@ import (
1514

1615
mcpv1alpha1 "github.com/stacklok/toolhive/cmd/thv-operator/api/v1alpha1"
1716
ctrlutil "github.com/stacklok/toolhive/cmd/thv-operator/pkg/controllerutil"
17+
runconfig "github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig"
1818
"github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig/configmap"
1919
configMapChecksum "github.com/stacklok/toolhive/cmd/thv-operator/pkg/runconfig/configmap/checksum"
2020
"github.com/stacklok/toolhive/pkg/operator/accessors"
@@ -166,7 +166,7 @@ func (r *MCPServerReconciler) createRunConfigFromMCPServer(m *mcpv1alpha1.MCPSer
166166
}
167167

168168
// Add telemetry configuration if specified
169-
addTelemetryConfigOptions(&options, m.Spec.Telemetry, m.Name)
169+
runconfig.AddTelemetryConfigOptions(&options, m.Spec.Telemetry, m.Name)
170170

171171
// Add authorization configuration if specified
172172
ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout)
@@ -186,7 +186,7 @@ func (r *MCPServerReconciler) createRunConfigFromMCPServer(m *mcpv1alpha1.MCPSer
186186
}
187187

188188
// Add audit configuration if specified
189-
addAuditConfigOptions(&options, m.Spec.Audit)
189+
runconfig.AddAuditConfigOptions(&options, m.Spec.Audit)
190190

191191
// Check for Vault Agent Injection and add env-file-dir if needed
192192
vaultDetected := false
@@ -446,92 +446,6 @@ func convertVolumesFromMCPServer(vols []mcpv1alpha1.Volume) []string {
446446
return volumes
447447
}
448448

449-
// addTelemetryConfigOptions adds telemetry configuration options to the builder options
450-
func addTelemetryConfigOptions(
451-
options *[]runner.RunConfigBuilderOption,
452-
telemetryConfig *mcpv1alpha1.TelemetryConfig,
453-
mcpServerName string,
454-
) {
455-
if telemetryConfig == nil {
456-
return
457-
}
458-
459-
// Default values
460-
var otelEndpoint string
461-
var otelEnablePrometheusMetricsPath bool
462-
var otelTracingEnabled bool
463-
var otelMetricsEnabled bool
464-
var otelServiceName string
465-
var otelSamplingRate = 0.05 // Default sampling rate
466-
var otelHeaders []string
467-
var otelInsecure bool
468-
var otelEnvironmentVariables []string
469-
470-
// Process OpenTelemetry configuration
471-
if telemetryConfig.OpenTelemetry != nil && telemetryConfig.OpenTelemetry.Enabled {
472-
otel := telemetryConfig.OpenTelemetry
473-
474-
// Strip http:// or https:// prefix if present, as OTLP client expects host:port format
475-
otelEndpoint = strings.TrimPrefix(strings.TrimPrefix(otel.Endpoint, "https://"), "http://")
476-
otelInsecure = otel.Insecure
477-
otelHeaders = otel.Headers
478-
479-
// Use MCPServer name as service name if not specified
480-
if otel.ServiceName != "" {
481-
otelServiceName = otel.ServiceName
482-
} else {
483-
otelServiceName = mcpServerName
484-
}
485-
486-
// Handle tracing configuration
487-
if otel.Tracing != nil {
488-
otelTracingEnabled = otel.Tracing.Enabled
489-
if otel.Tracing.SamplingRate != "" {
490-
// Parse sampling rate string to float64
491-
if rate, err := strconv.ParseFloat(otel.Tracing.SamplingRate, 64); err == nil {
492-
otelSamplingRate = rate
493-
}
494-
}
495-
}
496-
497-
// Handle metrics configuration
498-
if otel.Metrics != nil {
499-
otelMetricsEnabled = otel.Metrics.Enabled
500-
}
501-
}
502-
503-
// Process Prometheus configuration
504-
if telemetryConfig.Prometheus != nil {
505-
otelEnablePrometheusMetricsPath = telemetryConfig.Prometheus.Enabled
506-
}
507-
508-
// Add telemetry config to options
509-
*options = append(*options, runner.WithTelemetryConfig(
510-
otelEndpoint,
511-
otelEnablePrometheusMetricsPath,
512-
otelTracingEnabled,
513-
otelMetricsEnabled,
514-
otelServiceName,
515-
otelSamplingRate,
516-
otelHeaders,
517-
otelInsecure,
518-
otelEnvironmentVariables,
519-
))
520-
}
521-
522-
// addAuditConfigOptions adds audit configuration options to the builder options
523-
func addAuditConfigOptions(
524-
options *[]runner.RunConfigBuilderOption,
525-
auditConfig *mcpv1alpha1.AuditConfig,
526-
) {
527-
if auditConfig == nil {
528-
return
529-
}
530-
531-
// Add audit config to options with default config (no custom config path for now)
532-
*options = append(*options, runner.WithAuditEnabled(auditConfig.Enabled, ""))
533-
}
534-
535449
// hasVaultAgentInjection checks if Vault Agent Injection is enabled in the pod annotations
536450
func hasVaultAgentInjection(annotations map[string]string) bool {
537451
if annotations == nil {

0 commit comments

Comments
 (0)