Skip to content

Commit 039c6c1

Browse files
committed
Fix review findings
1 parent 030322a commit 039c6c1

File tree

1 file changed

+195
-7
lines changed

1 file changed

+195
-7
lines changed

internal/controllers/machineset/machineset_controller_test.go

+195-7
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,25 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
15101510
Type: clusterv1.MachineOwnerRemediatedCondition,
15111511
Status: corev1.ConditionFalse,
15121512
},
1513+
{
1514+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1515+
Status: corev1.ConditionFalse,
1516+
},
1517+
},
1518+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1519+
Conditions: []metav1.Condition{
1520+
{
1521+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1522+
Status: metav1.ConditionFalse,
1523+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1524+
},
1525+
{
1526+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1527+
Status: metav1.ConditionFalse,
1528+
Reason: clusterv1.MachineHealthCheckHasRemediateAnnotationV1Beta2Reason,
1529+
Message: "Marked for remediation via cluster.x-k8s.io/remediate-machine annotation",
1530+
},
1531+
},
15131532
},
15141533
},
15151534
}
@@ -1518,6 +1537,34 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
15181537
Name: "healthy-machine",
15191538
Namespace: "default",
15201539
},
1540+
Status: clusterv1.MachineStatus{
1541+
Conditions: []clusterv1.Condition{
1542+
{
1543+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1544+
Type: clusterv1.MachineOwnerRemediatedCondition,
1545+
Status: corev1.ConditionFalse,
1546+
},
1547+
{
1548+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1549+
Status: corev1.ConditionTrue,
1550+
},
1551+
},
1552+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1553+
Conditions: []metav1.Condition{
1554+
{
1555+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1556+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1557+
Status: metav1.ConditionFalse,
1558+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1559+
},
1560+
{
1561+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1562+
Status: metav1.ConditionTrue,
1563+
Reason: clusterv1.MachineHealthCheckSucceededV1Beta2Reason,
1564+
},
1565+
},
1566+
},
1567+
},
15211568
}
15221569

15231570
machines := []*clusterv1.Machine{unhealthyMachine, healthyMachine}
@@ -1590,6 +1637,25 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
15901637
Type: clusterv1.MachineOwnerRemediatedCondition,
15911638
Status: corev1.ConditionFalse,
15921639
},
1640+
{
1641+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1642+
Status: corev1.ConditionFalse,
1643+
},
1644+
},
1645+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1646+
Conditions: []metav1.Condition{
1647+
{
1648+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1649+
Status: metav1.ConditionFalse,
1650+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1651+
},
1652+
{
1653+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1654+
Status: metav1.ConditionFalse,
1655+
Reason: clusterv1.MachineHealthCheckHasRemediateAnnotationV1Beta2Reason,
1656+
Message: "Marked for remediation via cluster.x-k8s.io/remediate-machine annotation",
1657+
},
1658+
},
15931659
},
15941660
},
15951661
}
@@ -1598,6 +1664,34 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
15981664
Name: "healthy-machine",
15991665
Namespace: "default",
16001666
},
1667+
Status: clusterv1.MachineStatus{
1668+
Conditions: []clusterv1.Condition{
1669+
{
1670+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1671+
Type: clusterv1.MachineOwnerRemediatedCondition,
1672+
Status: corev1.ConditionFalse,
1673+
},
1674+
{
1675+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1676+
Status: corev1.ConditionTrue,
1677+
},
1678+
},
1679+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1680+
Conditions: []metav1.Condition{
1681+
{
1682+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1683+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1684+
Status: metav1.ConditionFalse,
1685+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1686+
},
1687+
{
1688+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1689+
Status: metav1.ConditionTrue,
1690+
Reason: clusterv1.MachineHealthCheckSucceededV1Beta2Reason,
1691+
},
1692+
},
1693+
},
1694+
},
16011695
}
16021696

16031697
machines := []*clusterv1.Machine{unhealthyMachine, healthyMachine}
@@ -1636,7 +1730,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
16361730
"The operation will continue after the preflight check(s) pass",
16371731
}, v1beta2conditions.IgnoreLastTransitionTime(true)))
16381732

