Skip to content

Commit dfdbd6c

Browse files
committed
fix review findings
1 parent f5c8a1e commit dfdbd6c

File tree

2 files changed

+33
-65
lines changed

2 files changed

+33
-65
lines changed

test/e2e/clusterclass_changes.go

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,11 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC
244244
// Get the ControlPlane.
245245
controlPlaneRef := input.Cluster.Spec.ControlPlaneRef
246246
controlPlaneTopology := input.Cluster.Spec.Topology.ControlPlane
247-
controlPlaneClass := input.ClusterClass.Spec.ControlPlane
248247
controlPlane, err := external.Get(ctx, mgmtClient, controlPlaneRef, input.ClusterClass.Namespace)
249248
g.Expect(err).ToNot(HaveOccurred())
250249

251250
// Verify that the fields from Cluster topology are set on the control plane.
252-
assertControlPlaneFields(g, controlPlane, newControlPlaneTemplate, controlPlaneTopology, controlPlaneClass)
251+
assertControlPlaneTopologyFields(g, controlPlane, controlPlaneTopology)
253252

254253
// Verify that ModifyControlPlaneFields have been set.
255254
for fieldPath, expectedValue := range input.ModifyControlPlaneFields {
@@ -262,10 +261,10 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC
262261
}, input.WaitForControlPlane...).Should(BeNil())
263262
}
264263

