Skip to content

Commit e563b8c

Browse files
authored
Merge pull request #1 from swarren83/add-internal-lb-static-ip-tests
chore: add internal lb static ip tests
2 parents e28d2c8 + 3aac3ad commit e563b8c

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

cloud/services/compute/loadbalancers/reconcile_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,70 @@ func TestService_createOrGetInternalAddress(t *testing.T) {
603603
},
604604
sharedVPC: true,
605605
},
606+
{
607+
name: "static address set for internal load balancer",
608+
scope: func(s *scope.ClusterScope) Scope {
609+
s.GCPCluster.Spec.LoadBalancer = infrav1.LoadBalancerSpec{
610+
LoadBalancerType: &lbTypeInternal,
611+
}
612+
613+
s.GCPCluster.Spec.LoadBalancer.InternalLoadBalancer.IPAddress = ptr.To("1.2.3.4")
614+
return s
615+
},
616+
617+
lbName: infrav1.InternalRoleTagValue,
618+
mockAddress: &cloud.MockAddresses{
619+
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
620+
Objects: map[meta.Key]*cloud.MockAddressesObj{},
621+
},
622+
mockSubnetworks: &cloud.MockSubnetworks{
623+
ProjectRouter: &cloud.SingleProjectRouter{ID: "my-proj"},
624+
Objects: map[meta.Key]*cloud.MockSubnetworksObj{
625+
*meta.RegionalKey("control-plane", "us-central1"): {},
626+
},
627+
},
628+
want: &compute.Address{
629+
Address: "1.2.3.4",
630+
IpVersion: "IPV4",
631+
Name: "my-cluster-api-internal",
632+
Region: "us-central1",
633+
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal",
634+
AddressType: "INTERNAL",
635+
Purpose: "GCE_ENDPOINT",
636+
},
637+
},
638+
{
639+
name: "static address set for internal load balancer using SharedVPC subnet (should create address)",
640+
scope: func(s *scope.ClusterScope) Scope {
641+
s.GCPCluster.Spec.LoadBalancer = infrav1.LoadBalancerSpec{
642+
LoadBalancerType: &lbTypeInternal,
643+
}
644+
645+
s.GCPCluster.Spec.LoadBalancer.InternalLoadBalancer.IPAddress = ptr.To("1.2.3.4")
646+
return s
647+
},
648+
lbName: infrav1.InternalRoleTagValue,
649+
mockAddress: &cloud.MockAddresses{
650+
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
651+
Objects: map[meta.Key]*cloud.MockAddressesObj{},
652+
},
653+
mockSubnetworks: &cloud.MockSubnetworks{
654+
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
655+
Objects: map[meta.Key]*cloud.MockSubnetworksObj{
656+
*meta.RegionalKey("control-plane", "us-central1"): {},
657+
},
658+
},
659+
want: &compute.Address{
660+
Address: "1.2.3.4",
661+
IpVersion: "IPV4",
662+
Name: "my-cluster-api-internal",
663+
Region: "us-central1",
664+
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal",
665+
AddressType: "INTERNAL",
666+
Purpose: "GCE_ENDPOINT",
667+
},
668+
sharedVPC: true,
669+
},
606670
}
607671
for _, tt := range tests {
608672
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)