1639-
// Verify the healthy machine continues to not have the MachineOwnerRemediated condition.
1733+
// Verify the healthy machine does not have the MachineOwnerRemediated condition.
16401734
m = &clusterv1.Machine{}
16411735
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
16421736
g.Expect(m.DeletionTimestamp.IsZero()).To(BeTrue())
@@ -1709,6 +1803,25 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17091803
Type: clusterv1.MachineOwnerRemediatedCondition,
17101804
Status: corev1.ConditionFalse,
17111805
},
1806+
{
1807+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1808+
Status: corev1.ConditionFalse,
1809+
},
1810+
},
1811+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1812+
Conditions: []metav1.Condition{
1813+
{
1814+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1815+
Status: metav1.ConditionFalse,
1816+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1817+
},
1818+
{
1819+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1820+
Status: metav1.ConditionFalse,
1821+
Reason: clusterv1.MachineHealthCheckHasRemediateAnnotationV1Beta2Reason,
1822+
Message: "Marked for remediation via cluster.x-k8s.io/remediate-machine annotation",
1823+
},
1824+
},
17121825
},
17131826
},
17141827
}
@@ -1717,6 +1830,34 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17171830
Name: "healthy-machine",
17181831
Namespace: "default",
17191832
},
1833+
Status: clusterv1.MachineStatus{
1834+
Conditions: []clusterv1.Condition{
1835+
{
1836+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1837+
Type: clusterv1.MachineOwnerRemediatedCondition,
1838+
Status: corev1.ConditionFalse,
1839+
},
1840+
{
1841+
Type: clusterv1.MachineHealthCheckSucceededCondition,
1842+
Status: corev1.ConditionTrue,
1843+
},
1844+
},
1845+
V1Beta2: &clusterv1.MachineV1Beta2Status{
1846+
Conditions: []metav1.Condition{
1847+
{
1848+
// This condition should be cleaned up because HealthCheckSucceeded is true.
1849+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
1850+
Status: metav1.ConditionFalse,
1851+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
1852+
},
1853+
{
1854+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
1855+
Status: metav1.ConditionTrue,
1856+
Reason: clusterv1.MachineHealthCheckSucceededV1Beta2Reason,
1857+
},
1858+
},
1859+
},
1860+
},
17201861
}
17211862

17221863
machines := []*clusterv1.Machine{unhealthyMachine, healthyMachine}
@@ -1764,7 +1905,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17641905
Message: "Machine won't be remediated because it is pending removal due to rollout",
17651906
}, v1beta2conditions.IgnoreLastTransitionTime(true)))
17661907

1767-
// Verify the healthy machine continues to not have the MachineOwnerRemediated condition.
1908+
// Verify the healthy machine does not have the MachineOwnerRemediated condition.
17681909
m = &clusterv1.Machine{}
17691910
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
17701911
g.Expect(m.DeletionTimestamp.IsZero()).To(BeTrue())
@@ -1795,7 +1936,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
17951936
Reason: clusterv1.MachineSetMachineRemediationMachineDeletedV1Beta2Reason,
17961937
}, v1beta2conditions.IgnoreLastTransitionTime(true)))
17971938

