Skip to content

Commit 474e312

Browse files
inline builders in test for MHC reconcilation
Signed-off-by: killianmuldoon <[email protected]>
1 parent 5dc0ab2 commit 474e312

File tree

1 file changed

+109
-21
lines changed

1 file changed

+109
-21
lines changed

internal/controllers/topology/cluster/reconcile_state_test.go

Lines changed: 109 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,18 +1775,6 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
17751775
Build()
17761776

17771777
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")
17901778

17911779
infrastructureMachineTemplate := builder.InfrastructureMachineTemplate(metav1.NamespaceDefault, "infrastructure-machine-1").Build()
17921780
bootstrapTemplate := builder.BootstrapTemplate(metav1.NamespaceDefault, "bootstrap-config-1").Build()
@@ -1802,10 +1790,31 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
18021790
current: nil,
18031791
desired: []*scope.MachineDeploymentState{
18041792
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate,
1805-
mhcBuilder.Build()),
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()),
18061805
},
18071806
want: []*clusterv1.MachineHealthCheck{
1808-
mhcBuilder.
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").
18091818
WithOwnerReferences([]metav1.OwnerReference{*ownerReferenceTo(md)}).
18101819
Build()},
18111820
},
@@ -1817,20 +1826,64 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
18171826
// MHC is added in the desired state of the MachineDeployment
18181827
desired: []*scope.MachineDeploymentState{
18191828
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate,
1820-
mhcBuilder.Build()),
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()),
18211841
},
18221842
want: []*clusterv1.MachineHealthCheck{
1823-
mhcBuilder.
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").
18241854
WithOwnerReferences([]metav1.OwnerReference{*ownerReferenceTo(md)}).
18251855
Build()}},
18261856
{
18271857
name: "Update MachineHealthCheck spec adding a field if the spec adds a field",
18281858
current: []*scope.MachineDeploymentState{
1829-
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, mhcBuilder.Build()),
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()),
18301872
},
18311873
desired: []*scope.MachineDeploymentState{
18321874
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate,
1833-
mhcBuilder.WithMaxUnhealthy(&maxUnhealthy).Build())},
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())},
18341887
want: []*clusterv1.MachineHealthCheck{
18351888
builder.MachineHealthCheck(metav1.NamespaceDefault, "md-1").
18361889
WithSelector(*selectorForMachineDeploymentMHC(md)).
@@ -1850,7 +1903,18 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
18501903
name: "Update MachineHealthCheck spec removing a field if the spec removes a field",
18511904
current: []*scope.MachineDeploymentState{
18521905
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate,
1853-
mhcBuilder.WithMaxUnhealthy(&maxUnhealthy).Build()),
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()),
18541918
},
18551919
desired: []*scope.MachineDeploymentState{
18561920
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate,
@@ -1884,15 +1948,39 @@ func TestReconcileMachineDeploymentMachineHealthCheck(t *testing.T) {
18841948
{
18851949
name: "Delete MachineHealthCheck spec if the MachineDeployment is modified to remove an existing one",
18861950
current: []*scope.MachineDeploymentState{
1887-
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, mhcBuilder.Build()),
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()),
18881964
},
18891965
desired: []*scope.MachineDeploymentState{newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, nil)},
18901966
want: []*clusterv1.MachineHealthCheck{},
18911967
},
18921968
{
18931969
name: "Delete MachineHealthCheck spec if the MachineDeployment is deleted",
18941970
current: []*scope.MachineDeploymentState{
1895-
newFakeMachineDeploymentTopologyState("md-1", infrastructureMachineTemplate, bootstrapTemplate, mhcBuilder.Build()),
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()),
18961984
},
18971985
desired: []*scope.MachineDeploymentState{},
18981986
want: []*clusterv1.MachineHealthCheck{},

0 commit comments

Comments
 (0)