@@ -37,6 +37,8 @@ func TestGetBlueprint(t *testing.T) {
37
37
builder .GenericInfrastructureClusterTemplateCRD ,
38
38
builder .GenericInfrastructureMachineTemplateCRD ,
39
39
builder .GenericInfrastructureMachineCRD ,
40
+ builder .GenericInfrastructureMachinePoolTemplateCRD ,
41
+ builder .GenericInfrastructureMachinePoolCRD ,
40
42
builder .GenericControlPlaneTemplateCRD ,
41
43
builder .GenericBootstrapConfigTemplateCRD ,
42
44
}
@@ -56,6 +58,8 @@ func TestGetBlueprint(t *testing.T) {
56
58
57
59
workerInfrastructureMachineTemplate := builder .InfrastructureMachineTemplate (metav1 .NamespaceDefault , "workerinframachinetemplate1" ).
58
60
Build ()
61
+ workerInfrastructureMachinePoolTemplate := builder .InfrastructureMachinePoolTemplate (metav1 .NamespaceDefault , "workerinframachinepooltemplate1" ).
62
+ Build ()
59
63
workerBootstrapTemplate := builder .BootstrapTemplate (metav1 .NamespaceDefault , "workerbootstraptemplate1" ).
60
64
Build ()
61
65
machineHealthCheck := & clusterv1.MachineHealthCheckClass {
@@ -73,6 +77,14 @@ func TestGetBlueprint(t *testing.T) {
73
77
74
78
mds := []clusterv1.MachineDeploymentClass {* machineDeployment }
75
79
80
+ machinePools := builder .MachinePoolClass ("workerclass2" ).
81
+ WithLabels (map [string ]string {"foo" : "bar" }).
82
+ WithAnnotations (map [string ]string {"a" : "b" }).
83
+ WithInfrastructureTemplate (workerInfrastructureMachinePoolTemplate ).
84
+ WithBootstrapTemplate (workerBootstrapTemplate ).
85
+ Build ()
86
+ mps := []clusterv1.MachinePoolClass {* machinePools }
87
+
76
88
// Define test cases.
77
89
tests := []struct {
78
90
name string
@@ -141,6 +153,7 @@ func TestGetBlueprint(t *testing.T) {
141
153
Template : controlPlaneTemplate ,
142
154
},
143
155
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
156
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
144
157
},
145
158
},
146
159
{
@@ -167,6 +180,7 @@ func TestGetBlueprint(t *testing.T) {
167
180
InfrastructureMachineTemplate : controlPlaneInfrastructureMachineTemplate ,
168
181
},
169
182
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
183
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
170
184
},
171
185
},
172
186
{
@@ -217,10 +231,11 @@ func TestGetBlueprint(t *testing.T) {
217
231
MachineHealthCheck : machineHealthCheck ,
218
232
},
219
233
},
234
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
220
235
},
221
236
},
222
237
{
223
- name : "Fails if ClusterClass has a MachineDeploymentClass referencing a BootstrapTemplate that does not exist" ,
238
+ name : "Fails if ClusterClass has a MachineDeploymentClass referencing a BootstrapConfigTemplate that does not exist" ,
224
239
clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
225
240
WithInfrastructureClusterTemplate (infraClusterTemplate ).
226
241
WithControlPlaneTemplate (controlPlaneTemplate ).
@@ -276,8 +291,75 @@ func TestGetBlueprint(t *testing.T) {
276
291
MachineHealthCheck : machineHealthCheck ,
277
292
},
278
293
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
294
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
295
+ },
296
+ },
297
+ {
298
+ name : "Should read a ClusterClass with a MachinePoolClass" ,
299
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
300
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
301
+ WithControlPlaneTemplate (controlPlaneTemplate ).
302
+ WithWorkerMachinePoolClasses (mps ... ).
303
+ Build (),
304
+ objects : []client.Object {
305
+ infraClusterTemplate ,
306
+ controlPlaneTemplate ,
307
+ workerInfrastructureMachinePoolTemplate ,
308
+ workerBootstrapTemplate ,
309
+ },
310
+ want : & scope.ClusterBlueprint {
311
+ ClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
312
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
313
+ WithControlPlaneTemplate (controlPlaneTemplate ).
314
+ WithWorkerMachinePoolClasses (mps ... ).
315
+ Build (),
316
+ InfrastructureClusterTemplate : infraClusterTemplate ,
317
+ ControlPlane : & scope.ControlPlaneBlueprint {
318
+ Template : controlPlaneTemplate ,
319
+ },
320
+ MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
321
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {
322
+ "workerclass2" : {
323
+ Metadata : clusterv1.ObjectMeta {
324
+ Labels : map [string ]string {"foo" : "bar" },
325
+ Annotations : map [string ]string {"a" : "b" },
326
+ },
327
+ InfrastructureMachinePoolTemplate : workerInfrastructureMachinePoolTemplate ,
328
+ BootstrapTemplate : workerBootstrapTemplate ,
329
+ },
330
+ },
279
331
},
280
332
},
333
+ {
334
+ name : "Fails if ClusterClass has a MachinePoolClass referencing a BootstrapConfigTemplate that does not exist" ,
335
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
336
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
337
+ WithControlPlaneTemplate (controlPlaneTemplate ).
338
+ WithWorkerMachinePoolClasses (mps ... ).
339
+ Build (),
340
+ objects : []client.Object {
341
+ infraClusterTemplate ,
342
+ controlPlaneTemplate ,
343
+ workerInfrastructureMachinePoolTemplate ,
344
+ // workerBootstrapTemplate is missing!
345
+ },
346
+ wantErr : true ,
347
+ },
348
+ {
349
+ name : "Fails if ClusterClass has a MachinePoolClass referencing a InfrastructureMachinePoolTemplate that does not exist" ,
350
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
351
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
352
+ WithControlPlaneTemplate (controlPlaneTemplate ).
353
+ WithWorkerMachinePoolClasses (mps ... ).
354
+ Build (),
355
+ objects : []client.Object {
356
+ infraClusterTemplate ,
357
+ controlPlaneTemplate ,
358
+ workerBootstrapTemplate ,
359
+ // workerInfrastructureMachinePoolTemplate is missing!
360
+ },
361
+ wantErr : true ,
362
+ },
281
363
}
282
364
for _ , tt := range tests {
283
365
t .Run (tt .name , func (t * testing.T ) {
@@ -333,7 +415,8 @@ func TestGetBlueprint(t *testing.T) {
333
415
g .Expect (tt .want .ClusterClass ).To (EqualObject (got .ClusterClass , IgnoreAutogeneratedMetadata ))
334
416
g .Expect (tt .want .InfrastructureClusterTemplate ).To (EqualObject (got .InfrastructureClusterTemplate ), cmp .Diff (got .InfrastructureClusterTemplate , tt .want .InfrastructureClusterTemplate ))
335
417
g .Expect (got .ControlPlane ).To (BeComparableTo (tt .want .ControlPlane ), cmp .Diff (got .ControlPlane , tt .want .ControlPlane ))
336
- g .Expect (tt .want .MachineDeployments ).To (BeComparableTo (got .MachineDeployments ), got .MachineDeployments , tt .want .MachineDeployments )
418
+ g .Expect (tt .want .MachineDeployments ).To (BeComparableTo (got .MachineDeployments ), cmp .Diff (got .MachineDeployments , tt .want .MachineDeployments ))
419
+ g .Expect (tt .want .MachinePools ).To (BeComparableTo (got .MachinePools ), cmp .Diff (got .MachinePools , tt .want .MachinePools ))
337
420
})
338
421
}
339
422
}
0 commit comments