@@ -536,6 +536,23 @@ func TestService_createOrGetAddress(t *testing.T) {
536536}
537537
538538func TestService_createOrGetInternalAddress (t * testing.T ) {
539+ address := & compute.Address {
540+ IpVersion : "IPV4" ,
541+ Name : "my-cluster-api-internal" ,
542+ Region : "us-central1" ,
543+ SelfLink : "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal" ,
544+ AddressType : "INTERNAL" ,
545+ Purpose : "GCE_ENDPOINT" ,
546+ }
547+ staticAddress := & compute.Address {
548+ Address : "10.0.0.10" ,
549+ IpVersion : "IPV4" ,
550+ Name : "my-cluster-api-internal" ,
551+ Region : "us-central1" ,
552+ SelfLink : "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal" ,
553+ AddressType : "INTERNAL" ,
554+ Purpose : "GCE_ENDPOINT" ,
555+ }
539556 tests := []struct {
540557 name string
541558 scope func (s * scope.ClusterScope ) Scope
@@ -565,17 +582,10 @@ func TestService_createOrGetInternalAddress(t *testing.T) {
565582 * meta .RegionalKey ("control-plane" , "us-central1" ): {},
566583 },
567584 },
568- want : & compute.Address {
569- IpVersion : "IPV4" ,
570- Name : "my-cluster-api-internal" ,
571- Region : "us-central1" ,
572- SelfLink : "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal" ,
573- AddressType : "INTERNAL" ,
574- Purpose : "GCE_ENDPOINT" ,
575- },
585+ want : address ,
576586 },
577587 {
578- name : "address does not exist for internal load balancer using SharedVPC subnet (should create address) " ,
588+ name : "address does not exist for internal load balancer using SharedVPC subnet" ,
579589 scope : func (s * scope.ClusterScope ) Scope {
580590 s .GCPCluster .Spec .LoadBalancer = infrav1.LoadBalancerSpec {
581591 LoadBalancerType : & lbTypeInternal ,
@@ -593,14 +603,57 @@ func TestService_createOrGetInternalAddress(t *testing.T) {
593603 * meta .RegionalKey ("control-plane" , "us-central1" ): {},
594604 },
595605 },
596- want : & compute.Address {
597- IpVersion : "IPV4" ,
598- Name : "my-cluster-api-internal" ,
599- Region : "us-central1" ,
600- SelfLink : "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/addresses/my-cluster-api-internal" ,
601- AddressType : "INTERNAL" ,
602- Purpose : "GCE_ENDPOINT" ,
606+ want : address ,
607+ sharedVPC : true ,
608+ },
609+ {
610+ name : "static address set for internal load balancer" ,
611+ scope : func (s * scope.ClusterScope ) Scope {
612+ s .GCPCluster .Spec .LoadBalancer = infrav1.LoadBalancerSpec {
613+ LoadBalancerType : & lbTypeInternal ,
614+ InternalLoadBalancer : & infrav1.LoadBalancer {
615+ IPAddress : ptr .To ("10.0.0.10" ),
616+ },
617+ }
618+ return s
619+ },
620+ lbName : infrav1 .InternalRoleTagValue ,
621+ mockAddress : & cloud.MockAddresses {
622+ ProjectRouter : & cloud.SingleProjectRouter {ID : "proj-id" },
623+ Objects : map [meta.Key ]* cloud.MockAddressesObj {},
624+ },
625+ mockSubnetworks : & cloud.MockSubnetworks {
626+ ProjectRouter : & cloud.SingleProjectRouter {ID : "my-proj" },
627+ Objects : map [meta.Key ]* cloud.MockSubnetworksObj {
628+ * meta .RegionalKey ("control-plane" , "us-central1" ): {},
629+ },
630+ },
631+ want : staticAddress ,
632+ },
633+ {
634+ name : "static address set for internal load balancer using SharedVPC subnet" ,
635+ scope : func (s * scope.ClusterScope ) Scope {
636+ s .GCPCluster .Spec .LoadBalancer = infrav1.LoadBalancerSpec {
637+ LoadBalancerType : & lbTypeInternal ,
638+ InternalLoadBalancer : & infrav1.LoadBalancer {
639+ IPAddress : ptr .To ("10.0.0.10" ),
640+ },
641+ }
642+
643+ return s
644+ },
645+ lbName : infrav1 .InternalRoleTagValue ,
646+ mockAddress : & cloud.MockAddresses {
647+ ProjectRouter : & cloud.SingleProjectRouter {ID : "proj-id" },
648+ Objects : map [meta.Key ]* cloud.MockAddressesObj {},
649+ },
650+ mockSubnetworks : & cloud.MockSubnetworks {
651+ ProjectRouter : & cloud.SingleProjectRouter {ID : "proj-id" },
652+ Objects : map [meta.Key ]* cloud.MockSubnetworksObj {
653+ * meta .RegionalKey ("control-plane" , "us-central1" ): {},
654+ },
603655 },
656+ want : staticAddress ,
604657 sharedVPC : true ,
605658 },
606659 }
0 commit comments