@@ -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,141 +1817,43 @@ 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
1827
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 ()),
1828
+ mhcBuilder .Clone ().Build ()),
1872
1829
},
1873
1830
desired : []* scope.MachineDeploymentState {
1874
1831
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 ())},
1832
+ mhcBuilder .Clone ().WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1887
1833
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
- }).
1834
+ mhcBuilder .Clone ().
1897
1835
WithMaxUnhealthy (& maxUnhealthy ).
1898
- 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 ,
1921
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1922
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1923
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1924
- {
1925
- Type : corev1 .NodeReady ,
1926
- Status : corev1 .ConditionUnknown ,
1927
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1928
- },
1929
- }).
1930
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1931
- WithClusterName ("cluster1" ).
1932
- Build ()),
1846
+ mhcBuilder .Clone ().Build ()),
1933
1847
},
1934
1848
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 ()},
1849
+ mhcBuilder .Clone ().Build (),
1850
+ },
1947
1851
},
1948
1852
{
1949
1853
name : "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one" ,
1950
1854
current : []* scope.MachineDeploymentState {
1951
1855
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 ()),
1856
+ mhcBuilder .Clone ().Build ()),
1964
1857
},
1965
1858
desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1966
1859
want : []* clusterv1.MachineHealthCheck {},
@@ -1969,18 +1862,7 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1969
1862
name : "Delete MachineHealthCheck spec if the MachineDeployment is deleted" ,
1970
1863
current : []* scope.MachineDeploymentState {
1971
1864
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 ()),
1865
+ mhcBuilder .Clone ().Build ()),
1984
1866
},
1985
1867
desired : []* scope.MachineDeploymentState {},
1986
1868
want : []* clusterv1.MachineHealthCheck {},
@@ -2082,36 +1964,36 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2082
1964
{
2083
1965
name : "Create a MachineHealthCheck" ,
2084
1966
current : nil ,
2085
- desired : mhcBuilder .Build (),
2086
- want : mhcBuilder .Build (),
1967
+ desired : mhcBuilder .Clone (). Build (),
1968
+ want : mhcBuilder .Clone (). Build (),
2087
1969
},
2088
1970
{
2089
1971
name : "Successfully create a valid Ownerreference on the MachineHealthCheck" ,
2090
1972
current : nil ,
2091
1973
// update the unhealthy conditions in the MachineHealthCheck
2092
- desired : mhcBuilder .
1974
+ desired : mhcBuilder .Clone ().
2093
1975
// Desired object has an incomplete owner reference which has no UID.
2094
1976
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion ()}}).
2095
1977
Build (),
2096
1978
// Want a reconciled object with a full ownerReference including UID
2097
- want : mhcBuilder .
1979
+ want : mhcBuilder .Clone ().
2098
1980
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion (), UID : cp .GetUID ()}}).
2099
1981
Build (),
2100
1982
wantErr : false ,
2101
1983
},
2102
1984
2103
1985
{
2104
1986
name : "Update a MachineHealthCheck with changes" ,
2105
- current : mhcBuilder .Build (),
1987
+ current : mhcBuilder .Clone (). Build (),
2106
1988
// update the unhealthy conditions in the MachineHealthCheck
2107
- desired : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1989
+ desired : mhcBuilder .Clone (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2108
1990
{
2109
1991
Type : corev1 .NodeReady ,
2110
1992
Status : corev1 .ConditionUnknown ,
2111
1993
Timeout : metav1.Duration {Duration : 1000 * time .Minute },
2112
1994
},
2113
1995
}).Build (),
2114
- want : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1996
+ want : mhcBuilder .Clone (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2115
1997
{
2116
1998
Type : corev1 .NodeReady ,
2117
1999
Status : corev1 .ConditionUnknown ,
@@ -2121,14 +2003,14 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2121
2003
},
2122
2004
{
2123
2005
name : "Don't change a MachineHealthCheck with no difference between desired and current" ,
2124
- current : mhcBuilder .Build (),
2006
+ current : mhcBuilder .Clone (). Build (),
2125
2007
// update the unhealthy conditions in the MachineHealthCheck
2126
- desired : mhcBuilder .Build (),
2127
- want : mhcBuilder .Build (),
2008
+ desired : mhcBuilder .Clone (). Build (),
2009
+ want : mhcBuilder .Clone (). Build (),
2128
2010
},
2129
2011
{
2130
2012
name : "Delete a MachineHealthCheck" ,
2131
- current : mhcBuilder .Build (),
2013
+ current : mhcBuilder .Clone (). Build (),
2132
2014
// update the unhealthy conditions in the MachineHealthCheck
2133
2015
desired : nil ,
2134
2016
want : nil ,
0 commit comments