@@ -1635,23 +1635,25 @@ func TestComputeMachineDeployment(t *testing.T) {
1635
1635
}).
1636
1636
Build ()
1637
1637
1638
- machineDeploymentStable := builder .MachineDeployment ("test-namespace" , "md-1 " ).
1638
+ machineDeploymentStable := builder .MachineDeployment ("test-namespace" , "md-stable " ).
1639
1639
WithGeneration (1 ).
1640
1640
WithReplicas (2 ).
1641
1641
WithStatus (clusterv1.MachineDeploymentStatus {
1642
1642
ObservedGeneration : 2 ,
1643
1643
Replicas : 2 ,
1644
+ ReadyReplicas : 2 ,
1644
1645
UpdatedReplicas : 2 ,
1645
1646
AvailableReplicas : 2 ,
1646
1647
}).
1647
1648
Build ()
1648
1649
1649
- machineDeploymentRollingOut := builder .MachineDeployment ("test-namespace" , "md-1 " ).
1650
+ machineDeploymentRollingOut := builder .MachineDeployment ("test-namespace" , "md-rolling " ).
1650
1651
WithGeneration (1 ).
1651
1652
WithReplicas (2 ).
1652
1653
WithStatus (clusterv1.MachineDeploymentStatus {
1653
1654
ObservedGeneration : 2 ,
1654
1655
Replicas : 1 ,
1656
+ ReadyReplicas : 1 ,
1655
1657
UpdatedReplicas : 1 ,
1656
1658
AvailableReplicas : 1 ,
1657
1659
}).
@@ -1669,28 +1671,46 @@ func TestComputeMachineDeployment(t *testing.T) {
1669
1671
name string
1670
1672
machineDeploymentsState scope.MachineDeploymentsStateMap
1671
1673
currentMDVersion * string
1674
+ upgradeConcurrency string
1672
1675
topologyVersion string
1673
1676
expectedVersion string
1674
1677
}{
1675
1678
{
1676
1679
name : "use cluster.spec.topology.version if creating a new machine deployment" ,
1677
1680
machineDeploymentsState : nil ,
1681
+ upgradeConcurrency : "1" ,
1678
1682
currentMDVersion : nil ,
1679
1683
topologyVersion : "v1.2.3" ,
1680
1684
expectedVersion : "v1.2.3" ,
1681
1685
},
1682
1686
{
1683
- name : "use machine deployment's spec.template.spec.version if one of the machine deployments is rolling out" ,
1687
+ name : "use machine deployment's spec.template.spec.version if one of the machine deployments is rolling out, concurrency limit reached " ,
1684
1688
machineDeploymentsState : machineDeploymentsStateRollingOut ,
1689
+ upgradeConcurrency : "1" ,
1685
1690
currentMDVersion : pointer .String ("v1.2.2" ),
1686
1691
topologyVersion : "v1.2.3" ,
1687
1692
expectedVersion : "v1.2.2" ,
1688
1693
},
1694
+ {
1695
+ name : "use cluster.spec.topology.version if one of the machine deployments is rolling out, concurrency limit not reached" ,
1696
+ machineDeploymentsState : machineDeploymentsStateRollingOut ,
1697
+ upgradeConcurrency : "2" ,
1698
+ currentMDVersion : pointer .String ("v1.2.2" ),
1699
+ topologyVersion : "v1.2.3" ,
1700
+ expectedVersion : "v1.2.3" ,
1701
+ },
1689
1702
}
1690
1703
for _ , tt := range tests {
1691
1704
t .Run (tt .name , func (t * testing.T ) {
1692
1705
g := NewWithT (t )
1693
- s := scope .New (cluster )
1706
+
1707
+ testCluster := cluster .DeepCopy ()
1708
+ if testCluster .Annotations == nil {
1709
+ testCluster .Annotations = map [string ]string {}
1710
+ }
1711
+ testCluster .Annotations [clusterv1 .ClusterTopologyUpgradeConcurrencyAnnotation ] = tt .upgradeConcurrency
1712
+
1713
+ s := scope .New (testCluster )
1694
1714
s .Blueprint = blueprint
1695
1715
s .Blueprint .Topology .Version = tt .topologyVersion
1696
1716
s .Blueprint .Topology .ControlPlane = clusterv1.ControlPlaneTopology {
@@ -1709,6 +1729,7 @@ func TestComputeMachineDeployment(t *testing.T) {
1709
1729
WithStatus (clusterv1.MachineDeploymentStatus {
1710
1730
ObservedGeneration : 2 ,
1711
1731
Replicas : 2 ,
1732
+ ReadyReplicas : 2 ,
1712
1733
UpdatedReplicas : 2 ,
1713
1734
AvailableReplicas : 2 ,
1714
1735
}).
@@ -1722,6 +1743,7 @@ func TestComputeMachineDeployment(t *testing.T) {
1722
1743
s .Current .ControlPlane = & scope.ControlPlaneState {
1723
1744
Object : controlPlaneStable123 ,
1724
1745
}
1746
+ s .UpgradeTracker .MachineDeployments .MarkRollingOut (s .Current .MachineDeployments .RollingOut ()... )
1725
1747
desiredControlPlaneState := & scope.ControlPlaneState {
1726
1748
Object : controlPlaneStable123 ,
1727
1749
}
@@ -1828,45 +1850,55 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1828
1850
//
1829
1851
// A machine deployment is considered upgrading if any of the above conditions
1830
1852
// is false.
1831
- machineDeploymentStable := builder .MachineDeployment ("test-namespace" , "md-1" ).
1832
- WithGeneration (1 ).
1833
- WithReplicas (2 ).
1834
- WithStatus (clusterv1.MachineDeploymentStatus {
1835
- ObservedGeneration : 2 ,
1836
- Replicas : 2 ,
1837
- UpdatedReplicas : 2 ,
1838
- AvailableReplicas : 2 ,
1839
- ReadyReplicas : 2 ,
1840
- UnavailableReplicas : 0 ,
1841
- }).
1842
- Build ()
1843
- machineDeploymentRollingOut := builder .MachineDeployment ("test-namespace" , "md-2" ).
1844
- WithGeneration (1 ).
1845
- WithReplicas (2 ).
1846
- WithStatus (clusterv1.MachineDeploymentStatus {
1847
- ObservedGeneration : 2 ,
1848
- Replicas : 1 ,
1849
- UpdatedReplicas : 1 ,
1850
- AvailableReplicas : 1 ,
1851
- ReadyReplicas : 1 ,
1852
- UnavailableReplicas : 1 ,
1853
- }).
1854
- Build ()
1853
+ stableMachineDeployment := func (ns , name string ) * clusterv1.MachineDeployment {
1854
+ return builder .MachineDeployment (ns , name ).
1855
+ WithGeneration (1 ).
1856
+ WithReplicas (2 ).
1857
+ WithStatus (clusterv1.MachineDeploymentStatus {
1858
+ ObservedGeneration : 2 ,
1859
+ Replicas : 2 ,
1860
+ UpdatedReplicas : 2 ,
1861
+ AvailableReplicas : 2 ,
1862
+ ReadyReplicas : 2 ,
1863
+ UnavailableReplicas : 0 ,
1864
+ }).
1865
+ Build ()
1866
+ }
1855
1867
1856
- machineDeploymentsStateStable := scope.MachineDeploymentsStateMap {
1857
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
1858
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
1868
+ rollingMachineDeployment := func (ns , name string ) * clusterv1.MachineDeployment {
1869
+ return builder .MachineDeployment (ns , name ).
1870
+ WithGeneration (1 ).
1871
+ WithReplicas (2 ).
1872
+ WithStatus (clusterv1.MachineDeploymentStatus {
1873
+ ObservedGeneration : 2 ,
1874
+ Replicas : 1 ,
1875
+ UpdatedReplicas : 1 ,
1876
+ AvailableReplicas : 1 ,
1877
+ ReadyReplicas : 1 ,
1878
+ UnavailableReplicas : 1 ,
1879
+ }).
1880
+ Build ()
1881
+ }
1882
+
1883
+ twoMachineDeploymentsStateStable := scope.MachineDeploymentsStateMap {
1884
+ "md1" : & scope.MachineDeploymentState {Object : stableMachineDeployment ("test1" , "md1" )},
1885
+ "md2" : & scope.MachineDeploymentState {Object : stableMachineDeployment ("test1" , "md2" )},
1886
+ }
1887
+ oneStableOneRollingMachineDeploymentState := scope.MachineDeploymentsStateMap {
1888
+ "md1" : & scope.MachineDeploymentState {Object : stableMachineDeployment ("test1" , "md1" )},
1889
+ "md2" : & scope.MachineDeploymentState {Object : rollingMachineDeployment ("test1" , "md2" )},
1859
1890
}
1860
- machineDeploymentsStateRollingOut := scope.MachineDeploymentsStateMap {
1861
- "md1" : & scope.MachineDeploymentState {Object : machineDeploymentStable },
1862
- "md2" : & scope.MachineDeploymentState {Object : machineDeploymentRollingOut },
1891
+ twoRollingMachineDeploymentState := scope.MachineDeploymentsStateMap {
1892
+ "md1" : & scope.MachineDeploymentState {Object : rollingMachineDeployment ( "test1" , "md1" ) },
1893
+ "md2" : & scope.MachineDeploymentState {Object : rollingMachineDeployment ( "test1" , "md2" ) },
1863
1894
}
1864
1895
1865
1896
tests := []struct {
1866
1897
name string
1867
1898
machineDeploymentTopology clusterv1.MachineDeploymentTopology
1868
1899
currentMachineDeploymentState * scope.MachineDeploymentState
1869
1900
machineDeploymentsStateMap scope.MachineDeploymentsStateMap
1901
+ upgradeConcurrency int
1870
1902
currentControlPlane * unstructured.Unstructured
1871
1903
desiredControlPlane * unstructured.Unstructured
1872
1904
topologyVersion string
@@ -1889,16 +1921,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1889
1921
},
1890
1922
},
1891
1923
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1892
- machineDeploymentsStateMap : machineDeploymentsStateStable ,
1893
- currentControlPlane : controlPlaneStable123 ,
1894
- desiredControlPlane : controlPlaneDesired ,
1895
- topologyVersion : "v1.2.3" ,
1896
- expectedVersion : "v1.2.2" ,
1897
- },
1898
- {
1899
- name : "should return machine deployment's spec.template.spec.version if any one of the machine deployments is rolling out" ,
1900
- currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1901
- machineDeploymentsStateMap : machineDeploymentsStateRollingOut ,
1924
+ machineDeploymentsStateMap : twoMachineDeploymentsStateStable ,
1902
1925
currentControlPlane : controlPlaneStable123 ,
1903
1926
desiredControlPlane : controlPlaneDesired ,
1904
1927
topologyVersion : "v1.2.3" ,
@@ -1908,7 +1931,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1908
1931
// Control plane is considered upgrading if the control plane's spec.version and status.version is not equal.
1909
1932
name : "should return machine deployment's spec.template.spec.version if control plane is upgrading" ,
1910
1933
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1911
- machineDeploymentsStateMap : machineDeploymentsStateStable ,
1934
+ machineDeploymentsStateMap : twoMachineDeploymentsStateStable ,
1912
1935
currentControlPlane : controlPlaneUpgrading ,
1913
1936
topologyVersion : "v1.2.3" ,
1914
1937
expectedVersion : "v1.2.2" ,
@@ -1917,7 +1940,7 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1917
1940
// Control plane is considered ready to upgrade if spec.version of current and desired control planes are not equal.
1918
1941
name : "should return machine deployment's spec.template.spec.version if control plane is ready to upgrade" ,
1919
1942
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1920
- machineDeploymentsStateMap : machineDeploymentsStateStable ,
1943
+ machineDeploymentsStateMap : twoMachineDeploymentsStateStable ,
1921
1944
currentControlPlane : controlPlaneStable122 ,
1922
1945
desiredControlPlane : controlPlaneDesired ,
1923
1946
topologyVersion : "v1.2.3" ,
@@ -1927,20 +1950,40 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1927
1950
// Control plane is considered scaling if its spec.replicas is not equal to any of status.replicas, status.readyReplicas or status.updatedReplicas.
1928
1951
name : "should return machine deployment's spec.template.spec.version if control plane is scaling" ,
1929
1952
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1930
- machineDeploymentsStateMap : machineDeploymentsStateStable ,
1953
+ machineDeploymentsStateMap : twoMachineDeploymentsStateStable ,
1931
1954
currentControlPlane : controlPlaneScaling ,
1932
1955
topologyVersion : "v1.2.3" ,
1933
1956
expectedVersion : "v1.2.2" ,
1934
1957
},
1935
1958
{
1936
1959
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" ,
1937
1960
currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1938
- machineDeploymentsStateMap : machineDeploymentsStateStable ,
1961
+ machineDeploymentsStateMap : twoMachineDeploymentsStateStable ,
1939
1962
currentControlPlane : controlPlaneStable123 ,
1940
1963
desiredControlPlane : controlPlaneDesired ,
1941
1964
topologyVersion : "v1.2.3" ,
1942
1965
expectedVersion : "v1.2.3" ,
1943
1966
},
1967
+ {
1968
+ name : "should return cluster.spec.topology.version if control plane is stable, other machine deployments are rolling out, concurrency limit not reached" ,
1969
+ currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1970
+ machineDeploymentsStateMap : oneStableOneRollingMachineDeploymentState ,
1971
+ upgradeConcurrency : 2 ,
1972
+ currentControlPlane : controlPlaneStable123 ,
1973
+ desiredControlPlane : controlPlaneDesired ,
1974
+ topologyVersion : "v1.2.3" ,
1975
+ expectedVersion : "v1.2.3" ,
1976
+ },
1977
+ {
1978
+ name : "should return machine deployment's spec.template.spec.version if control plane is stable, other machine deployments are rolling out, concurrency limit reached" ,
1979
+ currentMachineDeploymentState : & scope.MachineDeploymentState {Object : builder .MachineDeployment ("test1" , "md-current" ).WithVersion ("v1.2.2" ).Build ()},
1980
+ machineDeploymentsStateMap : twoRollingMachineDeploymentState ,
1981
+ upgradeConcurrency : 2 ,
1982
+ currentControlPlane : controlPlaneStable123 ,
1983
+ desiredControlPlane : controlPlaneDesired ,
1984
+ topologyVersion : "v1.2.3" ,
1985
+ expectedVersion : "v1.2.2" ,
1986
+ },
1944
1987
}
1945
1988
1946
1989
for _ , tt := range tests {
@@ -1959,9 +2002,10 @@ func TestComputeMachineDeploymentVersion(t *testing.T) {
1959
2002
ControlPlane : & scope.ControlPlaneState {Object : tt .currentControlPlane },
1960
2003
MachineDeployments : tt .machineDeploymentsStateMap ,
1961
2004
},
1962
- UpgradeTracker : scope .NewUpgradeTracker (),
2005
+ UpgradeTracker : scope .NewUpgradeTracker (scope . MaxMDUpgradeConcurrency ( tt . upgradeConcurrency ) ),
1963
2006
}
1964
2007
desiredControlPlaneState := & scope.ControlPlaneState {Object : tt .desiredControlPlane }
2008
+ s .UpgradeTracker .MachineDeployments .MarkRollingOut (s .Current .MachineDeployments .RollingOut ()... )
1965
2009
version , err := computeMachineDeploymentVersion (s , tt .machineDeploymentTopology , desiredControlPlaneState , tt .currentMachineDeploymentState )
1966
2010
g .Expect (err ).NotTo (HaveOccurred ())
1967
2011
g .Expect (version ).To (Equal (tt .expectedVersion ))
0 commit comments