Skip to content

Commit f94e09c

Browse files
committed
update
1 parent cab6507 commit f94e09c

File tree

1 file changed

+32
-65
lines changed

1 file changed

+32
-65
lines changed

test/e2e/clusterclass_rollout.go

Lines changed: 32 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import (
4949
)
5050

5151
// ClusterClassRolloutSpecInput is the input for ClusterClassRolloutSpec.
52+
// FIXME(sbueringer):doc: review the entire PR and add more godoc
53+
// FIXME(sbueringer): review the entire PR and check if we can move more to util funcs, split up more funcs
5254
type ClusterClassRolloutSpecInput struct {
5355
E2EConfig *clusterctl.E2EConfig
5456
ClusterctlConfigPath string
@@ -59,7 +61,7 @@ type ClusterClassRolloutSpecInput struct {
5961

6062
// Flavor is the cluster-template flavor used to create the Cluster for testing.
6163
// NOTE: The template must be using a ClusterClass.
62-
// FIXME(sbueringer): add more requirements
64+
// FIXME(sbueringer):doc: add more requirements
6365
Flavor string
6466

6567
// ModifyControlPlaneFields are the ControlPlane fields which will be set on the
@@ -69,7 +71,7 @@ type ClusterClassRolloutSpecInput struct {
6971
// map[string]interface{}{
7072
// "spec.path.to.field": <value>,
7173
// }
72-
// FIXME(sbueringer): should be a field which triggers a Machine rollout
74+
// FIXME(sbueringer):doc: should be a field which triggers a Machine rollout
7375
ModifyControlPlaneFields map[string]interface{}
7476

7577
// ModifyMachineDeploymentBootstrapConfigTemplateFields are the fields which will be set on the
@@ -92,7 +94,7 @@ type ClusterClassRolloutSpecInput struct {
9294
}
9395

9496
// ClusterClassRolloutSpec implements a test that verifies that ClusterClass changes are rolled out successfully.
95-
// FIXME(sbueringer)
97+
// FIXME(sbueringer):doc document this test is specifically for KCP + CABPK + MD/MS rollouts
9698
// Thus, the test consists of the following steps:
9799
// - Deploy Cluster using a ClusterClass and wait until it is fully provisioned.
98100
// - Modify the ControlPlaneTemplate of the ClusterClass by setting ModifyControlPlaneFields
@@ -162,8 +164,6 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
162164

163165
assertMetadataOnClusterObjects(ctx, input.BootstrapClusterProxy, clusterResources.Cluster, clusterResources.ClusterClass)
164166

165-
// FIXME: Verify all labels/annotations exactly on all objects (including nodes, inframachine, bootstrapconfig?) (fail on CAPI internal labels/annotations)
166-
167167
By("Rolling out changes to control plane and MachineDeployment (in-place)")
168168

169169
By("Modifying the control plane configuration in Cluster and wait for changes to be applied to the control plane object (in-place)")
@@ -184,10 +184,6 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
184184
},
185185
WaitForControlPlane: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),
186186
})
187-
188-
// FIXME: Verify all labels/annotations exactly on all objects (including nodes, inframachine, bootstrapconfig?) (fail on CAPI internal labels/annotations)
189-
// FIXME: Verify Machines are still the same
190-
191187
By("Modifying the MachineDeployment configuration in ClusterClass and wait for changes to be applied to the MachineDeployment objects (in-place")
192188
modifyMachineDeploymentViaClusterAndWait(ctx, modifyMachineDeploymentViaClusterAndWaitInput{
193189
ClusterProxy: input.BootstrapClusterProxy,
@@ -219,8 +215,9 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
219215
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
220216
})
221217

222-
// FIXME: Verify all labels/annotations exactly on all objects (including nodes, inframachine, bootstrapconfig?) (fail on CAPI internal labels/annotations)
223-
// * Wait for machines & they are still the same
218+
assertMetadataOnClusterObjects(ctx, input.BootstrapClusterProxy, clusterResources.Cluster, clusterResources.ClusterClass)
219+
220+
// FIXME: Verify machines are still the same (assert already waited for the in-place rollout)
224221

225222
By("Rolling out changes to control plane and MachineDeployment (rollout)")
226223

