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