Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cmd/thv-operator/controllers/embeddingserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand All @@ -35,7 +35,7 @@ import (
type EmbeddingServerReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
PlatformDetector *ctrlutil.SharedPlatformDetector
ImageValidation validation.ImageValidation
}
Expand Down Expand Up @@ -386,7 +386,15 @@ func (r *EmbeddingServerReconciler) validateAndUpdatePodTemplateStatus(
Message: fmt.Sprintf("Invalid PodTemplateSpec: %v", err),
ObservedGeneration: embedding.Generation,
})
r.Recorder.Event(embedding, corev1.EventTypeWarning, "ValidationFailed", fmt.Sprintf("Invalid PodTemplateSpec: %v", err))
r.Recorder.Eventf(
embedding,
nil,
corev1.EventTypeWarning,
"ValidationFailed",
"ValidatePodTemplateSpec",
"Invalid PodTemplateSpec: %v",
err,
)
return false
}

Expand Down Expand Up @@ -1055,7 +1063,7 @@ func (r *EmbeddingServerReconciler) finalizeEmbeddingServer(ctx context.Context,
// Cleanup logic here if needed
// For now, Kubernetes will handle cascade deletion of owned resources

r.Recorder.Event(embedding, corev1.EventTypeNormal, "Deleted", "EmbeddingServer has been finalized")
r.Recorder.Eventf(embedding, nil, corev1.EventTypeNormal, "Deleted", "Finalize", "EmbeddingServer has been finalized")
}

// SetupWithManager sets up the controller with the Manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -366,7 +366,7 @@ func TestReconcile_NotFound(t *testing.T) {
reconciler := &EmbeddingServerReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
ImageValidation: validation.ImageValidationAlwaysAllow,
}

Expand Down Expand Up @@ -398,7 +398,7 @@ func TestReconcile_CreateResources(t *testing.T) {
reconciler := &EmbeddingServerReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
PlatformDetector: ctrlutil.NewSharedPlatformDetector(),
ImageValidation: validation.ImageValidationAlwaysAllow,
}
Expand Down Expand Up @@ -655,7 +655,7 @@ func TestHandleDeletion(t *testing.T) {
reconciler := &EmbeddingServerReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
}

result, done, err := reconciler.handleDeletion(context.TODO(), tt.embedding)
Expand Down
6 changes: 3 additions & 3 deletions cmd/thv-operator/controllers/mcpremoteproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand All @@ -39,7 +39,7 @@ import (
type MCPRemoteProxyReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
PlatformDetector *ctrlutil.SharedPlatformDetector
}

