Skip to content

Commit f47ef28

Browse files
Make MHC ClusterClass authoritative on paths
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
1 parent 07e31b7 commit f47ef28

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

internal/controllers/topology/cluster/reconcile_state.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,9 @@ func (r *Reconciler) reconcileMachineHealthCheck(ctx context.Context, current, d
291291
ctx, log = log.WithObject(current).Into(ctx)
292292

293293
// Check differences between current and desired MachineHealthChecks, and patch if required.
294-
patchHelper, err := mergepatch.NewHelper(current, desired, r.Client)
294+
// NOTE: we want to be authoritative on the entire spec because the users are
295+
// expected to change MHC fields from the ClusterClass only.
296+
patchHelper, err := mergepatch.NewHelper(current, desired, r.Client, mergepatch.AuthoritativePaths{contract.Path{"spec"}})
295297
if err != nil {
296298
return errors.Wrapf(err, "failed to create patch helper for %s", tlog.KObj{Obj: current})
297299
}

internal/controllers/topology/cluster/reconcile_state_test.go

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)