@@ -1775,7 +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
1778
mhcBuilder := builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1780
1779
WithSelector (* selectorForMachineDeploymentMHC (md )).
1781
1780
WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
@@ -1802,12 +1801,10 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1802
1801
current : nil ,
1803
1802
desired : []* scope.MachineDeploymentState {
1804
1803
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1805
- mhcBuilder .Build ()),
1804
+ mhcBuilder .DeepCopy (). Build ()),
1806
1805
},
1807
1806
want : []* clusterv1.MachineHealthCheck {
1808
- mhcBuilder .
1809
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1810
- Build ()},
1807
+ mhcBuilder .DeepCopy ().Build ()},
1811
1808
},
1812
1809
{
1813
1810
name : "Create a new MachineHealthCheck if the MachineDeployment is modified to include one" ,
@@ -1817,82 +1814,52 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
1817
1814
// MHC is added in the desired state of the MachineDeployment
1818
1815
desired : []* scope.MachineDeploymentState {
1819
1816
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1820
- mhcBuilder .Build ()),
1817
+ mhcBuilder .DeepCopy (). Build ()),
1821
1818
},
1822
1819
want : []* clusterv1.MachineHealthCheck {
1823
- mhcBuilder .
1824
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1825
- Build ()}},
1820
+ mhcBuilder .DeepCopy ().Build ()}},
1826
1821
{
1827
1822
name : "Update MachineHealthCheck spec adding a field if the spec adds a field" ,
1828
1823
current : []* scope.MachineDeploymentState {
1829
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1824
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1825
+ mhcBuilder .DeepCopy ().Build ()),
1830
1826
},
1831
1827
desired : []* scope.MachineDeploymentState {
1832
1828
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1833
- mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1829
+ mhcBuilder .DeepCopy (). WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1834
1830
want : []* clusterv1.MachineHealthCheck {
1835
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1836
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1837
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1838
- {
1839
- Type : corev1 .NodeReady ,
1840
- Status : corev1 .ConditionUnknown ,
1841
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1842
- },
1843
- }).
1831
+ mhcBuilder .DeepCopy ().
1844
1832
WithMaxUnhealthy (& maxUnhealthy ).
1845
- WithClusterName ("cluster1" ).
1846
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1847
1833
Build ()},
1848
1834
},
1849
1835
{
1850
1836
name : "Update MachineHealthCheck spec removing a field if the spec removes a field" ,
1851
1837
current : []* scope.MachineDeploymentState {
1852
1838
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1853
- mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1839
+ mhcBuilder .DeepCopy (). WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1854
1840
},
1855
1841
desired : []* scope.MachineDeploymentState {
1856
1842
newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1857
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1858
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1859
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1860
- {
1861
- Type : corev1 .NodeReady ,
1862
- Status : corev1 .ConditionUnknown ,
1863
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1864
- },
1865
- }).
1866
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1867
- WithClusterName ("cluster1" ).
1868
- Build ()),
1843
+ mhcBuilder .DeepCopy ().Build ()),
1869
1844
},
1870
1845
want : []* clusterv1.MachineHealthCheck {
1871
- builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1872
- WithSelector (* selectorForMachineDeploymentMHC (md )).
1873
- WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1874
- {
1875
- Type : corev1 .NodeReady ,
1876
- Status : corev1 .ConditionUnknown ,
1877
- Timeout : metav1.Duration {Duration : 5 * time .Minute },
1878
- },
1879
- }).
1880
- WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1881
- WithClusterName ("cluster1" ).
1882
- Build ()},
1846
+ mhcBuilder .DeepCopy ().Build (),
1847
+ },
1883
1848
},
1884
1849
{
1885
1850
name : "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one" ,
1886
1851
current : []* scope.MachineDeploymentState {
1887
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1852
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1853
+ mhcBuilder .DeepCopy ().Build ()),
1888
1854
},
1889
1855
desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1890
1856
want : []* clusterv1.MachineHealthCheck {},
1891
1857
},
1892
1858
{
1893
1859
name : "Delete MachineHealthCheck spec if the MachineDeployment is deleted" ,
1894
1860
current : []* scope.MachineDeploymentState {
1895
- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1861
+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1862
+ mhcBuilder .DeepCopy ().Build ()),
1896
1863
},
1897
1864
desired : []* scope.MachineDeploymentState {},
1898
1865
want : []* clusterv1.MachineHealthCheck {},
@@ -1994,36 +1961,36 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
1994
1961
{
1995
1962
name : "Create a MachineHealthCheck" ,
1996
1963
current : nil ,
1997
- desired : mhcBuilder .Build (),
1998
- want : mhcBuilder .Build (),
1964
+ desired : mhcBuilder .DeepCopy (). Build (),
1965
+ want : mhcBuilder .DeepCopy (). Build (),
1999
1966
},
2000
1967
{
2001
1968
name : "Successfully create a valid Ownerreference on the MachineHealthCheck" ,
2002
1969
current : nil ,
2003
1970
// update the unhealthy conditions in the MachineHealthCheck
2004
- desired : mhcBuilder .
1971
+ desired : mhcBuilder .DeepCopy ().
2005
1972
// Desired object has an incomplete owner reference which has no UID.
2006
1973
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion ()}}).
2007
1974
Build (),
2008
1975
// Want a reconciled object with a full ownerReference including UID
2009
- want : mhcBuilder .
1976
+ want : mhcBuilder .DeepCopy ().
2010
1977
WithOwnerReferences ([]metav1.OwnerReference {{Name : cp .GetName (), Kind : cp .GetKind (), APIVersion : cp .GetAPIVersion (), UID : cp .GetUID ()}}).
2011
1978
Build (),
2012
1979
wantErr : false ,
2013
1980
},
2014
1981
2015
1982
{
2016
1983
name : "Update a MachineHealthCheck with changes" ,
2017
- current : mhcBuilder .Build (),
1984
+ current : mhcBuilder .DeepCopy (). Build (),
2018
1985
// update the unhealthy conditions in the MachineHealthCheck
2019
- desired : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1986
+ desired : mhcBuilder .DeepCopy (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2020
1987
{
2021
1988
Type : corev1 .NodeReady ,
2022
1989
Status : corev1 .ConditionUnknown ,
2023
1990
Timeout : metav1.Duration {Duration : 1000 * time .Minute },
2024
1991
},
2025
1992
}).Build (),
2026
- want : mhcBuilder .WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1993
+ want : mhcBuilder .DeepCopy (). WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
2027
1994
{
2028
1995
Type : corev1 .NodeReady ,
2029
1996
Status : corev1 .ConditionUnknown ,
@@ -2033,14 +2000,14 @@ func TestReconciler_reconcileMachineHealthCheck(t *testing.T) {
2033
2000
},
2034
2001
{
2035
2002
name : "Don't change a MachineHealthCheck with no difference between desired and current" ,
2036
- current : mhcBuilder .Build (),
2003
+ current : mhcBuilder .DeepCopy (). Build (),
2037
2004
// update the unhealthy conditions in the MachineHealthCheck
2038
- desired : mhcBuilder .Build (),
2039
- want : mhcBuilder .Build (),
2005
+ desired : mhcBuilder .DeepCopy (). Build (),
2006
+ want : mhcBuilder .DeepCopy (). Build (),
2040
2007
},
2041
2008
{
2042
2009
name : "Delete a MachineHealthCheck" ,
2043
- current : mhcBuilder .Build (),
2010
+ current : mhcBuilder .DeepCopy (). Build (),
2044
2011
// update the unhealthy conditions in the MachineHealthCheck
2045
2012
desired : nil ,
2046
2013
want : nil ,
0 commit comments