265-
func assertControlPlaneFields(g Gomega, controlPlane, controlPlaneTemplate *unstructured.Unstructured, controlPlaneTopology clusterv1.ControlPlaneTopology, controlPlaneClass clusterv1.ControlPlaneClass) {
266-
// Note: We only verify that all labels and annotations from the Cluster topology exist to keep it simple here.
267-
// There could be additional labels and annotations from the ClusterClass or the ControlPlane template.
268-
// This is fully covered by the ClusterClass rollout test.
264+
// assertControlPlaneTopologyFields asserts that all fields set in the ControlPlaneTopology have been set on the ControlPlane.
265+
// Note: We intentionally focus on the fields set in the ControlPlaneTopology and ignore the ones set through ClusterClass or
266+
// ControlPlane template as we want to validate that the fields of the ControlPlaneTopology have been propagated correctly.
267+
func assertControlPlaneTopologyFields(g Gomega, controlPlane *unstructured.Unstructured, controlPlaneTopology clusterv1.ControlPlaneTopology) {
269268
metadata, err := contract.ControlPlane().MachineTemplate().Metadata().Get(controlPlane)
270269
g.Expect(err).ToNot(HaveOccurred())
271270
for k, v := range controlPlaneTopology.Metadata.Labels {
@@ -275,41 +274,23 @@ func assertControlPlaneFields(g Gomega, controlPlane, controlPlaneTemplate *unst
275274
g.Expect(metadata.Annotations).To(HaveKeyWithValue(k, v))
276275
}
277276

278-
nodeDrainTimeout, err := contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Get(controlPlane)
279-
g.Expect(err).ToNot(HaveOccurred())
280-
expectedNodeDrainTimeout := controlPlaneTopology.NodeDrainTimeout
281-
if expectedNodeDrainTimeout == nil {
282-
expectedNodeDrainTimeout = controlPlaneClass.NodeDrainTimeout
283-
}
284-
if expectedNodeDrainTimeout == nil {
285-
expectedNodeDrainTimeout, err = contract.ControlPlaneTemplate().Template().MachineTemplate().NodeDrainTimeout().Get(controlPlaneTemplate)
277+
if controlPlaneTopology.NodeDrainTimeout != nil {
278+
nodeDrainTimeout, err := contract.ControlPlane().MachineTemplate().NodeDrainTimeout().Get(controlPlane)
286279
g.Expect(err).ToNot(HaveOccurred())
280+
g.Expect(nodeDrainTimeout).To(Equal(controlPlaneTopology.NodeDrainTimeout))
287281
}
288-
g.Expect(nodeDrainTimeout).To(Equal(expectedNodeDrainTimeout))
289282

290-
nodeDeletionTimeout, err := contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Get(controlPlane)
291-
g.Expect(err).ToNot(HaveOccurred())
292-
expectedNodeDeletionTimeout := controlPlaneTopology.NodeDeletionTimeout
293-
if expectedNodeDeletionTimeout == nil {
294-
expectedNodeDeletionTimeout = controlPlaneClass.NodeDeletionTimeout
295-
}
296-
if expectedNodeDeletionTimeout == nil {
297-
expectedNodeDeletionTimeout, err = contract.ControlPlaneTemplate().Template().MachineTemplate().NodeDeletionTimeout().Get(controlPlaneTemplate)
283+
if controlPlaneTopology.NodeDeletionTimeout != nil {
284+
nodeDeletionTimeout, err := contract.ControlPlane().MachineTemplate().NodeDeletionTimeout().Get(controlPlane)
298285
g.Expect(err).ToNot(HaveOccurred())
286+
g.Expect(nodeDeletionTimeout).To(Equal(controlPlaneTopology.NodeDeletionTimeout))
299287
}
300-
g.Expect(nodeDeletionTimeout).To(Equal(expectedNodeDeletionTimeout))
301288

302-
nodeVolumeDetachTimeout, err := contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Get(controlPlane)
303-
g.Expect(err).ToNot(HaveOccurred())
304-
expectedNodeVolumeDetachTimeout := controlPlaneTopology.NodeVolumeDetachTimeout
305-
if expectedNodeVolumeDetachTimeout == nil {
306-
expectedNodeVolumeDetachTimeout = controlPlaneClass.NodeVolumeDetachTimeout
307-
}
308-
if expectedNodeVolumeDetachTimeout == nil {
309-
expectedNodeVolumeDetachTimeout, err = contract.ControlPlaneTemplate().Template().MachineTemplate().NodeVolumeDetachTimeout().Get(controlPlaneTemplate)
289+
if controlPlaneTopology.NodeVolumeDetachTimeout != nil {
290+
nodeVolumeDetachTimeout, err := contract.ControlPlane().MachineTemplate().NodeVolumeDetachTimeout().Get(controlPlane)
310291
g.Expect(err).ToNot(HaveOccurred())
292+
g.Expect(nodeVolumeDetachTimeout).To(Equal(controlPlaneTopology.NodeVolumeDetachTimeout))
311293
}
312-
g.Expect(nodeVolumeDetachTimeout).To(Equal(expectedNodeVolumeDetachTimeout))
313294
}
314295

315296
// modifyMachineDeploymentViaClusterClassAndWaitInput is the input type for modifyMachineDeploymentViaClusterClassAndWait.
@@ -400,7 +381,7 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
400381
md := mdList.Items[0]
401382

402383
// Verify that the fields from Cluster topology are set on the MachineDeployment.
403-
assertMachineDeploymentFields(g, md, mdTopology, mdClass)
384+
assertMachineDeploymentTopologyFields(g, md, mdTopology)
404385

405386
if mdClass.Template.Bootstrap.Ref != nil {
406387
// Get the corresponding BootstrapConfigTemplate.
@@ -435,7 +416,10 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
435416
}
436417
}
437418

438-
func assertMachineDeploymentFields(g Gomega, md clusterv1.MachineDeployment, mdTopology clusterv1.MachineDeploymentTopology, mdClass clusterv1.MachineDeploymentClass) {
419+
// assertMachineDeploymentTopologyFields asserts that all fields set in the MachineDeploymentTopology have been set on the MachineDeployment.
420+
// Note: We intentionally focus on the fields set in the MachineDeploymentTopology and ignore the ones set through ClusterClass
421+
// as we want to validate that the fields of the MachineDeploymentTopology have been propagated correctly.
422+
func assertMachineDeploymentTopologyFields(g Gomega, md clusterv1.MachineDeployment, mdTopology clusterv1.MachineDeploymentTopology) {
439423
// Note: We only verify that all labels and annotations from the Cluster topology exist to keep it simple here.
440424
// This is fully covered by the ClusterClass rollout test.
441425
for k, v := range mdTopology.Metadata.Labels {
@@ -445,41 +429,29 @@ func assertMachineDeploymentFields(g Gomega, md clusterv1.MachineDeployment, mdT
445429
g.Expect(md.Annotations).To(HaveKeyWithValue(k, v))
446430
}
447431

448-
expectedNodeDrainTimeout := mdTopology.NodeDrainTimeout
449-
if expectedNodeDrainTimeout == nil {
450-
expectedNodeDrainTimeout = mdClass.NodeDrainTimeout
432+
if mdTopology.NodeDrainTimeout != nil {
433+
g.Expect(md.Spec.Template.Spec.NodeDrainTimeout).To(Equal(mdTopology.NodeDrainTimeout))
451434
}
452-
g.Expect(md.Spec.Template.Spec.NodeDrainTimeout).To(Equal(expectedNodeDrainTimeout))
453435

454-
expectedNodeDeletionTimeout := mdTopology.NodeDeletionTimeout
455-
if expectedNodeDeletionTimeout == nil {
456-
expectedNodeDeletionTimeout = mdClass.NodeDeletionTimeout
436+
if mdTopology.NodeDeletionTimeout != nil {
437+
g.Expect(md.Spec.Template.Spec.NodeDeletionTimeout).To(Equal(mdTopology.NodeDeletionTimeout))
457438
}
458-
g.Expect(md.Spec.Template.Spec.NodeDeletionTimeout).To(Equal(expectedNodeDeletionTimeout))
459439

460-
expectedNodeVolumeDetachTimeout := mdTopology.NodeVolumeDetachTimeout
461-
if expectedNodeVolumeDetachTimeout == nil {
462-
expectedNodeVolumeDetachTimeout = mdClass.NodeVolumeDetachTimeout
440+
if mdTopology.NodeVolumeDetachTimeout != nil {
441+
g.Expect(md.Spec.Template.Spec.NodeVolumeDetachTimeout).To(Equal(mdTopology.NodeVolumeDetachTimeout))
463442
}
464-
g.Expect(md.Spec.Template.Spec.NodeVolumeDetachTimeout).To(Equal(expectedNodeVolumeDetachTimeout))
465443

466-
expectedMinReadySeconds := mdTopology.MinReadySeconds
467-
if expectedMinReadySeconds == nil {
468-
expectedMinReadySeconds = mdClass.MinReadySeconds
444+
if mdTopology.MinReadySeconds != nil {
445+
g.Expect(md.Spec.MinReadySeconds).To(Equal(mdTopology.MinReadySeconds))
469446
}
470-
g.Expect(md.Spec.MinReadySeconds).To(Equal(expectedMinReadySeconds))
471447

472-
expectedStrategy := mdTopology.Strategy
473-
if expectedStrategy == nil {
474-
expectedStrategy = mdClass.Strategy
448+
if mdTopology.Strategy != nil {
449+
g.Expect(md.Spec.Strategy).To(Equal(mdTopology.Strategy))
475450
}
476-
g.Expect(md.Spec.Strategy).To(Equal(expectedStrategy))
477451

478-
expectedFailureDomain := mdTopology.FailureDomain
479-
if expectedFailureDomain == nil {
480-
expectedFailureDomain = mdClass.FailureDomain
452+
if mdTopology.FailureDomain != nil {
453+
g.Expect(md.Spec.Template.Spec.FailureDomain).To(Equal(mdTopology.FailureDomain))
481454
}
482-
g.Expect(md.Spec.Template.Spec.FailureDomain).To(Equal(expectedFailureDomain))
483455
}
484456

485457
// rebaseClusterClassAndWaitInput is the input type for rebaseClusterClassAndWait.

test/e2e/clusterclass_rollout.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,7 @@ func modifyControlPlaneViaClusterAndWait(ctx context.Context, input modifyContro
10161016
g.Expect(err).ToNot(HaveOccurred())
10171017

10181018
// Verify that the fields from Cluster topology are set on the control plane.
1019-
// Note: We don't have to pass in the ControlPlaneTemplate and the ControlPlaneClass as the
1020-
// timeouts are all set in the Cluster topology, so these objects are not used.
1021-
assertControlPlaneFields(g, controlPlane, nil, controlPlaneTopology, clusterv1.ControlPlaneClass{})
1019+
assertControlPlaneTopologyFields(g, controlPlane, controlPlaneTopology)
10221020
}, input.WaitForControlPlane...).Should(Succeed())
10231021
}
10241022

@@ -1062,9 +1060,7 @@ func modifyMachineDeploymentViaClusterAndWait(ctx context.Context, input modifyM
10621060
md := mdList.Items[0]
10631061

10641062
// Verify that the fields from Cluster topology are set on the MachineDeployment.
1065-
// Note: We don't have to pass in the MachineDeploymentClass as the fields are
1066-
// all set in the Cluster topology, so the MachineDeploymentClass is not used.
1067-
assertMachineDeploymentFields(g, md, mdTopology, clusterv1.MachineDeploymentClass{})
1063+
assertMachineDeploymentTopologyFields(g, md, mdTopology)
10681064
}, input.WaitForMachineDeployments...).Should(BeNil())
10691065
}
10701066
}

0 commit comments

Comments
 (0)