Skip to content

Commit 1ffc3e7

Browse files
zac-nixonniclask25
authored and
niclask25
committed
[feat: gw-api] Creating Target Group + TGB from Gateway spec (#4150)
* [gw api] tg creation * fixes to get tg + tgb working * make logging less noisy * refactor duplicated consts * tg tests * fix interval and timeout to appease alb * use shared constant for health check port * refactor multicluster to target group props * refactor to use route kind enum * infer target group type from route
1 parent 87161a5 commit 1ffc3e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1359
-171
lines changed

apis/gateway/v1beta1/targetgroupconfig_types.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ type HealthCheckConfiguration struct {
6565
// +optional
6666
HealthCheckPath *string `json:"healthCheckPath,omitempty"`
6767

68-
// healthCheckPort The port to use to connect with the target.
68+
// healthCheckPort The port the load balancer uses when performing health checks on targets.
69+
// The default is to use the port on which each target receives traffic from the load balancer.
6970
// +optional
70-
HealthCheckPort *int32 `json:"healthCheckPort,omitempty"`
71+
HealthCheckPort *string `json:"healthCheckPort,omitempty"`
7172

7273
// healthCheckProtocol The protocol to use to connect with the target. The GENEVE, TLS, UDP, and TCP_UDP protocols are not supported for health checks.
7374
// +optional
@@ -116,6 +117,18 @@ const (
116117
TargetGroupHealthCheckProtocolTCP TargetGroupHealthCheckProtocol = "tcp"
117118
)
118119

120+
// +kubebuilder:validation:Enum=HTTP;HTTPS;TCP;TLS;UDP;TCP_UDP
121+
type Protocol string
122+
123+
const (
124+
ProtocolHTTP Protocol = "HTTP"
125+
ProtocolHTTPS Protocol = "HTTPS"
126+
ProtocolTCP Protocol = "TCP"
127+
ProtocolTLS Protocol = "TLS"
128+
ProtocolUDP Protocol = "UDP"
129+
ProtocolTCP_UDP Protocol = "TCP_UDP"
130+
)
131+
119132
// +kubebuilder:validation:Enum=http1;http2;grpc
120133
type ProtocolVersion string
121134

@@ -125,12 +138,23 @@ const (
125138
ProtocolVersionGRPC ProtocolVersion = "grpc"
126139
)
127140

141+
// +kubebuilder:validation:Enum=none;prefer-route-specific;prefer-default
142+
type MergeMode string
143+
144+
const (
145+
MergeModeNone MergeMode = "none"
146+
MergeModePreferRouteSpecific MergeMode = "prefer-route-specific"
147+
MergeModePreferDefault MergeMode = "prefer-default"
148+
)
149+
128150
// TargetGroupConfigurationSpec defines the TargetGroup properties for a route.
129151
type TargetGroupConfigurationSpec struct {
130152

131153
// targetReference the kubernetes object to attach the Target Group settings to.
132154
TargetReference Reference `json:"targetReference"`
133155

156+
// mergeMode the mode to use for merging the identified per-route configuration and default configuration.
157+
134158
// defaultRouteConfiguration fallback configuration applied to all routes, unless overridden by route-specific configurations.
135159
// +optional
136160
DefaultConfiguration TargetGroupProps `json:"defaultConfiguration,omitempty"`
@@ -141,19 +165,23 @@ type TargetGroupConfigurationSpec struct {
141165
}
142166

143167
// +kubebuilder:validation:Pattern="^(HTTPRoute|TLSRoute|TCPRoute|UDPRoute|GRPCRoute)?:([^:]+)?:([^:]+)?$"
144-
type RouteName string
168+
type RouteIdentifier string
145169

146170
// RouteConfiguration defines the per route configuration
147171
type RouteConfiguration struct {
148-
// name the name of the route, it should be in the form of ROUTE:NAMESPACE:NAME
149-
Name RouteName `json:"name"`
172+
// name the identifier of the route, it should be in the form of ROUTE:NAMESPACE:NAME
173+
Identifier RouteIdentifier `json:"identifier"`
150174

151175
// targetGroupProps the target group specific properties
152176
TargetGroupProps TargetGroupProps `json:"targetGroupProps"`
153177
}
154178

155179
// TargetGroupProps defines the target group properties
156180
type TargetGroupProps struct {
181+
// targetGroupName specifies the name to assign to the Target Group. If not defined, then one is generated.
182+
// +optional
183+
TargetGroupName string `json:"targetGroupName,omitempty"`
184+
157185
// ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred.
158186
// +optional
159187
IPAddressType *TargetGroupIPAddressType `json:"ipAddressType,omitempty"`
@@ -174,10 +202,20 @@ type TargetGroupProps struct {
174202
// +optional
175203
TargetType *TargetType `json:"targetType,omitempty"`
176204

205+
// Protocol [Application / Network Load Balancer] the protocol for the target group.
206+
// If unspecified, it will be automatically inferred.
207+
// +optional
208+
Protocol *Protocol `json:"protocol,omitempty"`
209+
177210
// protocolVersion [HTTP/HTTPS protocol] The protocol version. The possible values are GRPC , HTTP1 and HTTP2
178211
// +optional
179212
ProtocolVersion *ProtocolVersion `json:"protocolVersion,omitempty"`
180213

214+
// EnableMultiCluster [Application / Network LoadBalancer]
215+
// Allows for multiple Clusters / Services to use the generated TargetGroup ARN
216+
// +optional
217+
EnableMultiCluster bool `json:"enableMultiCluster,omitempty"`
218+
181219
// vpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred.
182220
// +optional
183221
VpcID *string `json:"vpcID,omitempty"`
@@ -231,6 +269,10 @@ type TargetGroupConfiguration struct {
231269
Status TargetGroupConfigurationStatus `json:"status,omitempty"`
232270
}
233271

272+
func (tgConfig *TargetGroupConfiguration) GetTargetGroupConfigForRoute(name, namespace, kind string) *TargetGroupProps {
273+
return &tgConfig.Spec.DefaultConfiguration
274+
}
275+
234276
// +kubebuilder:object:root=true
235277

236278
// TargetGroupConfigurationList contains a list of TargetGroupConfiguration

apis/gateway/v1beta1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/gateway/gateway-crds.yaml

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ spec:
350350
description: defaultRouteConfiguration fallback configuration applied
351351
to all routes, unless overridden by route-specific configurations.
352352
properties:
353+
enableMultiCluster:
354+
description: |-
355+
EnableMultiCluster [Application / Network LoadBalancer]
356+
Allows for multiple Clusters / Services to use the generated TargetGroup ARN
357+
type: boolean
353358
healthCheckConfig:
354359
description: healthCheckConfig The Health Check configuration
355360
for this backend.
@@ -365,10 +370,10 @@ spec:
365370
on the targets.
366371
type: string
367372
healthCheckPort:
368-
description: healthCheckPort The port to use to connect with
369-
the target.
370-
format: int32
371-
type: integer
373+
description: |-
374+
healthCheckPort The port the load balancer uses when performing health checks on targets.
375+
The default is to use the port on which each target receives traffic from the load balancer.
376+
type: string
372377
healthCheckProtocol:
373378
description: healthCheckProtocol The protocol to use to connect
374379
with the target. The GENEVE, TLS, UDP, and TCP_UDP protocols
@@ -462,6 +467,18 @@ spec:
462467
type: object
463468
type: object
464469
x-kubernetes-map-type: atomic
470+
protocol:
471+
description: |-
472+
Protocol [Application / Network Load Balancer] the protocol for the target group.
473+
If unspecified, it will be automatically inferred.
474+
enum:
475+
- HTTP
476+
- HTTPS
477+
- TCP
478+
- TLS
479+
- UDP
480+
- TCP_UDP
481+
type: string
465482
protocolVersion:
466483
description: protocolVersion [HTTP/HTTPS protocol] The protocol
467484
version. The possible values are GRPC , HTTP1 and HTTP2
@@ -503,6 +520,10 @@ spec:
503520
- value
504521
type: object
505522
type: array
523+
targetGroupName:
524+
description: targetGroupName specifies the name to assign to the
525+
Target Group. If not defined, then one is generated.
526+
type: string
506527
targetType:
507528
description: targetType is the TargetType of TargetGroup. If unspecified,
508529
it will be automatically inferred as instance.
@@ -521,14 +542,19 @@ spec:
521542
items:
522543
description: RouteConfiguration defines the per route configuration
523544
properties:
524-
name:
525-
description: name the name of the route, it should be in the
526-
form of ROUTE:NAMESPACE:NAME
545+
identifier:
546+
description: name the identifier of the route, it should be
547+
in the form of ROUTE:NAMESPACE:NAME
527548
pattern: ^(HTTPRoute|TLSRoute|TCPRoute|UDPRoute|GRPCRoute)?:([^:]+)?:([^:]+)?$
528549
type: string
529550
targetGroupProps:
530551
description: targetGroupProps the target group specific properties
531552
properties:
553+
enableMultiCluster:
554+
description: |-
555+
EnableMultiCluster [Application / Network LoadBalancer]
556+
Allows for multiple Clusters / Services to use the generated TargetGroup ARN
557+
type: boolean
532558
healthCheckConfig:
533559
description: healthCheckConfig The Health Check configuration
534560
for this backend.
@@ -544,10 +570,10 @@ spec:
544570
checks on the targets.
545571
type: string
546572
healthCheckPort:
547-
description: healthCheckPort The port to use to connect
548-
with the target.
549-
format: int32
550-
type: integer
573+
description: |-
574+
healthCheckPort The port the load balancer uses when performing health checks on targets.
575+
The default is to use the port on which each target receives traffic from the load balancer.
576+
type: string
551577
healthCheckProtocol:
552578
description: healthCheckProtocol The protocol to use
553579
to connect with the target. The GENEVE, TLS, UDP,
@@ -644,6 +670,18 @@ spec:
644670
type: object
645671
type: object
646672
x-kubernetes-map-type: atomic
673+
protocol:
674+
description: |-
675+
Protocol [Application / Network Load Balancer] the protocol for the target group.
676+
If unspecified, it will be automatically inferred.
677+
enum:
678+
- HTTP
679+
- HTTPS
680+
- TCP
681+
- TLS
682+
- UDP
683+
- TCP_UDP
684+
type: string
647685
protocolVersion:
648686
description: protocolVersion [HTTP/HTTPS protocol] The protocol
649687
version. The possible values are GRPC , HTTP1 and HTTP2
@@ -686,6 +724,10 @@ spec:
686724
- value
687725
type: object
688726
type: array
727+
targetGroupName:
728+
description: targetGroupName specifies the name to assign
729+
to the Target Group. If not defined, then one is generated.
730+
type: string
689731
targetType:
690732
description: targetType is the TargetType of TargetGroup.
691733
If unspecified, it will be automatically inferred as instance.
@@ -699,7 +741,7 @@ spec:
699741
type: string
700742
type: object
701743
required:
702-
- name
744+
- identifier
703745
- targetGroupProps
704746
type: object
705747
type: array

0 commit comments

Comments
 (0)