|
77 | 77 | Region: "us-west", |
78 | 78 | IPv4: []*net.IP{&publicIPv4}, |
79 | 79 | } |
80 | | - newIpHolderInstance = linodego.Instance{ |
81 | | - ID: 123456, |
82 | | - Label: generateClusterScopedIPHolderLinodeName(zone, "linodelb"), |
83 | | - Type: "g6-standard-1", |
84 | | - Region: "us-west", |
85 | | - IPv4: []*net.IP{&publicIPv4}, |
86 | | - } |
| 80 | + newIpHolderInstance = linodego.Instance{} |
87 | 81 | ) |
88 | 82 |
|
89 | 83 | func TestCiliumCCMLoadBalancers(t *testing.T) { |
@@ -112,8 +106,12 @@ func TestCiliumCCMLoadBalancers(t *testing.T) { |
112 | 106 | f: testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffix, |
113 | 107 | }, |
114 | 108 | { |
115 | | - name: "Create Cilium Load Balancer With no existing IP holder nanode", |
116 | | - f: testCreateWithNoExistingIPHolder, |
| 109 | + name: "Create Cilium Load Balancer With no existing IP holder nanode and short suffix", |
| 110 | + f: testCreateWithNoExistingIPHolderUsingShortSuffix, |
| 111 | + }, |
| 112 | + { |
| 113 | + name: "Create Cilium Load Balancer With no existing IP holder nanode and no suffix", |
| 114 | + f: testCreateWithNoExistingIPHolderUsingNoSuffix, |
117 | 115 | }, |
118 | 116 | { |
119 | 117 | name: "Create Cilium Load Balancer With no existing IP holder nanode and 63 char long suffix", |
@@ -190,10 +188,21 @@ func addNodes(t *testing.T, kubeClient kubernetes.Interface, nodes []*v1.Node) { |
190 | 188 | } |
191 | 189 | } |
192 | 190 |
|
| 191 | +func createNewIpHolderInstance() linodego.Instance { |
| 192 | + return linodego.Instance{ |
| 193 | + ID: 123456, |
| 194 | + Label: generateClusterScopedIPHolderLinodeName(zone, Options.IpHolderSuffix), |
| 195 | + Type: "g6-standard-1", |
| 196 | + Region: "us-west", |
| 197 | + IPv4: []*net.IP{&publicIPv4}, |
| 198 | + } |
| 199 | +} |
| 200 | + |
193 | 201 | func testNoBGPNodeLabel(t *testing.T, mc *mocks.MockClient) { |
194 | 202 | Options.BGPNodeSelector = "" |
195 | 203 | Options.IpHolderSuffix = "linodelb" |
196 | 204 | svc := createTestService() |
| 205 | + newIpHolderInstance = createNewIpHolderInstance() |
197 | 206 |
|
198 | 207 | kubeClient, _ := k8sClient.NewFakeClientset() |
199 | 208 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -258,6 +267,7 @@ func testUnsupportedRegion(t *testing.T, mc *mocks.MockClient) { |
258 | 267 | func testCreateWithExistingIPHolderWithOldIpHolderNamingConvention(t *testing.T, mc *mocks.MockClient) { |
259 | 268 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
260 | 269 | svc := createTestService() |
| 270 | + newIpHolderInstance = createNewIpHolderInstance() |
261 | 271 |
|
262 | 272 | kubeClient, _ := k8sClient.NewFakeClientset() |
263 | 273 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -297,6 +307,7 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConvention(t *testing.T, |
297 | 307 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
298 | 308 | Options.IpHolderSuffix = "linodelb" |
299 | 309 | svc := createTestService() |
| 310 | + newIpHolderInstance = createNewIpHolderInstance() |
300 | 311 |
|
301 | 312 | kubeClient, _ := k8sClient.NewFakeClientset() |
302 | 313 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -336,6 +347,7 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi |
336 | 347 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
337 | 348 | Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp" |
338 | 349 | svc := createTestService() |
| 350 | + newIpHolderInstance = createNewIpHolderInstance() |
339 | 351 |
|
340 | 352 | kubeClient, _ := k8sClient.NewFakeClientset() |
341 | 353 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -371,10 +383,55 @@ func testCreateWithExistingIPHolderWithNewIpHolderNamingConventionUsingLongSuffi |
371 | 383 | } |
372 | 384 | } |
373 | 385 |
|
374 | | -func testCreateWithNoExistingIPHolder(t *testing.T, mc *mocks.MockClient) { |
| 386 | +func testCreateWithNoExistingIPHolderUsingNoSuffix(t *testing.T, mc *mocks.MockClient) { |
| 387 | + Options.BGPNodeSelector = "cilium-bgp-peering=true" |
| 388 | + Options.IpHolderSuffix = "" |
| 389 | + svc := createTestService() |
| 390 | + newIpHolderInstance = createNewIpHolderInstance() |
| 391 | + |
| 392 | + kubeClient, _ := k8sClient.NewFakeClientset() |
| 393 | + ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
| 394 | + addService(t, kubeClient, svc) |
| 395 | + addNodes(t, kubeClient, nodes) |
| 396 | + lb := &loadbalancers{mc, zone, kubeClient, ciliumClient, ciliumLBType} |
| 397 | + |
| 398 | + filter := map[string]string{"label": fmt.Sprintf("%s-%s", ipHolderLabelPrefix, zone)} |
| 399 | + rawFilter, _ := json.Marshal(filter) |
| 400 | + mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{}, nil) |
| 401 | + filter = map[string]string{"label": generateClusterScopedIPHolderLinodeName(zone, Options.IpHolderSuffix)} |
| 402 | + rawFilter, _ = json.Marshal(filter) |
| 403 | + mc.EXPECT().ListInstances(gomock.Any(), linodego.NewListOptions(1, string(rawFilter))).Times(1).Return([]linodego.Instance{}, nil) |
| 404 | + dummySharedIP := "45.76.101.26" |
| 405 | + mc.EXPECT().CreateInstance(gomock.Any(), gomock.Any()).Times(1).Return(&newIpHolderInstance, nil) |
| 406 | + mc.EXPECT().GetInstanceIPAddresses(gomock.Any(), newIpHolderInstance.ID).Times(1).Return(&linodego.InstanceIPAddressResponse{ |
| 407 | + IPv4: &linodego.InstanceIPv4Response{ |
| 408 | + Public: []*linodego.InstanceIP{{Address: publicIPv4.String()}, {Address: dummySharedIP}}, |
| 409 | + }, |
| 410 | + }, nil) |
| 411 | + mc.EXPECT().AddInstanceIPAddress(gomock.Any(), newIpHolderInstance.ID, true).Times(1).Return(&linodego.InstanceIP{Address: dummySharedIP}, nil) |
| 412 | + mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ |
| 413 | + IPs: []string{dummySharedIP}, |
| 414 | + LinodeID: 11111, |
| 415 | + }).Times(1) |
| 416 | + mc.EXPECT().ShareIPAddresses(gomock.Any(), linodego.IPAddressesShareOptions{ |
| 417 | + IPs: []string{dummySharedIP}, |
| 418 | + LinodeID: 22222, |
| 419 | + }).Times(1) |
| 420 | + |
| 421 | + lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes) |
| 422 | + if err != nil { |
| 423 | + t.Fatalf("expected a nil error, got %v", err) |
| 424 | + } |
| 425 | + if lbStatus == nil { |
| 426 | + t.Fatal("expected non-nil lbStatus") |
| 427 | + } |
| 428 | +} |
| 429 | + |
| 430 | +func testCreateWithNoExistingIPHolderUsingShortSuffix(t *testing.T, mc *mocks.MockClient) { |
375 | 431 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
376 | 432 | Options.IpHolderSuffix = "linodelb" |
377 | 433 | svc := createTestService() |
| 434 | + newIpHolderInstance = createNewIpHolderInstance() |
378 | 435 |
|
379 | 436 | kubeClient, _ := k8sClient.NewFakeClientset() |
380 | 437 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -418,6 +475,7 @@ func testCreateWithNoExistingIPHolderUsingLongSuffix(t *testing.T, mc *mocks.Moc |
418 | 475 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
419 | 476 | Options.IpHolderSuffix = "OaTJrRuufacHVougjwkpBpmstiqvswvBNEMWXsRYfMBTCkKIUTXpbGIcIbDWSQp" |
420 | 477 | svc := createTestService() |
| 478 | + newIpHolderInstance = createNewIpHolderInstance() |
421 | 479 |
|
422 | 480 | kubeClient, _ := k8sClient.NewFakeClientset() |
423 | 481 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -487,6 +545,7 @@ func testEnsureCiliumLoadBalancerDeletedWithNewIpHolderNamingConvention(t *testi |
487 | 545 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
488 | 546 | Options.IpHolderSuffix = "linodelb" |
489 | 547 | svc := createTestService() |
| 548 | + newIpHolderInstance = createNewIpHolderInstance() |
490 | 549 |
|
491 | 550 | kubeClient, _ := k8sClient.NewFakeClientset() |
492 | 551 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
@@ -573,6 +632,7 @@ func testCiliumUpdateLoadBalancerAddNodeWithNewIpHolderNamingConvention(t *testi |
573 | 632 | Options.BGPNodeSelector = "cilium-bgp-peering=true" |
574 | 633 | Options.IpHolderSuffix = "linodelb" |
575 | 634 | svc := createTestService() |
| 635 | + newIpHolderInstance = createNewIpHolderInstance() |
576 | 636 |
|
577 | 637 | kubeClient, _ := k8sClient.NewFakeClientset() |
578 | 638 | ciliumClient := &fakev2alpha1.FakeCiliumV2alpha1{Fake: &kubeClient.CiliumFakeClientset.Fake} |
|
0 commit comments