@@ -1775,6 +1775,18 @@ 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" )
1778
1790
1779
1791
infrastructureMachineTemplate := builder .InfrastructureMachineTemplate (metav1 .NamespaceDefault , "infrastructure-machine-1" ).Build ()
1780
1792
bootstrapTemplate := builder .BootstrapTemplate (metav1 .NamespaceDefault , "bootstrap-config-1" ).Build ()
@@ -1790,31 +1802,10 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1790
1802
current : nil ,
1791
1803
desired : []* scope.MachineDeploymentState {
1792
1804
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
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 ()),
1805
+ mhcBuilder .Clone ().Build ()),
1805
1806
},
1806
1807
want : []* clusterv1.MachineHealthCheck {
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" ).
1808
+ mhcBuilder .
1818
1809
WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1819
1810
Build ()},
1820
1811
},
@@ -1826,95 +1817,29 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1826
1817
// MHC is added in the desired state of the MachineDeployment
1827
1818
desired : []* scope.MachineDeploymentState {
1828
1819
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
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 ()),
1820
+ mhcBuilder .Clone ().Build ()),
1841
1821
},
1842
1822
want : []* clusterv1.MachineHealthCheck {
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" ).
1854
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1855
- Build ()}},
1823
+ mhcBuilder .Clone ().Build ()}},
1856
1824
{
1857
1825
name : "Update MachineHealthCheck spec adding a field if the spec adds a field" ,
1858
1826
current : []* scope.MachineDeploymentState {
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 ()),
1827
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Clone ().Build ()),
1872
1828
},
1873
1829
desired : []* scope.MachineDeploymentState {
1874
1830
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
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 ())},
1831
+ mhcBuilder .Clone ().WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1887
1832
want : []* clusterv1.MachineHealthCheck {
1888
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1889
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1890
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1891
- {
1892
- Type : corev1 .NodeReady ,
1893
- Status : corev1 .ConditionUnknown ,
1894
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1895
- },
1896
- }).
1833
+ mhcBuilder .Clone ().
1897
1834
WithMaxUnhealthy (& maxUnhealthy ).
1898
1835
WithClusterName ("cluster1" ).
1899
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1900
1836
Build ()},
1901
1837
},
1902
1838
{
1903
1839
name : "Update MachineHealthCheck spec removing a field if the spec removes a field" ,
1904
1840
current : []* scope.MachineDeploymentState {
1905
1841
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
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 ()),
1842
+ mhcBuilder .Clone ().WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1918
1843
},
1919
1844
desired : []* scope.MachineDeploymentState {
1920
1845
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
@@ -1932,55 +1857,21 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1932
1857
Build ()),
1933
1858
},
1934
1859
want : []* clusterv1.MachineHealthCheck {
1935
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1936
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1937
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1938
- {
1939
- Type : corev1 .NodeReady ,
1940
- Status : corev1 .ConditionUnknown ,
1941
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1942
- },
1943
- }).
1944
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1945
- WithClusterName ("cluster1" ).
1946
- Build ()},
1860
+ mhcBuilder .Clone ().Build (),
1861
+ },
1947
1862
},
1948
1863
{
1949
1864
name : "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one" ,
1950
1865
current : []* scope.MachineDeploymentState {
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 ()),
1866
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Clone ().Build ()),
1964
1867
},
1965
1868
desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1966
1869
want : []* clusterv1.MachineHealthCheck {},
1967
1870
},
1968
1871
{
1969
1872
name : "Delete MachineHealthCheck spec if the MachineDeployment is deleted" ,
1970
1873
current : []* scope.MachineDeploymentState {
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 ()),
1874
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Clone ().Build ()),
1984
1875
},
1985
1876
desired : []* scope.MachineDeploymentState {},
1986
1877
want : []* clusterv1.MachineHealthCheck {},
@@ -2082,36 +1973,36 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2082
1973
{
2083
1974
name : "Create a MachineHealthCheck" ,
2084
1975
current : nil ,
2085
- desired : mhcBuilder .Build (),
2086
- want : mhcBuilder .Build (),
1976
+ desired : mhcBuilder .Clone (). Build (),
1977
+ want : mhcBuilder .Clone (). Build (),
2087
1978
},
2088
1979
{
2089
1980
name : "Successfully create a valid Ownerreference on the MachineHealthCheck" ,
2090
1981
current : nil ,
2091
1982
// update the unhealthy conditions in the MachineHealthCheck
2092
- desired : mhcBuilder .
1983
+ desired : mhcBuilder .Clone ().
2093
1984
// Desired object has an incomplete owner reference which has no UID.
2094
1985
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion ()}}).
2095
1986
Build (),
2096
1987
// Want a reconciled object with a full ownerReference including UID
2097
- want : mhcBuilder .
1988
+ want : mhcBuilder .Clone ().
2098
1989
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion (), UID : cp .GetUID ()}}).
2099
1990
Build (),
2100
1991
wantErr : false ,
2101
1992
},
2102
1993
2103
1994
{
2104
1995
name : "Update a MachineHealthCheck with changes" ,
2105
- current : mhcBuilder .Build (),
1996
+ current : mhcBuilder .Clone (). Build (),
2106
1997
// update the unhealthy conditions in the MachineHealthCheck
2107
- desired : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1998
+ desired : mhcBuilder .Clone (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2108
1999
{
2109
2000
Type : corev1 .NodeReady ,
2110
2001
Status : corev1 .ConditionUnknown ,
2111
2002
Timeout : metav1.Duration {Duration : 1000 * time .Minute },
2112
2003
},
2113
2004
}).Build (),
2114
- want : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2005
+ want : mhcBuilder .Clone (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2115
2006
{
2116
2007
Type : corev1 .NodeReady ,
2117
2008
Status : corev1 .ConditionUnknown ,
@@ -2121,14 +2012,14 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2121
2012
},
2122
2013
{
2123
2014
name : "Don't change a MachineHealthCheck with no difference between desired and current" ,
2124
- current : mhcBuilder .Build (),
2015
+ current : mhcBuilder .Clone (). Build (),
2125
2016
// update the unhealthy conditions in the MachineHealthCheck
2126
- desired : mhcBuilder .Build (),
2127
- want : mhcBuilder .Build (),
2017
+ desired : mhcBuilder .Clone (). Build (),
2018
+ want : mhcBuilder .Clone (). Build (),
2128
2019
},
2129
2020
{
2130
2021
name : "Delete a MachineHealthCheck" ,
2131
- current : mhcBuilder .Build (),
2022
+ current : mhcBuilder .Clone (). Build (),
2132
2023
// update the unhealthy conditions in the MachineHealthCheck
2133
2024
desired : nil ,
2134
2025
want : nil ,
0 commit comments