@@ -232,10 +229,6 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
232229
ModifyControlPlaneFields: input.ModifyControlPlaneFields,
233230
WaitForControlPlane: input.E2EConfig.GetIntervals(specName, "wait-control-plane"),
234231
})
235-
236-
// FIXME: Verify all labels/annotations exactly on all objects (including nodes, inframachine, bootstrapconfig?) (fail on CAPI internal labels/annotations)
237-
// * Wait for machines & they are new
238-
239232
By("Modifying the MachineDeployment configuration in ClusterClass and wait for changes to be applied to the MachineDeployment objects (rollout")
240233
modifyMachineDeploymentViaClusterClassAndWait(ctx, modifyMachineDeploymentViaClusterClassAndWaitInput{
241234
ClusterProxy: input.BootstrapClusterProxy,
@@ -246,9 +239,9 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
246239
WaitForMachineDeployments: input.E2EConfig.GetIntervals(specName, "wait-worker-nodes"),
247240
})
248241

249-
// FIXME: Verify all labels/annotations exactly on all objects (including nodes, inframachine, bootstrapconfig?) (fail on CAPI internal labels/annotations)
250-
// * Wait for machines & they are new
251-
// * Verify old MachineSet is not changed
242+
assertMetadataOnClusterObjects(ctx, input.BootstrapClusterProxy, clusterResources.Cluster, clusterResources.ClusterClass)
243+
244+
// FIXME: Verify machines are all rotated (assert already waited for the full rollout)
252245

253246
By("PASSED!")
254247
})
@@ -259,10 +252,11 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
259252
})
260253
}
261254

262-
// FIXME: ensure we wait until everything is reconciled enough before we call this func
263-
// FIXME: extract util stuff into util funcs, also the whole get all objects thing
264-
// FIXME: check assertions have the right semantics (i.e. they use the right labels/annotations => based on picture)
265-
// FIXME: double check ordering vs code
255+
// FIXME: Ensure this func gracefully retries if the rollout is not complete (e.g. node might not exist)
256+
// FIXME: Check assertions have the right semantics (i.e. they use the right labels/annotations => based on picture)
257+
// FIXME: Double check ordering of labels/annotations vs our code paths
258+
// FIXME: Split up func in smaller assertion funcs
259+
// FIXME: Maybe extract util stuff into util funcs
266260
func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.ClusterProxy, cluster *clusterv1.Cluster, clusterClass *clusterv1.ClusterClass) {
267261
By("Checking cluster objects have the right labels, annotations and selectors")
268262

@@ -323,15 +317,15 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
323317
},
324318
cluster.Spec.Topology.ControlPlane.Metadata.Labels,
325319
clusterClass.Spec.ControlPlane.Metadata.Labels,
326-
//machineTemplateMetadata(clusterClassObjects.ControlPlaneTemplate).Labels, // FIXME: shouldn't work atm (fix CC reconciler)
320+
//machineTemplateMetadata(clusterClassObjects.ControlPlaneTemplate).Labels, // FIXME: doesn't work atm (fix CC reconciler)
327321
),
328322
))
329323

330324
g.Expect(controlPlaneMachineTemplateMetadata.Annotations).To(BeEquivalentTo(
331325
union(
332326
cluster.Spec.Topology.ControlPlane.Metadata.Annotations,
333327
clusterClass.Spec.ControlPlane.Metadata.Annotations,
334-
//machineTemplateMetadata(clusterClassObjects.ControlPlaneTemplate).Annotations, // FIXME: shouldn't work atm (fix CC reconciler)
328+
//machineTemplateMetadata(clusterClassObjects.ControlPlaneTemplate).Annotations, // FIXME: doesn't work atm (fix CC reconciler)
335329
),
336330
))
337331

@@ -560,6 +554,7 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
560554

561555
// MachineDeployment MachineSet
562556
for _, machineSet := range clusterObjects.MachineSetsByMachineDeployment[machineDeployment.Name] {
557+
// FIXME: skip old MachineSet
563558
machineTemplateHash := machineSet.Labels[clusterv1.MachineDeploymentUniqueLabel]
564559

565560
g.Expect(machineSet.Labels).To(BeEquivalentTo(
@@ -676,7 +671,7 @@ func assertMetadataOnClusterObjects(ctx context.Context, clusterProxy framework.
676671
}
677672
}
678673

679-
fmt.Println("FIXME: breakpoint")
674+
By("All cluster objects have the right labels, annotations and selectors")
680675
}, 10*time.Minute, 1*time.Second).Should(Succeed()) // FIXME: timeouts, look at actual rollout times
681676
}
682677

