@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"os"
23
23
"path/filepath"
24
+ "reflect"
24
25
"strings"
25
26
26
27
. "github.com/onsi/ginkgo/v2"
@@ -71,6 +72,15 @@ type ClusterClassChangesSpecInput struct {
71
72
// "spec.template.spec.path.to.field": <value>,
72
73
// }
73
74
ModifyMachineDeploymentBootstrapConfigTemplateFields map [string ]interface {}
75
+
76
+ // ModifyMachineDeploymentInfrastructureMachineTemplateFields are the fields which will be set on the
77
+ // InfrastructureMachineTemplate of all MachineDeploymentClasses of the ClusterClass after the initial Cluster creation.
78
+ // The test verifies that these fields are rolled out to the MachineDeployments.
79
+ // NOTE: The fields are configured in the following format:
80
+ // map[string]interface{}{
81
+ // "spec.template.spec.path.to.field": <value>,
82
+ // }
83
+ ModifyMachineDeploymentInfrastructureMachineTemplateFields map [string ]interface {}
74
84
}
75
85
76
86
// ClusterClassChangesSpec implements a test that verifies that ClusterClass changes are rolled out successfully.
@@ -81,6 +91,9 @@ type ClusterClassChangesSpecInput struct {
81
91
// - Modify the BootstrapTemplate of all MachineDeploymentClasses of the ClusterClass by setting
82
92
// ModifyMachineDeploymentBootstrapConfigTemplateFields and wait until the change has been rolled out
83
93
// to the MachineDeployments of the Cluster.
94
+ // - Modify the InfrastructureMachineTemplate of all MachineDeploymentClasses of the ClusterClass by setting
95
+ // ModifyMachineDeploymentInfrastructureMachineTemplateFields and wait until the change has been rolled out
96
+ // to the MachineDeployments of the Cluster.
84
97
// - Rebase the Cluster to a copy of the ClusterClass which has an additional worker label set. Then wait
85
98
// until the change has been rolled out to the MachineDeployments of the Cluster and verify the ControlPlane
86
99
// has not been changed.
@@ -110,7 +123,6 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas
110
123
Expect (input .E2EConfig .Variables ).To (HaveKey (KubernetesVersion ))
111
124
Expect (input .E2EConfig .Variables ).To (HaveValidVersion (input .E2EConfig .GetVariable (KubernetesVersion )))
112
125
Expect (input .ModifyControlPlaneFields ).ToNot (BeEmpty (), "Invalid argument. input.ModifyControlPlaneFields can't be empty when calling %s spec" , specName )
113
- Expect (input .ModifyMachineDeploymentBootstrapConfigTemplateFields ).ToNot (BeEmpty (), "Invalid argument. input.ModifyMachineDeploymentBootstrapConfigTemplateFields can't be empty when calling %s spec" , specName )
114
126
115
127
// Set up a Namespace where to host objects for this spec and create a watcher for the namespace events.
116
128
namespace , cancelWatches = setupSpecNamespace (ctx , specName , input .BootstrapClusterProxy , input .ArtifactFolder )
@@ -154,7 +166,8 @@ func ClusterClassChangesSpec(ctx context.Context, inputGetter func() ClusterClas
154
166
ClusterClass : clusterResources .ClusterClass ,
155
167
Cluster : clusterResources .Cluster ,
156
168
ModifyBootstrapConfigTemplateFields : input .ModifyMachineDeploymentBootstrapConfigTemplateFields ,
157
- WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
169
+ ModifyInfrastructureMachineTemplateFields : input .ModifyMachineDeploymentInfrastructureMachineTemplateFields ,
170
+ WaitForMachineDeployments : input .E2EConfig .GetIntervals (specName , "wait-worker-nodes" ),
158
171
})
159
172
160
173
By ("Rebasing the Cluster to a ClusterClass with a modified label for MachineDeployments and wait for changes to be applied to the MachineDeployment objects" )
@@ -243,11 +256,12 @@ func modifyControlPlaneViaClusterClassAndWait(ctx context.Context, input modifyC
243
256
244
257
// modifyMachineDeploymentViaClusterClassAndWaitInput is the input type for modifyMachineDeploymentViaClusterClassAndWait.
245
258
type modifyMachineDeploymentViaClusterClassAndWaitInput struct {
246
- ClusterProxy framework.ClusterProxy
247
- ClusterClass * clusterv1.ClusterClass
248
- Cluster * clusterv1.Cluster
249
- ModifyBootstrapConfigTemplateFields map [string ]interface {}
250
- WaitForMachineDeployments []interface {}
259
+ ClusterProxy framework.ClusterProxy
260
+ ClusterClass * clusterv1.ClusterClass
261
+ Cluster * clusterv1.Cluster
262
+ ModifyBootstrapConfigTemplateFields map [string ]interface {}
263
+ ModifyInfrastructureMachineTemplateFields map [string ]interface {}
264
+ WaitForMachineDeployments []interface {}
251
265
}
252
266
253
267
// modifyMachineDeploymentViaClusterClassAndWait modifies the BootstrapConfigTemplate of MachineDeploymentClasses of a ClusterClass
@@ -273,7 +287,6 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
273
287
bootstrapConfigTemplateRef := mdClass .Template .Bootstrap .Ref
274
288
bootstrapConfigTemplate , err := external .Get (ctx , mgmtClient , bootstrapConfigTemplateRef , input .Cluster .Namespace )
275
289
Expect (err ).ToNot (HaveOccurred ())
276
-
277
290
// Create a new BootstrapConfigTemplate object with a new name and ModifyBootstrapConfigTemplateFields set.
278
291
newBootstrapConfigTemplate := bootstrapConfigTemplate .DeepCopy ()
279
292
newBootstrapConfigTemplateName := fmt .Sprintf ("%s-%s" , bootstrapConfigTemplateRef .Name , util .RandomString (6 ))
@@ -284,10 +297,25 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
284
297
}
285
298
Expect (mgmtClient .Create (ctx , newBootstrapConfigTemplate )).To (Succeed ())
286
299
300
+ // Retrieve InfrastructureMachineTemplate object.
301
+ infrastructureMachineTemplateRef := mdClass .Template .Infrastructure .Ref
302
+ infrastructureMachineTemplate , err := external .Get (ctx , mgmtClient , infrastructureMachineTemplateRef , input .Cluster .Namespace )
303
+ Expect (err ).ToNot (HaveOccurred ())
304
+ // Create a new InfrastructureMachineTemplate object with a new name and ModifyInfrastructureMachineTemplateFields set.
305
+ newInfrastructureMachineTemplate := infrastructureMachineTemplate .DeepCopy ()
306
+ newInfrastructureMachineTemplateName := fmt .Sprintf ("%s-%s" , infrastructureMachineTemplateRef .Name , util .RandomString (6 ))
307
+ newInfrastructureMachineTemplate .SetName (newInfrastructureMachineTemplateName )
308
+ newInfrastructureMachineTemplate .SetResourceVersion ("" )
309
+ for fieldPath , value := range input .ModifyInfrastructureMachineTemplateFields {
310
+ Expect (unstructured .SetNestedField (newInfrastructureMachineTemplate .Object , value , strings .Split (fieldPath , "." )... )).To (Succeed ())
311
+ }
312
+ Expect (mgmtClient .Create (ctx , newInfrastructureMachineTemplate )).To (Succeed ())
313
+
287
314
// Patch the BootstrapConfigTemplate ref of the MachineDeploymentClass to reference the new BootstrapConfigTemplate.
288
315
patchHelper , err := patch .NewHelper (input .ClusterClass , mgmtClient )
289
316
Expect (err ).ToNot (HaveOccurred ())
290
317
bootstrapConfigTemplateRef .Name = newBootstrapConfigTemplateName
318
+ infrastructureMachineTemplateRef .Name = newInfrastructureMachineTemplateName
291
319
Expect (patchHelper .Patch (ctx , input .ClusterClass )).To (Succeed ())
292
320
293
321
log .Logf ("Waiting for MachineDeployment rollout for MachineDeploymentClass %q to complete." , mdClass .Class )
@@ -322,7 +350,23 @@ func modifyMachineDeploymentViaClusterClassAndWait(ctx context.Context, input mo
322
350
if err != nil || ! ok {
323
351
return errors .Errorf ("failed to get field %q" , fieldPath )
324
352
}
325
- if currentValue != expectedValue {
353
+ if ! reflect .DeepEqual (currentValue , expectedValue ) {
354
+ return errors .Errorf ("field %q should be equal to %q, but is %q" , fieldPath , expectedValue , currentValue )
355
+ }
356
+ }
357
+
358
+ // Get the corresponding InfrastructureMachineTemplate.
359
+ infrastructureMachineTemplateRef := md .Spec .Template .Spec .InfrastructureRef
360
+ infrastructureMachineTemplate , err := external .Get (ctx , mgmtClient , & infrastructureMachineTemplateRef , input .Cluster .Namespace )
361
+ Expect (err ).ToNot (HaveOccurred ())
362
+
363
+ // Verify that ModifyInfrastructureMachineTemplateFields have been set.
364
+ for fieldPath , expectedValue := range input .ModifyInfrastructureMachineTemplateFields {
365
+ currentValue , ok , err := unstructured .NestedFieldNoCopy (infrastructureMachineTemplate .Object , strings .Split (fieldPath , "." )... )
366
+ if err != nil || ! ok {
367
+ return errors .Errorf ("failed to get field %q" , fieldPath )
368
+ }
369
+ if ! reflect .DeepEqual (currentValue , expectedValue ) {
326
370
return errors .Errorf ("field %q should be equal to %q, but is %q" , fieldPath , expectedValue , currentValue )
327
371
}
328
372
}
0 commit comments