@@ -1775,18 +1775,6 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1775
1775
Build ()
1776
1776
1777
1777
maxUnhealthy := intstr .Parse ("45%" )
1778
- // TODO: (killianmuldoon) This builder should be copied and not just passed around.
1779
- mhcBuilder := builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1780
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1781
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1782
- {
1783
- Type : corev1 .NodeReady ,
1784
- Status : corev1 .ConditionUnknown ,
1785
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1786
- },
1787
- }).
1788
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1789
- WithClusterName ("cluster1" )
1790
1778
1791
1779
infrastructureMachineTemplate := builder .InfrastructureMachineTemplate (metav1 .NamespaceDefault , "infrastructure-machine-1" ).Build ()
1792
1780
bootstrapTemplate := builder .BootstrapTemplate (metav1 .NamespaceDefault , "bootstrap-config-1" ).Build ()
@@ -1802,10 +1790,31 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1802
1790
current : nil ,
1803
1791
desired : []* scope.MachineDeploymentState {
1804
1792
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1805
- mhcBuilder .Build ()),
1793
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1794
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1795
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1796
+ {
1797
+ Type : corev1 .NodeReady ,
1798
+ Status : corev1 .ConditionUnknown ,
1799
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1800
+ },
1801
+ }).
1802
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1803
+ WithClusterName ("cluster1" ).
1804
+ Build ()),
1806
1805
},
1807
1806
want : []* clusterv1.MachineHealthCheck {
1808
- mhcBuilder .
1807
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1808
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1809
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1810
+ {
1811
+ Type : corev1 .NodeReady ,
1812
+ Status : corev1 .ConditionUnknown ,
1813
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1814
+ },
1815
+ }).
1816
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1817
+ WithClusterName ("cluster1" ).
1809
1818
WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1810
1819
Build ()},
1811
1820
},
@@ -1817,20 +1826,64 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1817
1826
// MHC is added in the desired state of the MachineDeployment
1818
1827
desired : []* scope.MachineDeploymentState {
1819
1828
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1820
- mhcBuilder .Build ()),
1829
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1830
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1831
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1832
+ {
1833
+ Type : corev1 .NodeReady ,
1834
+ Status : corev1 .ConditionUnknown ,
1835
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1836
+ },
1837
+ }).
1838
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1839
+ WithClusterName ("cluster1" ).
1840
+ Build ()),
1821
1841
},
1822
1842
want : []* clusterv1.MachineHealthCheck {
1823
- mhcBuilder .
1843
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1844
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1845
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1846
+ {
1847
+ Type : corev1 .NodeReady ,
1848
+ Status : corev1 .ConditionUnknown ,
1849
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1850
+ },
1851
+ }).
1852
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1853
+ WithClusterName ("cluster1" ).
1824
1854
WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1825
1855
Build ()}},
1826
1856
{
1827
1857
name : "Update MachineHealthCheck spec adding a field if the spec adds a field" ,
1828
1858
current : []* scope.MachineDeploymentState {
1829
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1859
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1860
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1861
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1862
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1863
+ {
1864
+ Type : corev1 .NodeReady ,
1865
+ Status : corev1 .ConditionUnknown ,
1866
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1867
+ },
1868
+ }).
1869
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1870
+ WithClusterName ("cluster1" ).
1871
+ Build ()),
1830
1872
},
1831
1873
desired : []* scope.MachineDeploymentState {
1832
1874
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1833
- mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1875
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1876
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1877
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1878
+ {
1879
+ Type : corev1 .NodeReady ,
1880
+ Status : corev1 .ConditionUnknown ,
1881
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1882
+ },
1883
+ }).
1884
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1885
+ WithClusterName ("cluster1" ).WithMaxUnhealthy (& maxUnhealthy ).
1886
+ Build ())},
1834
1887
want : []* clusterv1.MachineHealthCheck {
1835
1888
builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1836
1889
WithSelector (* selectorForMachineDeploymentMHC (md )).
@@ -1850,7 +1903,18 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1850
1903
name : "Update MachineHealthCheck spec removing a field if the spec removes a field" ,
1851
1904
current : []* scope.MachineDeploymentState {
1852
1905
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1853
- mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1906
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1907
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1908
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1909
+ {
1910
+ Type : corev1 .NodeReady ,
1911
+ Status : corev1 .ConditionUnknown ,
1912
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1913
+ },
1914
+ }).
1915
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1916
+ WithClusterName ("cluster1" ).WithMaxUnhealthy (& maxUnhealthy ).
1917
+ Build ()),
1854
1918
},
1855
1919
desired : []* scope.MachineDeploymentState {
1856
1920
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
@@ -1884,15 +1948,39 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1884
1948
{
1885
1949
name : "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one" ,
1886
1950
current : []* scope.MachineDeploymentState {
1887
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1951
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1952
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1953
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1954
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1955
+ {
1956
+ Type : corev1 .NodeReady ,
1957
+ Status : corev1 .ConditionUnknown ,
1958
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1959
+ },
1960
+ }).
1961
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1962
+ WithClusterName ("cluster1" ).
1963
+ Build ()),
1888
1964
},
1889
1965
desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1890
1966
want : []* clusterv1.MachineHealthCheck {},
1891
1967
},
1892
1968
{
1893
1969
name : "Delete MachineHealthCheck spec if the MachineDeployment is deleted" ,
1894
1970
current : []* scope.MachineDeploymentState {
1895
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1971
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1972
+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1973
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1974
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1975
+ {
1976
+ Type : corev1 .NodeReady ,
1977
+ Status : corev1 .ConditionUnknown ,
1978
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1979
+ },
1980
+ }).
1981
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1982
+ WithClusterName ("cluster1" ).
1983
+ Build ()),
1896
1984
},
1897
1985
desired : []* scope.MachineDeploymentState {},
1898
1986
want : []* clusterv1.MachineHealthCheck {},
0 commit comments