@@ -637,43 +637,6 @@ func TestComputeControlPlaneVersion(t *testing.T) {
637
637
t .Run ("Compute control plane version under various circumstances" , func (t * testing.T ) {
638
638
defer utilfeature .SetFeatureGateDuringTest (t , feature .Gates , feature .RuntimeSDK , true )()
639
639
640
- // Note: the version used by the machine deployments does
641
- // not affect how we're determining the control plane version.
642
- // We only want to know if the machine deployments are stable.
643
- //
644
- // A machine deployment is considered stable if all the following are true:
645
- // - md.spec.replicas == md.status.replicas
646
- // - md.spec.replicas == md.status.updatedReplicas
647
- // - md.spec.replicas == md.status.readyReplicas
648
- // - md.Generation < md.status.observedGeneration
649
- //
650
- // A machine deployment is considered upgrading if any of the above conditions
651
- // is false.
652
- machineDeploymentStable := builder .MachineDeployment ("test-namespace" , "md1" ).
653
- WithGeneration (int64 (1 )).
654
- WithReplicas (int32 (2 )).
655
- WithStatus (clusterv1.MachineDeploymentStatus {
656
- ObservedGeneration : 2 ,
657
- Replicas : 2 ,
658
- UpdatedReplicas : 2 ,
659
- AvailableReplicas : 2 ,
660
- ReadyReplicas : 2 ,
661
- UnavailableReplicas : 0 ,
662
- }).
663
- Build ()
664
- machineDeploymentRollingOut := builder .MachineDeployment ("test-namespace" , "md2" ).
665
- WithGeneration (int64 (1 )).
666
- WithReplicas (int32 (2 )).
667
- WithStatus (clusterv1.MachineDeploymentStatus {
668
- ObservedGeneration : 2 ,
669
- Replicas : 1 ,
670
- UpdatedReplicas : 1 ,
671
- AvailableReplicas : 1 ,
672
- ReadyReplicas : 1 ,
673
- UnavailableReplicas : 0 ,
674
- }).
675
- Build ()
676
-
677
640
nonBlockingBeforeClusterUpgradeResponse := & runtimehooksv1.BeforeClusterUpgradeResponse {
678
641
CommonRetryResponse : runtimehooksv1.CommonRetryResponse {
679
642
CommonResponse : runtimehooksv1.CommonResponse {
@@ -708,13 +671,13 @@ func TestComputeControlPlaneVersion(t *testing.T) {
708
671
}
709
672
710
673
tests := []struct {
711
- name string
712
- hookResponse * runtimehooksv1.BeforeClusterUpgradeResponse
713
- topologyVersion string
714
- controlPlaneObj * unstructured.Unstructured
715
- machineDeploymentsState scope. MachineDeploymentsStateMap
716
- expectedVersion string
717
- wantErr bool
674
+ name string
675
+ hookResponse * runtimehooksv1.BeforeClusterUpgradeResponse
676
+ topologyVersion string
677
+ controlPlaneObj * unstructured.Unstructured
678
+ upgradingMachineDeployments [] string
679
+ expectedVersion string
680
+ wantErr bool
718
681
}{
719
682
{
720
683
name : "should return cluster.spec.topology.version if creating a new control plane" ,
@@ -779,7 +742,7 @@ func TestComputeControlPlaneVersion(t *testing.T) {
779
742
expectedVersion : "v1.2.2" ,
780
743
},
781
744
{
782
- name : "should return controlplane.spec.version if control plane is not upgrading and not scaling and one of the machine deployments is rolling out " ,
745
+ name : "should return controlplane.spec.version if control plane is not upgrading and not scaling and one of the machine deployments is upgrading " ,
783
746
topologyVersion : "v1.2.3" ,
784
747
controlPlaneObj : builder .ControlPlane ("test1" , "cp1" ).
785
748
WithSpecFields (map [string ]interface {}{
@@ -794,14 +757,11 @@ func TestComputeControlPlaneVersion(t *testing.T) {
794
757
"status.unavailableReplicas" : int64 (0 ),
795
758
}).
796
759
Build (),
797
- machineDeploymentsState : scope.MachineDeploymentsStateMap {
798
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
799
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentRollingOut },
800
- },
801
- expectedVersion : "v1.2.2" ,
760
+ upgradingMachineDeployments : []string {"md1" },
761
+ expectedVersion : "v1.2.2" ,
802
762
},
803
763
{
804
- name : "should return cluster.spec.topology.version if control plane is not upgrading and not scaling and none of the machine deployments are rolling out - hook returns non blocking response" ,
764
+ name : "should return cluster.spec.topology.version if control plane is not upgrading and not scaling and none of the machine deployments are upgrading - hook returns non blocking response" ,
805
765
hookResponse : nonBlockingBeforeClusterUpgradeResponse ,
806
766
topologyVersion : "v1.2.3" ,
807
767
controlPlaneObj : builder .ControlPlane ("test1" , "cp1" ).
@@ -817,11 +777,8 @@ func TestComputeControlPlaneVersion(t *testing.T) {
817
777
"status.unavailableReplicas" : int64 (0 ),
818
778
}).
819
779
Build (),
820
- machineDeploymentsState : scope.MachineDeploymentsStateMap {
821
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
822
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
823
- },
824
- expectedVersion : "v1.2.3" ,
780
+ upgradingMachineDeployments : []string {},
781
+ expectedVersion : "v1.2.3" ,
825
782
},
826
783
{
827
784
name : "should return the controlplane.spec.version if the BeforeClusterUpgrade hooks returns a blocking response" ,
@@ -840,10 +797,6 @@ func TestComputeControlPlaneVersion(t *testing.T) {
840
797
"status.unavailableReplicas" : int64 (0 ),
841
798
}).
842
799
Build (),
843
- machineDeploymentsState : scope.MachineDeploymentsStateMap {
844
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
845
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
846
- },
847
800
expectedVersion : "v1.2.2" ,
848
801
},
849
802
{
@@ -863,10 +816,6 @@ func TestComputeControlPlaneVersion(t *testing.T) {
863
816
"status.unavailableReplicas" : int64 (0 ),
864
817
}).
865
818
Build (),
866
- machineDeploymentsState : scope.MachineDeploymentsStateMap {
867
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
868
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
869
- },
870
819
expectedVersion : "v1.2.2" ,
871
820
wantErr : true ,
872
821
},
@@ -889,12 +838,14 @@ func TestComputeControlPlaneVersion(t *testing.T) {
889
838
Namespace : "test-ns" ,
890
839
},
891
840
},
892
- ControlPlane : & scope.ControlPlaneState {Object : tt .controlPlaneObj },
893
- MachineDeployments : tt .machineDeploymentsState ,
841
+ ControlPlane : & scope.ControlPlaneState {Object : tt .controlPlaneObj },
894
842
},
895
843
UpgradeTracker : scope .NewUpgradeTracker (),
896
844
HookResponseTracker : scope .NewHookResponseTracker (),
897
845
}
846
+ if len (tt .upgradingMachineDeployments ) > 0 {
847
+ s .UpgradeTracker .MachineDeployments .MarkUpgrading (tt .upgradingMachineDeployments ... )
848
+ }
898
849
899
850
runtimeClient := fakeruntimeclient .NewRuntimeClientBuilder ().
900
851
WithCatalog (catalog ).
@@ -1723,7 +1674,6 @@ func TestComputeMachineDeployment(t *testing.T) {
1723
1674
s .Current .ControlPlane = & scope.ControlPlaneState {
1724
1675
Object : controlPlaneStable123 ,
1725
1676
}
1726
- s .UpgradeTracker .MachineDeployments .MarkRollingOut (s .Current .MachineDeployments .RollingOut ()... )
1727
1677
desiredControlPlaneState := & scope.ControlPlaneState {
1728
1678
Object : controlPlaneStable123 ,
1729
1679
}
@@ -1733,7 +1683,7 @@ func TestComputeMachineDeployment(t *testing.T) {
1733
1683
Name : "big-pool-of-machines" ,
1734
1684
Replicas : pointer .Int32 (2 ),
1735
1685
}
1736
- s .UpgradeTracker .MachineDeployments .MarkUpgradingAndRollingOut (tt .upgradingMachineDeployments ... )
1686
+ s .UpgradeTracker .MachineDeployments .MarkUpgrading (tt .upgradingMachineDeployments ... )
1737
1687
obj , err := computeMachineDeployment (ctx , s , desiredControlPlaneState , mdTopology )
1738
1688
g .Expect (err ).NotTo (HaveOccurred ())
1739
1689
g .Expect (* obj .Object .Spec .Template .Spec .Version ).To (Equal (tt .expectedVersion ))
@@ -1883,7 +1833,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1883
1833
expectedVersion : "v1.2.2" ,
1884
1834
},
1885
1835
{
1886
- name : "should return cluster.spec.topology.version if the control plane is not upgrading, not scaling, not ready to upgrade and none of the machine deployments are rolling out " ,
1836
+ name : "should return cluster.spec.topology.version if the control plane is not upgrading, not scaling, not ready to upgrade and none of the machine deployments are upgrading " ,
1887
1837
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1888
1838
upgradingMachineDeployments : []string {},
1889
1839
currentControlPlane : controlPlaneStable123 ,
@@ -1892,7 +1842,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1892
1842
expectedVersion : "v1.2.3" ,
1893
1843
},
1894
1844
{
1895
- name : "should return cluster.spec.topology.version if control plane is stable, other machine deployments are rolling out , concurrency limit not reached" ,
1845
+ name : "should return cluster.spec.topology.version if control plane is stable, other machine deployments are upgrading , concurrency limit not reached" ,
1896
1846
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1897
1847
upgradingMachineDeployments : []string {"upgrading-md1" },
1898
1848
upgradeConcurrency : 2 ,
@@ -1902,7 +1852,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1902
1852
expectedVersion : "v1.2.3" ,
1903
1853
},
1904
1854
{
1905
- name : "should return machine deployment's spec.template.spec.version if control plane is stable, other machine deployments are rolling out , concurrency limit reached" ,
1855
+ name : "should return machine deployment's spec.template.spec.version if control plane is stable, other machine deployments are upgrading , concurrency limit reached" ,
1906
1856
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1907
1857
upgradingMachineDeployments : []string {"upgrading-md1" , "upgrading-md2" },
1908
1858
upgradeConcurrency : 2 ,
@@ -1931,7 +1881,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1931
1881
UpgradeTracker : scope .NewUpgradeTracker (scope .MaxMDUpgradeConcurrency (tt .upgradeConcurrency )),
1932
1882
}
1933
1883
desiredControlPlaneState := & scope.ControlPlaneState {Object : tt .desiredControlPlane }
1934
- s .UpgradeTracker .MachineDeployments .MarkUpgradingAndRollingOut (tt .upgradingMachineDeployments ... )
1884
+ s .UpgradeTracker .MachineDeployments .MarkUpgrading (tt .upgradingMachineDeployments ... )
1935
1885
version , err := computeMachineDeploymentVersion (s , tt .machineDeploymentTopology , desiredControlPlaneState , tt .currentMachineDeploymentState )
1936
1886
g .Expect (err ).NotTo (HaveOccurred ())
1937
1887
g .Expect (version ).To (Equal (tt .expectedVersion ))
0 commit comments