@@ -713,7 +708,8 @@ func groupKind(ref *corev1.ObjectReference) string {
713708
return gk.String()
714709
}
715710

716-
// FIXME(sbueringer) move to contract (+ use must func)
711+
// FIXME(sbueringer) move to contract (+ use must func), also for other usages of contract + check if we can optimize contract call length
712+
// e.g. contract.ControlPlane().MachineTemplate() => controlPlaneMachineTemplate := contract.ControlPlane().MachineTemplate()
717713
func templateMetadata(obj *unstructured.Unstructured) *clusterv1.ObjectMeta {
718714
labelsValue, ok, err := unstructured.NestedStringMap(obj.UnstructuredContent(), "spec", "template", "metadata", "labels")
719715
Expect(err).ToNot(HaveOccurred())
@@ -733,26 +729,6 @@ func templateMetadata(obj *unstructured.Unstructured) *clusterv1.ObjectMeta {
733729
}
734730
}
735731

736-
// FIXME(sbueringer) move to contract (+ use must func)
737-
func machineTemplateMetadata(obj *unstructured.Unstructured) *clusterv1.ObjectMeta {
738-
labelsValue, ok, err := unstructured.NestedStringMap(obj.UnstructuredContent(), "spec", "template", "spec", "machineTemplate", "metadata", "labels")
739-
Expect(err).ToNot(HaveOccurred())
740-
if !ok {
741-
labelsValue = map[string]string{}
742-
}
743-
744-
annotationsValue, ok, err := unstructured.NestedStringMap(obj.UnstructuredContent(), "spec", "template", "spec", "machineTemplate", "metadata", "annotations")
745-
Expect(err).ToNot(HaveOccurred())
746-
if !ok {
747-
annotationsValue = map[string]string{}
748-
}
749-
750-
return &clusterv1.ObjectMeta{
751-
Labels: labelsValue,
752-
Annotations: annotationsValue,
753-
}
754-
}
755-
756732
type unionMap map[string]string
757733

758734
// union merges maps. keys from earlier maps are preserved over keys from later maps.
@@ -811,7 +787,6 @@ type clusterClassObjects struct {
811787
BootstrapConfigTemplateByMachineDeploymentClass map[string]*unstructured.Unstructured
812788
}
813789

814-
// FIXME: ensure bootstrap is optional everywhere
815790
func getClusterClassObjects(ctx context.Context, g Gomega, clusterProxy framework.ClusterProxy, clusterClass *clusterv1.ClusterClass) clusterClassObjects {
816791
mgmtClient := clusterProxy.GetClient()
817792

@@ -835,11 +810,9 @@ func getClusterClassObjects(ctx context.Context, g Gomega, clusterProxy framewor
835810
g.Expect(err).ToNot(HaveOccurred())
836811
res.InfrastructureMachineTemplateByMachineDeploymentClass[mdClass.Class] = infrastructureMachineTemplate
837812

838-
if mdClass.Template.Bootstrap.Ref != nil {
839-
bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Bootstrap.Ref, clusterClass.Namespace)
840-
g.Expect(err).ToNot(HaveOccurred())
841-
res.BootstrapConfigTemplateByMachineDeploymentClass[mdClass.Class] = bootstrapConfigTemplate
842-
}
813+
bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, mdClass.Template.Bootstrap.Ref, clusterClass.Namespace)
814+
g.Expect(err).ToNot(HaveOccurred())
815+
res.BootstrapConfigTemplateByMachineDeploymentClass[mdClass.Class] = bootstrapConfigTemplate
843816
}
844817

845818
return res
@@ -864,7 +837,7 @@ type clusterObjects struct {
864837
BootstrapConfigByMachine map[string]*unstructured.Unstructured
865838
}
866839

