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
536450func hasVaultAgentInjection (annotations map [string ]string ) bool {
537451 if annotations == nil {
0 commit comments