@@ -217,9 +217,8 @@ func TestLBReconciliation(t *testing.T) {
217
217
},
218
218
},
219
219
{
220
- name : "more than one cp subnet" ,
221
- errorExpected : true ,
222
- matchError : errors .New ("cannot have more than 1 control plane endpoint subnet" ),
220
+ name : "create load balancer more than one subnet" ,
221
+ errorExpected : false ,
223
222
testSpecificSetup : func (clusterScope * ClusterScope , lbClient * mock_lb.MockLoadBalancerClient ) {
224
223
clusterScope .OCIClusterAccessor .GetNetworkSpec ().Vcn .Subnets = []* infrastructurev1beta2.Subnet {
225
224
{
@@ -231,11 +230,89 @@ func TestLBReconciliation(t *testing.T) {
231
230
ID : common .String ("s2" ),
232
231
},
233
232
}
233
+ clusterScope .OCIClusterAccessor .GetNetworkSpec ().Vcn .NetworkSecurityGroup = infrastructurev1beta2.NetworkSecurityGroup {
234
+ List : []* infrastructurev1beta2.NSG {
235
+ {
236
+ Role : infrastructurev1beta2 .ControlPlaneEndpointRole ,
237
+ ID : common .String ("nsg1" ),
238
+ },
239
+ {
240
+ Role : infrastructurev1beta2 .ControlPlaneEndpointRole ,
241
+ ID : common .String ("nsg2" ),
242
+ },
243
+ },
244
+ }
245
+ definedTags , definedTagsInterface := getDefinedTags ()
246
+ ociClusterAccessor .OCICluster .Spec .DefinedTags = definedTags
234
247
lbClient .EXPECT ().ListLoadBalancers (gomock .Any (), gomock .Eq (loadbalancer.ListLoadBalancersRequest {
235
248
CompartmentId : common .String ("compartment-id" ),
236
249
DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
250
+ })).Return (loadbalancer.ListLoadBalancersResponse {
251
+ Items : []loadbalancer.LoadBalancer {},
252
+ }, nil )
253
+ lbClient .EXPECT ().CreateLoadBalancer (gomock .Any (), gomock .Eq (loadbalancer.CreateLoadBalancerRequest {
254
+ CreateLoadBalancerDetails : loadbalancer.CreateLoadBalancerDetails {
255
+ CompartmentId : common .String ("compartment-id" ),
256
+ DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
257
+ SubnetIds : []string {"s1" , "s2" },
258
+ NetworkSecurityGroupIds : []string {"nsg1" , "nsg2" },
259
+ IsPrivate : common .Bool (false ),
260
+ ShapeName : common .String ("flexible" ),
261
+ ShapeDetails : & loadbalancer.ShapeDetails {MaximumBandwidthInMbps : common .Int (100 ),
262
+ MinimumBandwidthInMbps : common .Int (10 )},
263
+ Listeners : map [string ]loadbalancer.ListenerDetails {
264
+ APIServerLBListener : {
265
+ Protocol : common .String ("TCP" ),
266
+ Port : common .Int (int (6443 )),
267
+ DefaultBackendSetName : common .String (APIServerLBBackendSetName ),
268
+ },
269
+ },
270
+ BackendSets : map [string ]loadbalancer.BackendSetDetails {
271
+ APIServerLBBackendSetName : loadbalancer.BackendSetDetails {
272
+ Policy : common .String ("ROUND_ROBIN" ),
273
+
274
+ HealthChecker : & loadbalancer.HealthCheckerDetails {
275
+ Port : common .Int (6443 ),
276
+ Protocol : common .String ("TCP" ),
277
+ },
278
+ Backends : []loadbalancer.BackendDetails {},
279
+ },
280
+ },
281
+ FreeformTags : tags ,
282
+ DefinedTags : definedTagsInterface ,
283
+ },
284
+ OpcRetryToken : ociutil .GetOPCRetryToken ("%s-%s" , "create-lb" , string ("resource_uid" )),
237
285
})).
238
- Return (loadbalancer.ListLoadBalancersResponse {}, nil )
286
+ Return (loadbalancer.CreateLoadBalancerResponse {
287
+ OpcWorkRequestId : common .String ("opc-wr-id" ),
288
+ }, nil )
289
+ lbClient .EXPECT ().GetWorkRequest (gomock .Any (), gomock .Eq (loadbalancer.GetWorkRequestRequest {
290
+ WorkRequestId : common .String ("opc-wr-id" ),
291
+ })).Return (loadbalancer.GetWorkRequestResponse {
292
+ WorkRequest : loadbalancer.WorkRequest {
293
+ LoadBalancerId : common .String ("lb-id" ),
294
+ LifecycleState : loadbalancer .WorkRequestLifecycleStateSucceeded ,
295
+ },
296
+ }, nil )
297
+
298
+ lbClient .EXPECT ().GetLoadBalancer (gomock .Any (), gomock .Eq (loadbalancer.GetLoadBalancerRequest {
299
+ LoadBalancerId : common .String ("lb-id" ),
300
+ })).
301
+ Return (loadbalancer.GetLoadBalancerResponse {
302
+ LoadBalancer : loadbalancer.LoadBalancer {
303
+ Id : common .String ("lb-id" ),
304
+ FreeformTags : tags ,
305
+ IsPrivate : common .Bool (false ),
306
+ DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
307
+ IpAddresses : []loadbalancer.IpAddress {
308
+ {
309
+ IpAddress : common .String ("2.2.2.2" ),
310
+ IsPublic : common .Bool (true ),
311
+ },
312
+ },
313
+ },
314
+ }, nil )
315
+
239
316
},
240
317
},
241
318
{
@@ -248,6 +325,18 @@ func TestLBReconciliation(t *testing.T) {
248
325
ID : common .String ("s1" ),
249
326
},
250
327
}
328
+ clusterScope .OCIClusterAccessor .GetNetworkSpec ().Vcn .NetworkSecurityGroup = infrastructurev1beta2.NetworkSecurityGroup {
329
+ List : []* infrastructurev1beta2.NSG {
330
+ {
331
+ Role : infrastructurev1beta2 .ControlPlaneEndpointRole ,
332
+ ID : common .String ("nsg1" ),
333
+ },
334
+ {
335
+ Role : infrastructurev1beta2 .ControlPlaneEndpointRole ,
336
+ ID : common .String ("nsg2" ),
337
+ },
338
+ },
339
+ }
251
340
definedTags , definedTagsInterface := getDefinedTags ()
252
341
ociClusterAccessor .OCICluster .Spec .DefinedTags = definedTags
253
342
lbClient .EXPECT ().ListLoadBalancers (gomock .Any (), gomock .Eq (loadbalancer.ListLoadBalancersRequest {
@@ -258,11 +347,12 @@ func TestLBReconciliation(t *testing.T) {
258
347
}, nil )
259
348
lbClient .EXPECT ().CreateLoadBalancer (gomock .Any (), gomock .Eq (loadbalancer.CreateLoadBalancerRequest {
260
349
CreateLoadBalancerDetails : loadbalancer.CreateLoadBalancerDetails {
261
- CompartmentId : common .String ("compartment-id" ),
262
- DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
263
- SubnetIds : []string {"s1" },
264
- IsPrivate : common .Bool (false ),
265
- ShapeName : common .String ("flexible" ),
350
+ CompartmentId : common .String ("compartment-id" ),
351
+ DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
352
+ SubnetIds : []string {"s1" },
353
+ NetworkSecurityGroupIds : []string {"nsg1" , "nsg2" },
354
+ IsPrivate : common .Bool (false ),
355
+ ShapeName : common .String ("flexible" ),
266
356
ShapeDetails : & loadbalancer.ShapeDetails {MaximumBandwidthInMbps : common .Int (100 ),
267
357
MinimumBandwidthInMbps : common .Int (10 )},
268
358
Listeners : map [string ]loadbalancer.ListenerDetails {
@@ -340,10 +430,11 @@ func TestLBReconciliation(t *testing.T) {
340
430
}, nil )
341
431
lbClient .EXPECT ().CreateLoadBalancer (gomock .Any (), gomock .Eq (loadbalancer.CreateLoadBalancerRequest {
342
432
CreateLoadBalancerDetails : loadbalancer.CreateLoadBalancerDetails {
343
- CompartmentId : common .String ("compartment-id" ),
344
- DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
345
- SubnetIds : []string {"s1" },
346
- ShapeName : common .String ("flexible" ),
433
+ CompartmentId : common .String ("compartment-id" ),
434
+ DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
435
+ SubnetIds : []string {"s1" },
436
+ NetworkSecurityGroupIds : make ([]string , 0 ),
437
+ ShapeName : common .String ("flexible" ),
347
438
ShapeDetails : & loadbalancer.ShapeDetails {MaximumBandwidthInMbps : common .Int (100 ),
348
439
MinimumBandwidthInMbps : common .Int (10 )},
349
440
IsPrivate : common .Bool (false ),
@@ -391,10 +482,11 @@ func TestLBReconciliation(t *testing.T) {
391
482
Return (loadbalancer.ListLoadBalancersResponse {}, nil )
392
483
lbClient .EXPECT ().CreateLoadBalancer (gomock .Any (), gomock .Eq (loadbalancer.CreateLoadBalancerRequest {
393
484
CreateLoadBalancerDetails : loadbalancer.CreateLoadBalancerDetails {
394
- CompartmentId : common .String ("compartment-id" ),
395
- DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
396
- SubnetIds : []string {"s1" },
397
- ShapeName : common .String ("flexible" ),
485
+ CompartmentId : common .String ("compartment-id" ),
486
+ DisplayName : common .String (fmt .Sprintf ("%s-%s" , "cluster" , "apiserver" )),
487
+ SubnetIds : []string {"s1" },
488
+ NetworkSecurityGroupIds : make ([]string , 0 ),
489
+ ShapeName : common .String ("flexible" ),
398
490
ShapeDetails : & loadbalancer.ShapeDetails {MaximumBandwidthInMbps : common .Int (100 ),
399
491
MinimumBandwidthInMbps : common .Int (10 )},
400
492
IsPrivate : common .Bool (false ),
0 commit comments