867-
// FIXME(sbueringer) add godoc (which should help with structure
840+
// FIXME(sbueringer):doc add godoc (which should help with structure)
868841
func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.ClusterProxy, cluster *clusterv1.Cluster) clusterObjects {
869842
mgmtClient := clusterProxy.GetClient()
870843
workloadClient := clusterProxy.GetWorkloadCluster(ctx, cluster.Namespace, cluster.Name).GetClient()
@@ -912,11 +885,9 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu
912885
md := mdList.Items[0]
913886
res.MachineDeployments = append(res.MachineDeployments, &md)
914887

915-
if md.Spec.Template.Spec.Bootstrap.ConfigRef != nil {
916-
bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, md.Spec.Template.Spec.Bootstrap.ConfigRef, cluster.Namespace)
917-
g.Expect(err).ToNot(HaveOccurred())
918-
res.BootstrapConfigTemplateByMachineDeployment[md.Name] = bootstrapConfigTemplate
919-
}
888+
bootstrapConfigTemplate, err := external.Get(ctx, mgmtClient, md.Spec.Template.Spec.Bootstrap.ConfigRef, cluster.Namespace)
889+
g.Expect(err).ToNot(HaveOccurred())
890+
res.BootstrapConfigTemplateByMachineDeployment[md.Name] = bootstrapConfigTemplate
920891

921892
infrastructureMachineTemplate, err := external.Get(ctx, mgmtClient, &md.Spec.Template.Spec.InfrastructureRef, cluster.Namespace)
922893
g.Expect(err).ToNot(HaveOccurred())
@@ -944,11 +915,9 @@ func getClusterObjects(ctx context.Context, g Gomega, clusterProxy framework.Clu
944915
}
945916

946917
func addMachineObjects(ctx context.Context, g Gomega, res clusterObjects, mgmtClient, workloadClient client.Client, cluster *clusterv1.Cluster, machine *clusterv1.Machine) {
947-
if machine.Spec.Bootstrap.ConfigRef != nil {
948-
bootstrapConfig, err := external.Get(ctx, mgmtClient, machine.Spec.Bootstrap.ConfigRef, cluster.Namespace)
949-
g.Expect(err).ToNot(HaveOccurred())
950-
res.BootstrapConfigByMachine[machine.Name] = bootstrapConfig
951-
}
918+
bootstrapConfig, err := external.Get(ctx, mgmtClient, machine.Spec.Bootstrap.ConfigRef, cluster.Namespace)
919+
g.Expect(err).ToNot(HaveOccurred())
920+
res.BootstrapConfigByMachine[machine.Name] = bootstrapConfig
952921

953922
infrastructureMachine, err := external.Get(ctx, mgmtClient, &machine.Spec.InfrastructureRef, cluster.Namespace)
954923
g.Expect(err).ToNot(HaveOccurred())
@@ -971,7 +940,6 @@ type modifyControlPlaneViaClusterAndWaitInput struct {
971940
// modifyControlPlaneViaClusterAndWait modifies the ControlPlaneTemplate of a ClusterClass by setting ModifyControlPlaneFields
972941
// and waits until the changes are rolled out to the ControlPlane of the Cluster.
973942
// NOTE: This helper is really specific to this test, so we are keeping this private vs. adding it to the framework.
974-
// FIXME(sbueringer)
975943
func modifyControlPlaneViaClusterAndWait(ctx context.Context, input modifyControlPlaneViaClusterAndWaitInput) {
976944
Expect(ctx).NotTo(BeNil(), "ctx is required for modifyControlPlaneViaClusterAndWait")
977945
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling modifyControlPlaneViaClusterAndWait")
@@ -1013,7 +981,6 @@ type modifyMachineDeploymentViaClusterAndWaitInput struct {
1013981
// modifyMachineDeploymentViaClusterAndWait modifies the BootstrapConfigTemplate of MachineDeploymentClasses of a ClusterClass
1014982
// by setting ModifyBootstrapConfigTemplateFields and waits until the changes are rolled out to the MachineDeployments of the Cluster.
1015983
// NOTE: This helper is really specific to this test, so we are keeping this private vs. adding it to the framework.
1016-
// FIXME(sbueringer)
1017984
func modifyMachineDeploymentViaClusterAndWait(ctx context.Context, input modifyMachineDeploymentViaClusterAndWaitInput) {
1018985
Expect(ctx).NotTo(BeNil(), "ctx is required for modifyMachineDeploymentViaClusterAndWait")
1019986
Expect(input.ClusterProxy).ToNot(BeNil(), "Invalid argument. input.ClusterProxy can't be nil when calling modifyMachineDeploymentViaClusterAndWait")

0 commit comments

Comments
 (0)