@@ -1775,6 +1775,17 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1775
1775
Build ()
1776
1776
1777
1777
maxUnhealthy := intstr .Parse ("45%" )
1778
+ mhcBuilder := builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1779
+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1780
+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1781
+ {
1782
+ Type : corev1 .NodeReady ,
1783
+ Status : corev1 .ConditionUnknown ,
1784
+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1785
+ },
1786
+ }).
1787
+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1788
+ WithClusterName ("cluster1" )
1778
1789
1779
1790
infrastructureMachineTemplate := builder .InfrastructureMachineTemplate (metav1 .NamespaceDefault , "infrastructure-machine-1" ).Build ()
1780
1791
bootstrapTemplate := builder .BootstrapTemplate (metav1 .NamespaceDefault , "bootstrap-config-1" ).Build ()
@@ -1790,33 +1801,10 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1790
1801
current : nil ,
1791
1802
desired : []* scope.MachineDeploymentState {
1792
1803
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 ()),
1804
+ mhcBuilder .DeepCopy ().Build ()),
1805
1805
},
1806
1806
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" ).
1818
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1819
- Build ()},
1807
+ mhcBuilder .DeepCopy ().Build ()},
1820
1808
},
1821
1809
{
1822
1810
name : "Create a new MachineHealthCheck if the MachineDeployment is modified to include one" ,
@@ -1826,141 +1814,43 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1826
1814
// MHC is added in the desired state of the MachineDeployment
1827
1815
desired : []* scope.MachineDeploymentState {
1828
1816
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 ()),
1817
+ mhcBuilder .DeepCopy ().Build ()),
1841
1818
},
1842
1819
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 ()}},
1820
+ mhcBuilder .DeepCopy ().Build ()}},
1856
1821
{
1857
1822
name : "Update MachineHealthCheck spec adding a field if the spec adds a field" ,
1858
1823
current : []* scope.MachineDeploymentState {
1859
1824
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 ()),
1825
+ mhcBuilder .DeepCopy ().Build ()),
1872
1826
},
1873
1827
desired : []* scope.MachineDeploymentState {
1874
1828
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 ())},
1829
+ mhcBuilder .DeepCopy ().WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1887
1830
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
- }).
1831
+ mhcBuilder .DeepCopy ().
1897
1832
WithMaxUnhealthy (& maxUnhealthy ).
1898
- WithClusterName ("cluster1" ).
1899
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1900
1833
Build ()},
1901
1834
},
1902
1835
{
1903
1836
name : "Update MachineHealthCheck spec removing a field if the spec removes a field" ,
1904
1837
current : []* scope.MachineDeploymentState {
1905
1838
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 ()),
1839
+ mhcBuilder .DeepCopy ().WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1918
1840
},
1919
1841
desired : []* scope.MachineDeploymentState {
1920
1842
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 ()),
1843
+ mhcBuilder .DeepCopy ().Build ()),
1933
1844
},
1934
1845
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 ()},
1846
+ mhcBuilder .DeepCopy ().Build (),
1847
+ },
1947
1848
},
1948
1849
{
1949
1850
name : "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one" ,
1950
1851
current : []* scope.MachineDeploymentState {
1951
1852
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 ()),
1853
+ mhcBuilder .DeepCopy ().Build ()),
1964
1854
},
1965
1855
desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1966
1856
want : []* clusterv1.MachineHealthCheck {},
@@ -1969,18 +1859,7 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1969
1859
name : "Delete MachineHealthCheck spec if the MachineDeployment is deleted" ,
1970
1860
current : []* scope.MachineDeploymentState {
1971
1861
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 ()),
1862
+ mhcBuilder .DeepCopy ().Build ()),
1984
1863
},
1985
1864
desired : []* scope.MachineDeploymentState {},
1986
1865
want : []* clusterv1.MachineHealthCheck {},
@@ -2082,36 +1961,36 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2082
1961
{
2083
1962
name : "Create a MachineHealthCheck" ,
2084
1963
current : nil ,
2085
- desired : mhcBuilder .Build (),
2086
- want : mhcBuilder .Build (),
1964
+ desired : mhcBuilder .DeepCopy (). Build (),
1965
+ want : mhcBuilder .DeepCopy (). Build (),
2087
1966
},
2088
1967
{
2089
1968
name : "Successfully create a valid Ownerreference on the MachineHealthCheck" ,
2090
1969
current : nil ,
2091
1970
// update the unhealthy conditions in the MachineHealthCheck
2092
- desired : mhcBuilder .
1971
+ desired : mhcBuilder .DeepCopy ().
2093
1972
// Desired object has an incomplete owner reference which has no UID.
2094
1973
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion ()}}).
2095
1974
Build (),
2096
1975
// Want a reconciled object with a full ownerReference including UID
2097
- want : mhcBuilder .
1976
+ want : mhcBuilder .DeepCopy ().
2098
1977
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion (), UID : cp .GetUID ()}}).
2099
1978
Build (),
2100
1979
wantErr : false ,
2101
1980
},
2102
1981
2103
1982
{
2104
1983
name : "Update a MachineHealthCheck with changes" ,
2105
- current : mhcBuilder .Build (),
1984
+ current : mhcBuilder .DeepCopy (). Build (),
2106
1985
// update the unhealthy conditions in the MachineHealthCheck
2107
- desired : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1986
+ desired : mhcBuilder .DeepCopy (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2108
1987
{
2109
1988
Type : corev1 .NodeReady ,
2110
1989
Status : corev1 .ConditionUnknown ,
2111
1990
Timeout : metav1.Duration {Duration : 1000 * time .Minute },
2112
1991
},
2113
1992
}).Build (),
2114
- want : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1993
+ want : mhcBuilder .DeepCopy (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2115
1994
{
2116
1995
Type : corev1 .NodeReady ,
2117
1996
Status : corev1 .ConditionUnknown ,
@@ -2121,14 +2000,14 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2121
2000
},
2122
2001
{
2123
2002
name : "Don't change a MachineHealthCheck with no difference between desired and current" ,
2124
- current : mhcBuilder .Build (),
2003
+ current : mhcBuilder .DeepCopy (). Build (),
2125
2004
// update the unhealthy conditions in the MachineHealthCheck
2126
- desired : mhcBuilder .Build (),
2127
- want : mhcBuilder .Build (),
2005
+ desired : mhcBuilder .DeepCopy (). Build (),
2006
+ want : mhcBuilder .DeepCopy (). Build (),
2128
2007
},
2129
2008
{
2130
2009
name : "Delete a MachineHealthCheck" ,
2131
- current : mhcBuilder .Build (),
2010
+ current : mhcBuilder .DeepCopy (). Build (),
2132
2011
// update the unhealthy conditions in the MachineHealthCheck
2133
2012
desired : nil ,
2134
2013
want : nil ,
0 commit comments