@@ -32,7 +32,6 @@ import (
32
32
"k8s.io/apimachinery/pkg/util/validation"
33
33
"k8s.io/apimachinery/pkg/util/validation/field"
34
34
"k8s.io/apimachinery/pkg/util/wait"
35
- "k8s.io/klog/v2"
36
35
ctrl "sigs.k8s.io/controller-runtime"
37
36
"sigs.k8s.io/controller-runtime/pkg/client"
38
37
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -446,6 +445,11 @@ func (webhook *Cluster) validateTopology(ctx context.Context, oldCluster, newClu
446
445
}
447
446
448
447
func (webhook * Cluster ) validateTopologyVersion (ctx context.Context , fldPath * field.Path , fldValue string , inVersion , oldVersion semver.Version , oldCluster * clusterv1.Cluster ) * field.Error {
448
+ // Nothing to do if the version doesn't change.
449
+ if version .Compare (inVersion , oldVersion , version .WithBuildTags ()) == 0 {
450
+ return nil
451
+ }
452
+
449
453
// Version could only be increased.
450
454
if inVersion .NE (semver.Version {}) && oldVersion .NE (semver.Version {}) && version .Compare (inVersion , oldVersion , version .WithBuildTags ()) == - 1 {
451
455
return field .Invalid (
@@ -469,39 +473,27 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
469
473
)
470
474
}
471
475
472
- // Only check the following cases if the minor version increases by 1 (we already return above for >= 2).
473
- ceilVersion = semver.Version {
474
- Major : oldVersion .Major ,
475
- Minor : oldVersion .Minor + 1 ,
476
- Patch : 0 ,
477
- }
478
-
479
- // Return early if its not a minor version upgrade.
480
- if ! inVersion .GTE (ceilVersion ) {
481
- return nil
482
- }
483
-
484
476
allErrs := []error {}
485
477
// minor version cannot be increased if control plane is upgrading or not yet on the current version
486
478
if err := validateTopologyControlPlaneVersion (ctx , webhook .Client , oldCluster , oldVersion ); err != nil {
487
- allErrs = append (allErrs , fmt . Errorf ( "blocking version update due to ControlPlane version check: %v" , err ) )
479
+ allErrs = append (allErrs , err )
488
480
}
489
481
490
482
// minor version cannot be increased if MachineDeployments are upgrading or not yet on the current version
491
483
if err := validateTopologyMachineDeploymentVersions (ctx , webhook .Client , oldCluster , oldVersion ); err != nil {
492
- allErrs = append (allErrs , fmt . Errorf ( "blocking version update due to MachineDeployment version check: %v" , err ) )
484
+ allErrs = append (allErrs , err )
493
485
}
494
486
495
487
// minor version cannot be increased if MachinePools are upgrading or not yet on the current version
496
488
if err := validateTopologyMachinePoolVersions (ctx , webhook .Client , webhook .ClusterCacheReader , oldCluster , oldVersion ); err != nil {
497
- allErrs = append (allErrs , fmt . Errorf ( "blocking version update due to MachinePool version check: %v" , err ) )
489
+ allErrs = append (allErrs , err )
498
490
}
499
491
500
492
if len (allErrs ) > 0 {
501
493
return field .Invalid (
502
494
fldPath ,
503
495
fldValue ,
504
- fmt .Sprintf ("minor version update cannot happen at this time : %v" , kerrors .NewAggregate (allErrs )),
496
+ fmt .Sprintf ("version cannot be changed : %v" , kerrors .NewAggregate (allErrs )),
505
497
)
506
498
}
507
499
@@ -511,39 +503,39 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
511
503
func validateTopologyControlPlaneVersion (ctx context.Context , ctrlClient client.Reader , oldCluster * clusterv1.Cluster , oldVersion semver.Version ) error {
512
504
cp , err := external .Get (ctx , ctrlClient , oldCluster .Spec .ControlPlaneRef )
513
505
if err != nil {
514
- return errors .Wrap (err , "failed to get ControlPlane object" )
506
+ return errors .Wrap (err , "failed to check if control plane is upgrading: failed to get control plane object" )
515
507
}
516
508
517
509
cpVersionString , err := contract .ControlPlane ().Version ().Get (cp )
518
510
if err != nil {
519
- return errors .Wrap (err , "failed to get ControlPlane version" )
511
+ return errors .Wrap (err , "failed to check if control plane is upgrading: failed to get control plane version" )
520
512
}
521
513
522
514
cpVersion , err := semver .ParseTolerant (* cpVersionString )
523
515
if err != nil {
524
516
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
525
- return errors .New ( "failed to parse version of ControlPlane" )
517
+ return errors .Wrapf ( err , "failed to check if control plane is upgrading: failed to parse control plane version %s" , * cpVersionString )
526
518
}
527
519
if cpVersion .NE (oldVersion ) {
528
- return fmt .Errorf ("ControlPlane version %q does not match the current version %q " , cpVersion , oldVersion )
520
+ return fmt .Errorf ("Cluster.spec.topology. version %s was not propagated to control plane yet (control plane version %s) " , oldVersion , cpVersion ) //nolint:stylecheck // capitalization is intentional
529
521
}
530
522
531
523
provisioning , err := contract .ControlPlane ().IsProvisioning (cp )
532
524
if err != nil {
533
- return errors .Wrap (err , "failed to check if ControlPlane is provisioning" )
525
+ return errors .Wrap (err , "failed to check if control plane is provisioning" )
534
526
}
535
527
536
528
if provisioning {
537
- return errors .New ("ControlPlane is currently provisioning" )
529
+ return errors .New ("control plane is currently provisioning" )
538
530
}
539
531
540
532
upgrading , err := contract .ControlPlane ().IsUpgrading (cp )
541
533
if err != nil {
542
- return errors .Wrap (err , "failed to check if ControlPlane is upgrading" )
534
+ return errors .Wrap (err , "failed to check if control plane is upgrading" )
543
535
}
544
536
545
537
if upgrading {
546
- return errors .New ("ControlPlane is still completing a previous upgrade" )
538
+ return errors .New ("control plane is still completing a previous upgrade" )
547
539
}
548
540
549
541
return nil
@@ -561,7 +553,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, ctrlClient c
561
553
client .InNamespace (oldCluster .Namespace ),
562
554
)
563
555
if err != nil {
564
- return errors .Wrap (err , "failed to read MachineDeployments for managed topology " )
556
+ return errors .Wrap (err , "failed to check if MachineDeployments are upgrading: failed to get MachineDeployments " )
565
557
}
566
558
567
559
if len (mds .Items ) == 0 {
@@ -576,7 +568,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, ctrlClient c
576
568
mdVersion , err := semver .ParseTolerant (* md .Spec .Template .Spec .Version )
577
569
if err != nil {
578
570
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
579
- return errors .Wrapf (err , "failed to parse MachineDeployment's %q version %q " , klog . KObj ( md ) , * md .Spec .Template .Spec .Version )
571
+ return errors .Wrapf (err , "failed to check if MachineDeployment %s is upgrading: failed to parse version %s " , md . Name , * md .Spec .Template .Spec .Version )
580
572
}
581
573
582
574
if mdVersion .NE (oldVersion ) {
@@ -586,15 +578,15 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, ctrlClient c
586
578
587
579
upgrading , err := check .IsMachineDeploymentUpgrading (ctx , ctrlClient , md )
588
580
if err != nil {
589
- return errors . Wrap ( err , "failed to check if MachineDeployment is upgrading" )
581
+ return err
590
582
}
591
583
if upgrading {
592
584
mdUpgradingNames = append (mdUpgradingNames , md .Name )
593
585
}
594
586
}
595
587
596
588
if len (mdUpgradingNames ) > 0 {
597
- return fmt .Errorf ("there are MachineDeployments still completing a previous upgrade: [%s]" , strings .Join (mdUpgradingNames , ", " ))
589
+ return fmt .Errorf ("there are still MachineDeployments completing a previous upgrade: [%s]" , strings .Join (mdUpgradingNames , ", " ))
598
590
}
599
591
600
592
return nil
@@ -612,17 +604,16 @@ func validateTopologyMachinePoolVersions(ctx context.Context, ctrlClient client.
612
604
client .InNamespace (oldCluster .Namespace ),
613
605
)
614
606
if err != nil {
615
- return errors .Wrap (err , "failed to read MachinePools for managed topology " )
607
+ return errors .Wrap (err , "failed to check if MachinePools are upgrading: failed to get MachinePools " )
616
608
}
617
609
618
- // Return early
619
610
if len (mps .Items ) == 0 {
620
611
return nil
621
612
}
622
613
623
614
wlClient , err := clusterCacheReader .GetReader (ctx , client .ObjectKeyFromObject (oldCluster ))
624
615
if err != nil {
625
- return errors .Wrap (err , "unable to get client for workload cluster" )
616
+ return errors .Wrap (err , "failed to check if MachinePools are upgrading: unable to get client for workload cluster" )
626
617
}
627
618
628
619
mpUpgradingNames := []string {}
@@ -633,7 +624,7 @@ func validateTopologyMachinePoolVersions(ctx context.Context, ctrlClient client.
633
624
mpVersion , err := semver .ParseTolerant (* mp .Spec .Template .Spec .Version )
634
625
if err != nil {
635
626
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
636
- return errors .Wrapf (err , "failed to parse MachinePool's %q version %q " , klog . KObj ( mp ) , * mp .Spec .Template .Spec .Version )
627
+ return errors .Wrapf (err , "failed to check if MachinePool %s is upgrading: failed to parse version %s " , mp . Name , * mp .Spec .Template .Spec .Version )
637
628
}
638
629
639
630
if mpVersion .NE (oldVersion ) {
@@ -643,15 +634,15 @@ func validateTopologyMachinePoolVersions(ctx context.Context, ctrlClient client.
643
634
644
635
upgrading , err := check .IsMachinePoolUpgrading (ctx , wlClient , mp )
645
636
if err != nil {
646
- return errors . Wrap ( err , "failed to check if MachinePool is upgrading" )
637
+ return err
647
638
}
648
639
if upgrading {
649
640
mpUpgradingNames = append (mpUpgradingNames , mp .Name )
650
641
}
651
642
}
652
643
653
644
if len (mpUpgradingNames ) > 0 {
654
- return fmt .Errorf ("there are MachinePools still completing a previous upgrade: [%s]" , strings .Join (mpUpgradingNames , ", " ))
645
+ return fmt .Errorf ("there are still MachinePools completing a previous upgrade: [%s]" , strings .Join (mpUpgradingNames , ", " ))
655
646
}
656
647
657
648
return nil
0 commit comments