1798-
// Verify (again) the healthy machine continues to not have the MachineOwnerRemediated condition.
1939+
// Verify (again) the healthy machine does not have the MachineOwnerRemediated condition.
17991940
m = &clusterv1.Machine{}
18001941
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
18011942
g.Expect(m.DeletionTimestamp.IsZero()).To(BeTrue())
@@ -1872,6 +2013,25 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
18722013
Type: clusterv1.MachineOwnerRemediatedCondition,
18732014
Status: corev1.ConditionFalse,
18742015
},
2016+
{
2017+
Type: clusterv1.MachineHealthCheckSucceededCondition,
2018+
Status: corev1.ConditionFalse,
2019+
},
2020+
},
2021+
V1Beta2: &clusterv1.MachineV1Beta2Status{
2022+
Conditions: []metav1.Condition{
2023+
{
2024+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
2025+
Status: metav1.ConditionFalse,
2026+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
2027+
},
2028+
{
2029+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
2030+
Status: metav1.ConditionFalse,
2031+
Reason: clusterv1.MachineHealthCheckHasRemediateAnnotationV1Beta2Reason,
2032+
Message: "Marked for remediation via cluster.x-k8s.io/remediate-machine annotation",
2033+
},
2034+
},
18752035
},
18762036
},
18772037
})
@@ -1882,6 +2042,34 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
18822042
Name: "healthy-machine",
18832043
Namespace: "default",
18842044
},
2045+
Status: clusterv1.MachineStatus{
2046+
Conditions: []clusterv1.Condition{
2047+
{
2048+
// This condition should be cleaned up because HealthCheckSucceeded is true.
2049+
Type: clusterv1.MachineOwnerRemediatedCondition,
2050+
Status: corev1.ConditionFalse,
2051+
},
2052+
{
2053+
Type: clusterv1.MachineHealthCheckSucceededCondition,
2054+
Status: corev1.ConditionTrue,
2055+
},
2056+
},
2057+
V1Beta2: &clusterv1.MachineV1Beta2Status{
2058+
Conditions: []metav1.Condition{
2059+
{
2060+
// This condition should be cleaned up because HealthCheckSucceeded is true.
2061+
Type: clusterv1.MachineOwnerRemediatedV1Beta2Condition,
2062+
Status: metav1.ConditionFalse,
2063+
Reason: clusterv1.MachineOwnerRemediatedWaitingForRemediationV1Beta2Reason,
2064+
},
2065+
{
2066+
Type: clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
2067+
Status: metav1.ConditionTrue,
2068+
Reason: clusterv1.MachineHealthCheckSucceededV1Beta2Reason,
2069+
},
2070+
},
2071+
},
2072+
},
18852073
}
18862074

18872075
fakeClient := fake.NewClientBuilder().WithObjects(cluster, machineDeployment, healthyMachine).
@@ -1936,7 +2124,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
19362124
}
19372125
}
19382126

1939-
// Verify the healthy machine continues to not have the MachineOwnerRemediated condition.
2127+
// Verify the healthy machine does not have the MachineOwnerRemediated condition.
19402128
m := &clusterv1.Machine{}
19412129
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
19422130
g.Expect(conditions.Has(m, condition)).
@@ -2026,7 +2214,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
20262214
}
20272215
validateSecondPass(false)
20282216

2029-
// Verify (again) the healthy machine continues to not have the MachineOwnerRemediated condition.
2217+
// Verify (again) the healthy machine does not have the MachineOwnerRemediated condition.
20302218
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
20312219
g.Expect(conditions.Has(m, condition)).
20322220
To(BeFalse(), "Machine should not have the %s condition set", condition)
@@ -2048,7 +2236,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
20482236
// Validate and remove finalizers for in flight machines.
20492237
validateSecondPass(true)
20502238

2051-
// Verify (again) the healthy machine continues to not have the MachineOwnerRemediated condition.
2239+
// Verify (again) the healthy machine does not have the MachineOwnerRemediated condition.
20522240
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
20532241
g.Expect(conditions.Has(m, condition)).
20542242
To(BeFalse(), "Machine should not have the %s condition set", condition)
@@ -2073,7 +2261,7 @@ func TestMachineSetReconciler_reconcileUnhealthyMachines(t *testing.T) {
20732261
g.Expect(apierrors.IsNotFound(err)).To(BeTrue(), "expected machine %d to be deleted: %v", i)
20742262
}
20752263

2076-
// Verify (again) the healthy machine continues to not have the MachineOwnerRemediated condition.
2264+
// Verify (again) the healthy machine does not have the MachineOwnerRemediated condition.
20772265
g.Expect(r.Client.Get(ctx, client.ObjectKeyFromObject(healthyMachine), m)).To(Succeed())
20782266
g.Expect(conditions.Has(m, condition)).
20792267
To(BeFalse(), "Machine should not have the %s condition set", condition)

0 commit comments

Comments
 (0)