@@ -298,7 +298,12 @@ func (r *MCPServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
298
298
err = r .Get (ctx , types.NamespacedName {Name : mcpServer .Name , Namespace : mcpServer .Namespace }, deployment )
299
299
if err != nil && errors .IsNotFound (err ) {
300
300
// Validate PodTemplateSpec and update status
301
- r .validateAndUpdatePodTemplateStatus (ctx , mcpServer )
301
+ if ! r .validateAndUpdatePodTemplateStatus (ctx , mcpServer ) {
302
+ // Invalid PodTemplateSpec - return without error to avoid infinite retries
303
+ // The user must fix the spec and the next reconciliation will retry
304
+ ctxLogger .Info ("Skipping deployment creation due to invalid PodTemplateSpec" )
305
+ return ctrl.Result {}, nil
306
+ }
302
307
303
308
// Define a new deployment
304
309
dep := r .deploymentForMCPServer (ctx , mcpServer )
@@ -370,7 +375,12 @@ func (r *MCPServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
370
375
// Check if the deployment spec changed
371
376
if r .deploymentNeedsUpdate (ctx , deployment , mcpServer ) {
372
377
// Validate PodTemplateSpec and update status
373
- r .validateAndUpdatePodTemplateStatus (ctx , mcpServer )
378
+ if ! r .validateAndUpdatePodTemplateStatus (ctx , mcpServer ) {
379
+ // Invalid PodTemplateSpec - return without error to avoid infinite retries
380
+ // The user must fix the spec and the next reconciliation will retry
381
+ ctxLogger .Info ("Skipping deployment update due to invalid PodTemplateSpec" )
382
+ return ctrl.Result {}, nil
383
+ }
374
384
375
385
// Update the deployment
376
386
newDeployment := r .deploymentForMCPServer (ctx , mcpServer )
@@ -416,43 +426,55 @@ func setImageValidationCondition(mcpServer *mcpv1alpha1.MCPServer, status metav1
416
426
417
427
// validateAndUpdatePodTemplateStatus validates the PodTemplateSpec and updates the MCPServer status
418
428
// with appropriate conditions and events
419
- func (r * MCPServerReconciler ) validateAndUpdatePodTemplateStatus (ctx context.Context , mcpServer * mcpv1alpha1.MCPServer ) {
429
+ func (r * MCPServerReconciler ) validateAndUpdatePodTemplateStatus (ctx context.Context , mcpServer * mcpv1alpha1.MCPServer ) bool {
420
430
ctxLogger := log .FromContext (ctx )
421
431
422
432
// Only validate if PodTemplateSpec is provided
423
433
if mcpServer .Spec .PodTemplateSpec == nil || mcpServer .Spec .PodTemplateSpec .Raw == nil {
424
- return
434
+ // No PodTemplateSpec provided, validation passes
435
+ return true
425
436
}
426
437
427
438
_ , err := NewMCPServerPodTemplateSpecBuilder (mcpServer .Spec .PodTemplateSpec )
428
439
if err != nil {
429
440
// Record event for invalid PodTemplateSpec
430
441
r .Recorder .Eventf (mcpServer , corev1 .EventTypeWarning , "InvalidPodTemplateSpec" ,
431
- "Failed to parse PodTemplateSpec: %v. Deployment will continue without pod customizations ." , err )
442
+ "Failed to parse PodTemplateSpec: %v. Deployment blocked until PodTemplateSpec is fixed ." , err )
432
443
433
444
// Set condition for invalid PodTemplateSpec
434
445
meta .SetStatusCondition (& mcpServer .Status .Conditions , metav1.Condition {
435
446
Type : "PodTemplateValid" ,
436
447
Status : metav1 .ConditionFalse ,
437
448
ObservedGeneration : mcpServer .Generation ,
438
449
Reason : "InvalidPodTemplateSpec" ,
439
- Message : fmt .Sprintf ("Failed to parse PodTemplateSpec: %v. Deployment continues without customizations." , err ),
440
- })
441
- } else {
442
- // Set condition for valid PodTemplateSpec
443
- meta .SetStatusCondition (& mcpServer .Status .Conditions , metav1.Condition {
444
- Type : "PodTemplateValid" ,
445
- Status : metav1 .ConditionTrue ,
446
- ObservedGeneration : mcpServer .Generation ,
447
- Reason : "ValidPodTemplateSpec" ,
448
- Message : "PodTemplateSpec is valid" ,
450
+ Message : fmt .Sprintf ("Failed to parse PodTemplateSpec: %v. Deployment blocked until fixed." , err ),
449
451
})
452
+
453
+ // Update status with the condition
454
+ if statusErr := r .Status ().Update (ctx , mcpServer ); statusErr != nil {
455
+ ctxLogger .Error (statusErr , "Failed to update MCPServer status with PodTemplateSpec validation" )
456
+ }
457
+
458
+ ctxLogger .Error (err , "PodTemplateSpec validation failed" )
459
+ return false
450
460
}
451
461
462
+ // Set condition for valid PodTemplateSpec
463
+ meta .SetStatusCondition (& mcpServer .Status .Conditions , metav1.Condition {
464
+ Type : "PodTemplateValid" ,
465
+ Status : metav1 .ConditionTrue ,
466
+ ObservedGeneration : mcpServer .Generation ,
467
+ Reason : "ValidPodTemplateSpec" ,
468
+ Message : "PodTemplateSpec is valid" ,
469
+ })
470
+
452
471
// Update status with the condition
453
472
if statusErr := r .Status ().Update (ctx , mcpServer ); statusErr != nil {
454
473
ctxLogger .Error (statusErr , "Failed to update MCPServer status with PodTemplateSpec validation" )
455
474
}
475
+
476
+ ctxLogger .V (1 ).Info ("PodTemplateSpec validation completed successfully" )
477
+ return true
456
478
}
457
479
458
480
// handleRestartAnnotation checks if the restart annotation has been updated and triggers a restart if needed
0 commit comments