Skip to content

Commit 71f39ce

Browse files
authored
Merge pull request #1469 from hrbasic/allow-global-access
option to enable global access for internal passthrough load balancers
2 parents 7ea9851 + 1d6db6d commit 71f39ce

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

api/v1beta1/types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,17 @@ type ObjectReference struct {
357357
Name string `json:"name"`
358358
}
359359

360+
// InternalAccess defines the access for the Internal Passthrough Load Balancer.
361+
type InternalAccess string
362+
363+
const (
364+
// InternalAccessRegional restricts traffic to clients within the same region as the internal load balancer.
365+
InternalAccessRegional = InternalAccess("Regional")
366+
367+
// InternalAccessGlobal allows traffic from any region to access the internal load balancer.
368+
InternalAccessGlobal = InternalAccess("Global")
369+
)
370+
360371
// LoadBalancer specifies the configuration of a LoadBalancer.
361372
type LoadBalancer struct {
362373
// Name is the name of the Load Balancer. If not set a default name
@@ -371,4 +382,17 @@ type LoadBalancer struct {
371382
// required for the Load Balancer, if not defined the first configured subnet will be
372383
// used.
373384
Subnet *string `json:"subnet,omitempty"`
385+
386+
// InternalAccess defines the access for the Internal Passthrough Load Balancer.
387+
// It determines whether the load balancer allows global access,
388+
// or restricts traffic to clients within the same region as the load balancer.
389+
// If unspecified, the value defaults to "Regional".
390+
//
391+
// Possible values:
392+
// "Regional" - Only clients in the same region as the load balancer can access it.
393+
// "Global" - Clients from any region can access the load balancer.
394+
// +kubebuilder:validation:Enum=Regional;Global
395+
// +kubebuilder:default=Regional
396+
// +optional
397+
InternalAccess InternalAccess `json:"internalAccess,omitempty"`
374398
}

cloud/services/compute/loadbalancers/reconcile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ func (s *Service) createOrGetRegionalForwardingRule(ctx context.Context, lbname
601601
spec.LoadBalancingScheme = string(loadBalanceTrafficInternal)
602602
spec.Region = s.scope.Region()
603603
spec.BackendService = backendSvc.SelfLink
604+
lbSpec := s.scope.LoadBalancer()
605+
if lbSpec.InternalLoadBalancer != nil && lbSpec.InternalLoadBalancer.InternalAccess == infrav1.InternalAccessGlobal {
606+
spec.AllowGlobalAccess = true
607+
}
604608
// Ports is used instead or PortRange for passthrough Load Balancer
605609
// Configure ports for k8s API to match the external API which is the first port of range
606610
var ports []string

cloud/services/compute/loadbalancers/reconcile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ func TestService_createOrGetRegionalForwardingRule(t *testing.T) {
818818
Region: "us-central1",
819819
Name: "my-cluster-api-internal",
820820
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/forwardingRules/my-cluster-api-internal",
821+
AllowGlobalAccess: false,
821822
},
822823
},
823824
}

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclusters.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ spec:
122122
description: InternalLoadBalancer is the configuration for an
123123
Internal Passthrough Network Load Balancer.
124124
properties:
125+
internalAccess:
126+
default: Regional
127+
description: |-
128+
InternalAccess defines the access for the Internal Passthrough Load Balancer.
129+
It determines whether the load balancer allows global access,
130+
or restricts traffic to clients within the same region as the load balancer.
131+
If unspecified, the value defaults to "Regional".
132+
133+
Possible values:
134+
"Regional" - Only clients in the same region as the load balancer can access it.
135+
"Global" - Clients from any region can access the load balancer.
136+
enum:
137+
- Regional
138+
- Global
139+
type: string
125140
name:
126141
description: |-
127142
Name is the name of the Load Balancer. If not set a default name

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpclustertemplates.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ spec:
138138
description: InternalLoadBalancer is the configuration
139139
for an Internal Passthrough Network Load Balancer.
140140
properties:
141+
internalAccess:
142+
default: Regional
143+
description: |-
144+
InternalAccess defines the access for the Internal Passthrough Load Balancer.
145+
It determines whether the load balancer allows global access,
146+
or restricts traffic to clients within the same region as the load balancer.
147+
If unspecified, the value defaults to "Regional".
148+
149+
Possible values:
150+
"Regional" - Only clients in the same region as the load balancer can access it.
151+
"Global" - Clients from any region can access the load balancer.
152+
enum:
153+
- Regional
154+
- Global
155+
type: string
141156
name:
142157
description: |-
143158
Name is the name of the Load Balancer. If not set a default name

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedclusters.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ spec:
117117
description: InternalLoadBalancer is the configuration for an
118118
Internal Passthrough Network Load Balancer.
119119
properties:
120+
internalAccess:
121+
default: Regional
122+
description: |-
123+
InternalAccess defines the access for the Internal Passthrough Load Balancer.
124+
It determines whether the load balancer allows global access,
125+
or restricts traffic to clients within the same region as the load balancer.
126+
If unspecified, the value defaults to "Regional".
127+
128+
Possible values:
129+
"Regional" - Only clients in the same region as the load balancer can access it.
130+
"Global" - Clients from any region can access the load balancer.
131+
enum:
132+
- Regional
133+
- Global
134+
type: string
120135
name:
121136
description: |-
122137
Name is the name of the Load Balancer. If not set a default name

0 commit comments

Comments
 (0)