Expand Down Expand Up @@ -405,7 +405,7 @@ func (r *MCPRemoteProxyReconciler) failValidation(proxy *mcpv1alpha1.MCPRemotePr
// recordValidationEvent emits a Warning event for a validation failure.
func (r *MCPRemoteProxyReconciler) recordValidationEvent(proxy *mcpv1alpha1.MCPRemoteProxy, reason, message string) {
if r.Recorder != nil {
r.Recorder.Event(proxy, corev1.EventTypeWarning, reason, message)
r.Recorder.Eventf(proxy, nil, corev1.EventTypeWarning, reason, "ValidateSpec", message)
}
}

Expand Down
12 changes: 6 additions & 6 deletions cmd/thv-operator/controllers/mcpremoteproxy_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -304,7 +304,7 @@ func TestMCPRemoteProxyFullReconciliation(t *testing.T) {
reconciler := &MCPRemoteProxyReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
PlatformDetector: ctrlutil.NewSharedPlatformDetector(),
}

Expand Down Expand Up @@ -389,7 +389,7 @@ func TestMCPRemoteProxyConfigChangePropagation(t *testing.T) {
reconciler := &MCPRemoteProxyReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
PlatformDetector: ctrlutil.NewSharedPlatformDetector(),
}

Expand Down Expand Up @@ -467,7 +467,7 @@ func TestMCPRemoteProxyStatusProgression(t *testing.T) {
reconciler := &MCPRemoteProxyReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
PlatformDetector: ctrlutil.NewSharedPlatformDetector(),
}

Expand Down Expand Up @@ -1005,7 +1005,7 @@ func TestValidateSpecConfigurationConditions(t *testing.T) {
WithStatusSubresource(&mcpv1alpha1.MCPRemoteProxy{}).
Build()

fakeRecorder := record.NewFakeRecorder(10)
fakeRecorder := events.NewFakeRecorder(10)
reconciler := &MCPRemoteProxyReconciler{
Client: fakeClient,
Scheme: scheme,
Expand Down Expand Up @@ -1139,7 +1139,7 @@ func TestValidateAndHandleConfigs(t *testing.T) {
reconciler := &MCPRemoteProxyReconciler{
Client: fakeClient,
Scheme: scheme,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
}

err := reconciler.validateAndHandleConfigs(context.TODO(), tt.proxy)
Expand Down
6 changes: 3 additions & 3 deletions cmd/thv-operator/controllers/mcpserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand All @@ -47,7 +47,7 @@ import (
type MCPServerReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
PlatformDetector *ctrlutil.SharedPlatformDetector
ImageValidation validation.ImageValidation
}
Expand Down Expand Up @@ -641,7 +641,7 @@ func (r *MCPServerReconciler) validateAndUpdatePodTemplateStatus(ctx context.Con
if err != nil {
// Record event for invalid PodTemplateSpec
if r.Recorder != nil {
r.Recorder.Eventf(mcpServer, corev1.EventTypeWarning, "InvalidPodTemplateSpec",
r.Recorder.Eventf(mcpServer, nil, corev1.EventTypeWarning, "InvalidPodTemplateSpec", "ValidatePodTemplateSpec",
"Failed to parse PodTemplateSpec: %v. Deployment blocked until PodTemplateSpec is fixed.", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestMCPServerReconciler_InvalidPodTemplateSpec(t *testing.T) {
require.NoError(t, mcpv1alpha1.AddToScheme(s))

// Create a fake event recorder for each test
eventRecorder := record.NewFakeRecorder(10)
eventRecorder := events.NewFakeRecorder(10)

// Create a fake client with the MCPServer
fakeClient := fake.NewClientBuilder().
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestDeploymentArgsWithInvalidPodTemplateSpec(t *testing.T) {
r := &MCPServerReconciler{
Client: fakeClient,
Scheme: s,
Recorder: record.NewFakeRecorder(10),
Recorder: events.NewFakeRecorder(10),
PlatformDetector: ctrlutil.NewSharedPlatformDetector(),
}

Expand Down
30 changes: 15 additions & 15 deletions cmd/thv-operator/controllers/virtualmcpserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/events"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -87,7 +87,7 @@ type AuthConfigError struct {
type VirtualMCPServerReconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder record.EventRecorder
Recorder events.EventRecorder
PlatformDetector *ctrlutil.SharedPlatformDetector
}

Expand Down Expand Up @@ -483,7 +483,7 @@ func (r *VirtualMCPServerReconciler) validateAndUpdatePodTemplateStatus(
if err != nil {
// Record event for invalid PodTemplateSpec
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "InvalidPodTemplateSpec",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "InvalidPodTemplateSpec", "ValidatePodTemplateSpec",
"Failed to parse PodTemplateSpec: %v. Deployment blocked until PodTemplateSpec is fixed.", err)
}

Expand Down Expand Up @@ -537,7 +537,7 @@ func (r *VirtualMCPServerReconciler) ensureAllResources(
statusManager.SetObservedGeneration(vmcp.Generation)
// Record event for secret validation failure
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "SecretValidationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "SecretValidationFailed", "ValidateSecrets",
"Secret validation failed: %v", err)
}
return ctrl.Result{}, err
Expand Down Expand Up @@ -691,7 +691,7 @@ func (r *VirtualMCPServerReconciler) ensureHMACSecret(
if err != nil {
ctxLogger.Error(err, "Failed to generate HMAC secret")
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "HMACSecretGenerationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "HMACSecretGenerationFailed", "GenerateHMACSecret",
"Failed to generate HMAC secret: %v", err)
}
return fmt.Errorf("failed to generate HMAC secret: %w", err)
Expand Down Expand Up @@ -727,15 +727,15 @@ func (r *VirtualMCPServerReconciler) ensureHMACSecret(
if err := r.Create(ctx, newSecret); err != nil {
ctxLogger.Error(err, "Failed to create HMAC secret")
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "HMACSecretCreationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "HMACSecretCreationFailed", "CreateHMACSecret",
"Failed to create HMAC secret: %v", err)
}
return fmt.Errorf("failed to create HMAC secret: %w", err)
}

// Record success event
if r.Recorder != nil {
r.Recorder.Event(vmcp, corev1.EventTypeNormal, "HMACSecretCreated",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeNormal, "HMACSecretCreated", "CreateHMACSecret",
"HMAC secret created for session token binding")
}
return nil
Expand All @@ -748,7 +748,7 @@ func (r *VirtualMCPServerReconciler) ensureHMACSecret(
if err := r.validateHMACSecret(ctx, vmcp, secret); err != nil {
ctxLogger.Error(err, "Existing HMAC secret is invalid", "Secret.Name", secretName)
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "HMACSecretValidationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "HMACSecretValidationFailed", "ValidateHMACSecret",
"Existing HMAC secret validation failed: %v", err)
}
return fmt.Errorf("existing HMAC secret validation failed: %w", err)
Expand Down Expand Up @@ -897,14 +897,14 @@ func (r *VirtualMCPServerReconciler) ensureDeployment(
ctxLogger.Error(err, "Failed to create new Deployment")
// Record event for deployment creation failure
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "DeploymentCreationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "DeploymentCreationFailed", "CreateDeployment",
"Failed to create Deployment: %v", err)
}
return ctrl.Result{}, err
}
// Record event for successful deployment creation
if r.Recorder != nil {
r.Recorder.Event(vmcp, corev1.EventTypeNormal, "DeploymentCreated",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeNormal, "DeploymentCreated", "CreateDeployment",
"Deployment created successfully")
}
// Return empty result to continue with rest of reconciliation (Service, status update, etc.)
Expand Down Expand Up @@ -941,15 +941,15 @@ func (r *VirtualMCPServerReconciler) ensureDeployment(
ctxLogger.Error(err, "Failed to update Deployment")
// Record event for deployment update failure
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "DeploymentUpdateFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "DeploymentUpdateFailed", "UpdateDeployment",
"Failed to update Deployment: %v", err)
}
// Return error to trigger reconcile retry (handles transient failures and conflicts)
return ctrl.Result{}, err
}
// Record event for successful deployment update (config change triggers rollout)
if r.Recorder != nil {
r.Recorder.Event(vmcp, corev1.EventTypeNormal, "DeploymentUpdated",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeNormal, "DeploymentUpdated", "UpdateDeployment",
"Deployment updated, rolling out new configuration")
}
// Return empty result to continue with rest of reconciliation
Expand Down Expand Up @@ -983,14 +983,14 @@ func (r *VirtualMCPServerReconciler) ensureService(
ctxLogger.Error(err, "Failed to create new Service")
// Record event for service creation failure
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "ServiceCreationFailed",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "ServiceCreationFailed", "CreateService",
"Failed to create Service: %v", err)
}
return ctrl.Result{}, err
}
// Record event for successful service creation
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeNormal, "ServiceCreated",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeNormal, "ServiceCreated", "CreateService",
"Service %s created successfully", serviceName)
}
// Return empty result to continue with rest of reconciliation
Expand Down Expand Up @@ -1905,7 +1905,7 @@ func (r *VirtualMCPServerReconciler) validateEmbeddingServerRef(
)
statusManager.SetObservedGeneration(vmcp.Generation)
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "EmbeddingServerRefNotFound",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "EmbeddingServerRefNotFound", "ValidateEmbeddingServerRef",
"Referenced EmbeddingServer %s not found", refName)
}
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/thv-operator/controllers/virtualmcpserver_vmcpconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (r *VirtualMCPServerReconciler) populateOptimizerEmbeddingService(
"consider using embeddingServerRef for managed lifecycle",
"embeddingService", config.Optimizer.EmbeddingService)
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "EmbeddingServiceManual",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "EmbeddingServiceManual", "ValidateEmbeddingService",
"config.optimizer.embeddingService is set without embeddingServerRef; "+
"specifying an embeddingServerRef is the recommended configuration")
}
Expand All @@ -157,7 +157,7 @@ func (r *VirtualMCPServerReconciler) populateOptimizerFromRef(
"overridden", config.Optimizer.EmbeddingService,
"new", esURL)
if r.Recorder != nil {
r.Recorder.Eventf(vmcp, corev1.EventTypeWarning, "EmbeddingServiceOverridden",
r.Recorder.Eventf(vmcp, nil, corev1.EventTypeWarning, "EmbeddingServiceOverridden", "ResolveEmbeddingService",
"config.optimizer.embeddingService will be replaced by EmbeddingServerRef %q URL",
vmcp.Spec.EmbeddingServerRef.Name)
}
Expand Down
Loading
Loading