@@ -1774,6 +1774,7 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
17741774 Build ()
17751775
17761776 maxUnhealthy := intstr .Parse ("45%" )
1777+ // TODO: (killianmuldoon) This builder should be copied and not just passed around.
17771778 mhcBuilder := builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
17781779 WithSelector (* selectorForMachineDeploymentMHC (md )).
17791780 WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
@@ -1799,34 +1800,84 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
17991800 name : "Create a MachineHealthCheck if the MachineDeployment is being created" ,
18001801 current : nil ,
18011802 desired : []* scope.MachineDeploymentState {
1802- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1803+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1804+ mhcBuilder .Build ()),
18031805 },
18041806 want : []* clusterv1.MachineHealthCheck {
18051807 mhcBuilder .
18061808 WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
18071809 Build ()},
18081810 },
18091811 {
1810- name : "Create a new MachineHealthCheck if the MachineDeployment is modified to include one" ,
1811- current : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , nil )},
1812+ name : "Create a new MachineHealthCheck if the MachineDeployment is modified to include one" ,
1813+ current : []* scope.MachineDeploymentState {
1814+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1815+ nil )},
18121816 // MHC is added in the desired state of the MachineDeployment
18131817 desired : []* scope.MachineDeploymentState {
1814- newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
1818+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1819+ mhcBuilder .Build ()),
18151820 },
18161821 want : []* clusterv1.MachineHealthCheck {
18171822 mhcBuilder .
18181823 WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
18191824 Build ()}},
18201825 {
1821- name : "Update MachineHealthCheck spec if the spec changes " ,
1826+ name : "Update MachineHealthCheck spec adding a field if the spec adds a field " ,
18221827 current : []* scope.MachineDeploymentState {
18231828 newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .Build ()),
18241829 },
1825- desired : []* scope.MachineDeploymentState {newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate , mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ())},
1830+ desired : []* scope.MachineDeploymentState {
1831+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1832+ mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ())},
18261833 want : []* clusterv1.MachineHealthCheck {
1827- mhcBuilder .
1834+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1835+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1836+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1837+ {
1838+ Type : corev1 .NodeReady ,
1839+ Status : corev1 .ConditionUnknown ,
1840+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1841+ },
1842+ }).
18281843 WithMaxUnhealthy (& maxUnhealthy ).
1844+ WithClusterName ("cluster1" ).
1845+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1846+ Build ()},
1847+ },
1848+ {
1849+ name : "Update MachineHealthCheck spec removing a field if the spec removes a field" ,
1850+ current : []* scope.MachineDeploymentState {
1851+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1852+ mhcBuilder .WithMaxUnhealthy (& maxUnhealthy ).Build ()),
1853+ },
1854+ desired : []* scope.MachineDeploymentState {
1855+ newFakeMachineDeploymentTopologyState ("md-1" , infrastructureMachineTemplate , bootstrapTemplate ,
1856+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1857+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1858+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1859+ {
1860+ Type : corev1 .NodeReady ,
1861+ Status : corev1 .ConditionUnknown ,
1862+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1863+ },
1864+ }).
1865+ WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1866+ WithClusterName ("cluster1" ).
1867+ Build ()),
1868+ },
1869+ want : []* clusterv1.MachineHealthCheck {
1870+ builder .MachineHealthCheck (metav1 .NamespaceDefault , "md-1" ).
1871+ WithSelector (* selectorForMachineDeploymentMHC (md )).
1872+ WithUnhealthyConditions ([]clusterv1.UnhealthyCondition {
1873+ {
1874+ Type : corev1 .NodeReady ,
1875+ Status : corev1 .ConditionUnknown ,
1876+ Timeout : metav1.Duration {Duration : 5 * time .Minute },
1877+ },
1878+ }).
18291879 WithOwnerReferences ([]metav1.OwnerReference {* ownerReferenceTo (md )}).
1880+ WithClusterName ("cluster1" ).
18301881 Build ()},
18311882 },
18321883 {
0 commit comments