@@ -56,6 +56,8 @@ func TestGetBlueprint(t *testing.T) {
56
56
57
57
workerInfrastructureMachineTemplate := builder .InfrastructureMachineTemplate (metav1 .NamespaceDefault , "workerinframachinetemplate1" ).
58
58
Build ()
59
+ workerInfrastructureMachinePoolTemplate := builder .InfrastructureMachinePoolTemplate (metav1 .NamespaceDefault , "workerinframachinepooltemplate1" ).
60
+ Build ()
59
61
workerBootstrapTemplate := builder .BootstrapTemplate (metav1 .NamespaceDefault , "workerbootstraptemplate1" ).
60
62
Build ()
61
63
machineHealthCheck := & clusterv1.MachineHealthCheckClass {
@@ -73,6 +75,14 @@ func TestGetBlueprint(t *testing.T) {
73
75
74
76
mds := []clusterv1.MachineDeploymentClass {* machineDeployment }
75
77
78
+ machinePools := builder .MachinePoolClass ("workerclass2" ).
79
+ WithLabels (map [string ]string {"foo" : "bar" }).
80
+ WithAnnotations (map [string ]string {"a" : "b" }).
81
+ WithInfrastructureTemplate (workerInfrastructureMachinePoolTemplate ).
82
+ WithBootstrapTemplate (workerBootstrapTemplate ).
83
+ Build ()
84
+ mps := []clusterv1.MachinePoolClass {* machinePools }
85
+
76
86
// Define test cases.
77
87
tests := []struct {
78
88
name string
@@ -141,6 +151,7 @@ func TestGetBlueprint(t *testing.T) {
141
151
Template : controlPlaneTemplate ,
142
152
},
143
153
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
154
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
144
155
},
145
156
},
146
157
{
@@ -167,6 +178,7 @@ func TestGetBlueprint(t *testing.T) {
167
178
InfrastructureMachineTemplate : controlPlaneInfrastructureMachineTemplate ,
168
179
},
169
180
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
181
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
170
182
},
171
183
},
172
184
{
@@ -217,6 +229,7 @@ func TestGetBlueprint(t *testing.T) {
217
229
MachineHealthCheck : machineHealthCheck ,
218
230
},
219
231
},
232
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
220
233
},
221
234
},
222
235
{
@@ -276,8 +289,60 @@ func TestGetBlueprint(t *testing.T) {
276
289
MachineHealthCheck : machineHealthCheck ,
277
290
},
278
291
MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
292
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {},
279
293
},
280
294
},
295
+ {
296
+ name : "Should read a ClusterClass with a MachinePoolClass" ,
297
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
298
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
299
+ WithControlPlaneTemplate (controlPlaneTemplate ).
300
+ WithWorkerMachinePoolClasses (mps ... ).
301
+ Build (),
302
+ objects : []client.Object {
303
+ infraClusterTemplate ,
304
+ controlPlaneTemplate ,
305
+ workerInfrastructureMachinePoolTemplate ,
306
+ workerBootstrapTemplate ,
307
+ },
308
+ want : & scope.ClusterBlueprint {
309
+ ClusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
310
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
311
+ WithControlPlaneTemplate (controlPlaneTemplate ).
312
+ WithWorkerMachinePoolClasses (mps ... ).
313
+ Build (),
314
+ InfrastructureClusterTemplate : infraClusterTemplate ,
315
+ ControlPlane : & scope.ControlPlaneBlueprint {
316
+ Template : controlPlaneTemplate ,
317
+ },
318
+ MachineDeployments : map [string ]* scope.MachineDeploymentBlueprint {},
319
+ MachinePools : map [string ]* scope.MachinePoolBlueprint {
320
+ "workerclass2" : {
321
+ Metadata : clusterv1.ObjectMeta {
322
+ Labels : map [string ]string {"foo" : "bar" },
323
+ Annotations : map [string ]string {"a" : "b" },
324
+ },
325
+ InfrastructureMachinePoolTemplate : workerInfrastructureMachinePoolTemplate ,
326
+ BootstrapTemplate : workerBootstrapTemplate ,
327
+ },
328
+ },
329
+ },
330
+ },
331
+ {
332
+ name : "Fails if ClusterClass has a MachinePoolClass referencing a BootstrapConfig that does not exist" ,
333
+ clusterClass : builder .ClusterClass (metav1 .NamespaceDefault , "class1" ).
334
+ WithInfrastructureClusterTemplate (infraClusterTemplate ).
335
+ WithControlPlaneTemplate (controlPlaneTemplate ).
336
+ WithWorkerMachinePoolClasses (mps ... ).
337
+ Build (),
338
+ objects : []client.Object {
339
+ infraClusterTemplate ,
340
+ controlPlaneTemplate ,
341
+ workerInfrastructureMachinePoolTemplate ,
342
+ // workerInfrastructureMachinePoolTemplate is missing!
343
+ },
344
+ wantErr : true ,
345
+ },
281
346
}
282
347
for _ , tt := range tests {
283
348
t .Run (tt .name , func (t * testing.T ) {
@@ -334,6 +399,7 @@ func TestGetBlueprint(t *testing.T) {
334
399
g .Expect (tt .want .InfrastructureClusterTemplate ).To (EqualObject (got .InfrastructureClusterTemplate ), cmp .Diff (got .InfrastructureClusterTemplate , tt .want .InfrastructureClusterTemplate ))
335
400
g .Expect (got .ControlPlane ).To (BeComparableTo (tt .want .ControlPlane ), cmp .Diff (got .ControlPlane , tt .want .ControlPlane ))
336
401
g .Expect (tt .want .MachineDeployments ).To (BeComparableTo (got .MachineDeployments ), got .MachineDeployments , tt .want .MachineDeployments )
402
+ g .Expect (tt .want .MachinePools ).To (BeComparableTo (got .MachinePools ), got .MachinePools , tt .want .MachinePools )
337
403
})
338
404
}
339
405
}
0 commit comments