@@ -671,6 +671,52 @@ func TestComputeDesiredMachineSet(t *testing.T) {
671
671
g .Expect (err ).To (BeNil ())
672
672
assertMachineSet (g , actualMS , expectedMS )
673
673
})
674
+
675
+ t .Run ("should compute the updated MachineSet when no old MachineSets exists (" , func (t * testing.T ) {
676
+ // Set rollout strategy to "OnDelete".
677
+ deployment := deployment .DeepCopy ()
678
+ deployment .Spec .Strategy = & clusterv1.MachineDeploymentStrategy {
679
+ Type : clusterv1 .OnDeleteMachineDeploymentStrategyType ,
680
+ RollingUpdate : nil ,
681
+ }
682
+
683
+ uniqueID := apirand .String (5 )
684
+ existingMS := skeletonMSBasedOnMD .DeepCopy ()
685
+ // computeDesiredMachineSet should retain the UID, name and the "machine-template-hash" label value
686
+ // of the existing machine.
687
+ // Other fields like labels, annotations, node timeout, etc are expected to change.
688
+ existingMSUID := types .UID ("abc-123-uid" )
689
+ existingMS .UID = existingMSUID
690
+ existingMS .Name = deployment .Name + "-" + uniqueID
691
+ existingMS .Labels = map [string ]string {
692
+ clusterv1 .MachineDeploymentUniqueLabel : uniqueID ,
693
+ "ms-label-1" : "ms-value-1" ,
694
+ }
695
+ existingMS .Annotations = nil
696
+ existingMS .Spec .Template .Labels = map [string ]string {
697
+ clusterv1 .MachineDeploymentUniqueLabel : uniqueID ,
698
+ "ms-label-2" : "ms-value-2" ,
699
+ }
700
+ existingMS .Spec .Template .Annotations = nil
701
+ existingMS .Spec .Template .Spec .NodeDrainTimeout = duration5s
702
+ existingMS .Spec .Template .Spec .NodeDeletionTimeout = duration5s
703
+ existingMS .Spec .Template .Spec .NodeVolumeDetachTimeout = duration5s
704
+ existingMS .Spec .DeletePolicy = string (clusterv1 .NewestMachineSetDeletePolicy )
705
+ existingMS .Spec .MinReadySeconds = 0
706
+
707
+ expectedMS := skeletonMSBasedOnMD .DeepCopy ()
708
+ expectedMS .UID = existingMSUID
709
+ expectedMS .Name = deployment .Name + "-" + uniqueID
710
+ expectedMS .Labels [clusterv1 .MachineDeploymentUniqueLabel ] = uniqueID
711
+ expectedMS .Spec .Template .Labels [clusterv1 .MachineDeploymentUniqueLabel ] = uniqueID
712
+ // DeletePolicy should be empty with rollout strategy "OnDelete".
713
+ expectedMS .Spec .DeletePolicy = ""
714
+
715
+ g := NewWithT (t )
716
+ actualMS , err := (& Reconciler {}).computeDesiredMachineSet (deployment , existingMS , nil , log )
717
+ g .Expect (err ).To (BeNil ())
718
+ assertMachineSet (g , actualMS , expectedMS )
719
+ })
674
720
}
675
721
676
722
func assertMachineSet (g * WithT , actualMS * clusterv1.MachineSet , expectedMS * clusterv1.MachineSet ) {
0 commit comments