Skip to content

Commit 6cb72c2

Browse files
committed
[feat: aga] add AWS Global Accelerator CRD with comprehensive validation
Acknowledge-by: Taylor Smith [taylorsmithgg]
1 parent 066d132 commit 6cb72c2

File tree

10 files changed

+2207
-0
lines changed

10 files changed

+2207
-0
lines changed

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ AWS_SDK_MODEL_OVERRIDE ?= "n"
2121
# Move Gateway API CRDs from bases directory to gateway directory
2222
MOVE_GATEWAY_CRDS = mv config/crd/bases/gateway.k8s.aws_* config/crd/gateway/
2323

24+
# Move AGA CRDs from bases directory to aga directory
25+
MOVE_AGA_CRDS = mkdir -p config/crd/aga && mv config/crd/bases/aga.k8s.aws_* config/crd/aga/
26+
2427
# Copy combined Gateway API CRDs from bases directory to helm directory
2528
COPY_GATEWAY_CRDS_TO_HELM = cp config/crd/gateway/gateway-crds.yaml helm/aws-load-balancer-controller/crds/gateway-crds.yaml
2629

30+
# Copy combined AGA CRDs from aga directory to helm directory
31+
COPY_AGA_CRDS_TO_HELM = cp config/crd/aga/aga-crds.yaml helm/aws-load-balancer-controller/crds/aga-crds.yaml
32+
2733
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2834
ifeq (,$(shell go env GOBIN))
2935
GOBIN=$(shell go env GOPATH)/bin
@@ -68,11 +74,16 @@ manifests: controller-gen kustomize
6874

6975
crds: manifests
7076
$(MOVE_GATEWAY_CRDS)
77+
$(MOVE_AGA_CRDS)
7178
$(KUSTOMIZE) build config/crd > helm/aws-load-balancer-controller/crds/crds.yaml
7279
$(KUSTOMIZE) build config/crd/gateway > config/crd/gateway/gateway-crds.yaml
7380
echo '---' > config/crd/gateway/gateway-crds.yaml
7481
$(KUSTOMIZE) build config/crd/gateway >> config/crd/gateway/gateway-crds.yaml
7582
$(COPY_GATEWAY_CRDS_TO_HELM)
83+
$(KUSTOMIZE) build config/crd/aga > config/crd/aga/aga-crds.yaml
84+
echo '---' > config/crd/aga/aga-crds.yaml
85+
$(KUSTOMIZE) build config/crd/aga >> config/crd/aga/aga-crds.yaml
86+
$(COPY_AGA_CRDS_TO_HELM)
7687

7788
# Run go fmt against code
7889
fmt:
@@ -218,3 +229,12 @@ gw-api-ref-docs:
218229
--config=crd-ref-docs.yaml \
219230
--renderer=markdown \
220231
--output-path=${PWD}/docs/guide/gateway/spec.md
232+
233+
# generate aga CRD spec doc
234+
.PHONY: aga-ref-docs
235+
aga-ref-docs:
236+
crd-ref-docs \
237+
--source-path=${PWD}/apis/aga/ \
238+
--config=crd-ref-docs.yaml \
239+
--renderer=markdown \
240+
--output-path=${PWD}/docs/guide/globalaccelerator/spec.md
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
/*
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// +kubebuilder:validation:Enum=STANDARD
24+
// AcceleratorType is the type of Global Accelerator.
25+
type AcceleratorType string
26+
27+
const (
28+
AcceleratorTypeStandard AcceleratorType = "STANDARD"
29+
)
30+
31+
// +kubebuilder:validation:Enum=TCP;UDP
32+
// GlobalAcceleratorProtocol defines the protocol for Global Accelerator listeners.
33+
type GlobalAcceleratorProtocol string
34+
35+
const (
36+
GlobalAcceleratorProtocolTCP GlobalAcceleratorProtocol = "TCP"
37+
GlobalAcceleratorProtocolUDP GlobalAcceleratorProtocol = "UDP"
38+
)
39+
40+
// +kubebuilder:validation:Enum=SOURCE_IP;NONE
41+
// ClientAffinityType defines the client affinity for Global Accelerator listeners.
42+
type ClientAffinityType string
43+
44+
const (
45+
ClientAffinitySourceIP ClientAffinityType = "SOURCE_IP"
46+
ClientAffinityNone ClientAffinityType = "NONE"
47+
)
48+
49+
// +kubebuilder:validation:Enum=IPV4;DUAL_STACK
50+
// IPAddressType defines the IP address type for Global Accelerator.
51+
type IPAddressType string
52+
53+
const (
54+
IPAddressTypeIPV4 IPAddressType = "IPV4"
55+
IPAddressTypeDualStack IPAddressType = "DUAL_STACK"
56+
)
57+
58+
// PortRange defines the port range for Global Accelerator listeners.
59+
type PortRange struct {
60+
// FromPort is the first port in the range of ports, inclusive.
61+
// +kubebuilder:validation:Minimum=1
62+
// +kubebuilder:validation:Maximum=65535
63+
FromPort int32 `json:"fromPort"`
64+
65+
// ToPort is the last port in the range of ports, inclusive.
66+
// +kubebuilder:validation:Minimum=1
67+
// +kubebuilder:validation:Maximum=65535
68+
ToPort int32 `json:"toPort"`
69+
}
70+
71+
// GlobalAcceleratorListener defines a listener for the Global Accelerator.
72+
type GlobalAcceleratorListener struct {
73+
// Protocol is the protocol for the connections from clients to the accelerator.
74+
// When not specified, the controller will automatically determine the protocol by inspecting
75+
// the referenced Kubernetes resources (Service, Ingress, or Gateway) in the endpoint groups.
76+
// +optional
77+
Protocol *GlobalAcceleratorProtocol `json:"protocol,omitempty"`
78+
79+
// PortRanges is the list of port ranges for the connections from clients to the accelerator.
80+
// When not specified, the controller will automatically determine the port ranges by inspecting
81+
// the referenced Kubernetes resources (Service, Ingress, or Gateway) in the endpoint groups.
82+
// +kubebuilder:validation:MinItems=1
83+
// +kubebuilder:validation:MaxItems=10
84+
// +optional
85+
PortRanges []PortRange `json:"portRanges,omitempty"`
86+
87+
// ClientAffinity lets you direct all requests from a user to the same endpoint, if you have stateful applications, regardless of the port and protocol of the client request.
88+
// Client affinity gives you control over whether to always route each client to the same specific endpoint.
89+
// AWS Global Accelerator uses a consistent-flow hashing algorithm to choose the optimal endpoint for a connection.
90+
// If client affinity is NONE, Global Accelerator uses the "five-tuple" (5-tuple) properties—source IP address, source port, destination IP address, destination port, and protocol—to select the hash value, and then chooses the best endpoint.
91+
// However, with this setting, if someone uses different ports to connect to Global Accelerator, their connections might not be always routed to the same endpoint because the hash value changes.
92+
// If you want a given client to always be routed to the same endpoint, set client affinity to SOURCE_IP instead.
93+
// When you use the SOURCE_IP setting, Global Accelerator uses the "two-tuple" (2-tuple) properties— source (client) IP address and destination IP address—to select the hash value.
94+
// The default value is NONE.
95+
// +kubebuilder:default="NONE"
96+
// +optional
97+
ClientAffinity ClientAffinityType `json:"clientAffinity,omitempty"`
98+
99+
// EndpointGroups defines a list of endpoint groups for a Global Accelerator listener.
100+
// +optional
101+
EndpointGroups []GlobalAcceleratorEndpointGroup `json:"endpointGroups,omitempty"`
102+
}
103+
104+
// +kubebuilder:validation:Enum=HTTP;HTTPS;TCP
105+
// EndpointGroupHealthCheckProtocol defines the protocol for Global Accelerator endpoint group health checks.
106+
type EndpointGroupHealthCheckProtocol string
107+
108+
const (
109+
EndpointGroupHealthCheckProtocolHTTP EndpointGroupHealthCheckProtocol = "HTTP"
110+
EndpointGroupHealthCheckProtocolHTTPS EndpointGroupHealthCheckProtocol = "HTTPS"
111+
EndpointGroupHealthCheckProtocolTCP EndpointGroupHealthCheckProtocol = "TCP"
112+
)
113+
114+
// GlobalAcceleratorEndpointGroup defines an endpoint group for a Global Accelerator listener.
115+
type GlobalAcceleratorEndpointGroup struct {
116+
// Region is the AWS Region where the endpoint group is located.
117+
// +kubebuilder:validation:MaxLength=255
118+
Region string `json:"region"`
119+
120+
// TrafficDialPercentage is the percentage of traffic to send to an AWS Regions. Additional traffic is distributed to other endpoint groups for this listener
121+
// Use this action to increase (dial up) or decrease (dial down) traffic to a specific Region. The percentage is applied to the traffic that would otherwise have been routed to the Region based on optimal routing.
122+
// +kubebuilder:validation:Minimum=0
123+
// +kubebuilder:validation:Maximum=100
124+
// +kubebuilder:default=100
125+
// +optional
126+
TrafficDialPercentage *int32 `json:"trafficDialPercentage,omitempty"`
127+
128+
// PortOverrides is a list of endpoint port overrides. Allows you to override the destination ports used to route traffic to an endpoint. Using a port override lets you map a list of external destination ports (that your users send traffic to) to a list of internal destination ports that you want an application endpoint to receive traffic on.
129+
// +optional
130+
PortOverrides []PortOverride `json:"portOverrides,omitempty"`
131+
132+
// Endpoints is the list of endpoint configurations for this endpoint group.
133+
// +kubebuilder:validation:MaxItems=10
134+
// +optional
135+
Endpoints []GlobalAcceleratorEndpoint `json:"endpoints,omitempty"`
136+
}
137+
138+
// PortOverride defines a port override for an endpoint group.
139+
// Override specific listener ports used to route traffic to endpoints that are part of an endpoint group.
140+
// For example, you can create a port override in which the listener receives user traffic on ports 80 and 443,
141+
// but your accelerator routes that traffic to ports 1080 and 1443, respectively, on the endpoints.
142+
//
143+
// For more information, see Port overrides in the AWS Global Accelerator Developer Guide:
144+
// https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoint-groups-port-override.html
145+
type PortOverride struct {
146+
// ListenerPort is the listener port that you want to map to a specific endpoint port.
147+
// This is the port that user traffic arrives to the Global Accelerator on.
148+
// +kubebuilder:validation:Minimum=1
149+
// +kubebuilder:validation:Maximum=65535
150+
ListenerPort int32 `json:"listenerPort"`
151+
152+
// EndpointPort is the endpoint port that you want traffic to be routed to.
153+
// This is the port on the endpoint, such as the Application Load Balancer or Amazon EC2 instance.
154+
// +kubebuilder:validation:Minimum=1
155+
// +kubebuilder:validation:Maximum=65535
156+
EndpointPort int32 `json:"endpointPort"`
157+
}
158+
159+
// +kubebuilder:validation:Enum=EndpointID;Service;Ingress;Gateway
160+
// GlobalAcceleratorEndpointType defines the type of endpoint for Global Accelerator.
161+
type GlobalAcceleratorEndpointType string
162+
163+
const (
164+
GlobalAcceleratorEndpointTypeEndpointID GlobalAcceleratorEndpointType = "EndpointID"
165+
GlobalAcceleratorEndpointTypeService GlobalAcceleratorEndpointType = "Service"
166+
GlobalAcceleratorEndpointTypeIngress GlobalAcceleratorEndpointType = "Ingress"
167+
GlobalAcceleratorEndpointTypeGateway GlobalAcceleratorEndpointType = "Gateway"
168+
)
169+
170+
// GlobalAcceleratorEndpoint defines an endpoint for a Global Accelerator endpoint group.
171+
// +kubebuilder:validation:XValidation:rule="self.type != 'EndpointID' || (has(self.endpointID) && !has(self.name))",message="endpointID is required and name must not be set when type is EndpointID"
172+
// +kubebuilder:validation:XValidation:rule="self.type == 'EndpointID' || (has(self.name) && !has(self.endpointID))",message="name is required and endpointID must not be set when type is Service/Ingress/Gateway"
173+
type GlobalAcceleratorEndpoint struct {
174+
// Type specifies the type of endpoint reference.
175+
Type GlobalAcceleratorEndpointType `json:"type"`
176+
177+
// EndpointID is the ID of the endpoint when type is EndpointID.
178+
// If the endpoint is a Network Load Balancer or Application Load Balancer, this is the Amazon Resource Name (ARN) of the resource.
179+
// A resource must be valid and active when you add it as an endpoint.
180+
// Mandatory for remote regions.
181+
// +kubebuilder:validation:MaxLength=255
182+
// +optional
183+
EndpointID *string `json:"endpointID,omitempty"`
184+
185+
// Name is the name of the Kubernetes resource when type is Service, Ingress, or Gateway.
186+
// +optional
187+
Name *string `json:"name,omitempty"`
188+
189+
// Namespace is the namespace of the Kubernetes resource when type is Service, Ingress, or Gateway.
190+
// If not specified, defaults to the same namespace as the GlobalAccelerator resource.
191+
// +optional
192+
Namespace *string `json:"namespace,omitempty"`
193+
194+
// Weight is the weight associated with the endpoint. When you add weights to endpoints, you configure Global Accelerator to route traffic based on proportions that you specify.
195+
// For example, you might specify endpoint weights of 4, 5, 5, and 6 (sum=20). The result is that 4/20 of your traffic, on average, is routed to the first endpoint,
196+
// 5/20 is routed both to the second and third endpoints, and 6/20 is routed to the last endpoint.
197+
// For more information, see Endpoint Weights in the AWS Global Accelerator Developer Guide:
198+
// https://docs.aws.amazon.com/global-accelerator/latest/dg/about-endpoints-endpoint-weights.html
199+
// +kubebuilder:validation:Minimum=0
200+
// +kubebuilder:validation:Maximum=255
201+
// +kubebuilder:default=128
202+
// +optional
203+
Weight *int32 `json:"weight,omitempty"`
204+
205+
// ClientIPPreservationEnabled indicates whether client IP address preservation is enabled for an Application Load Balancer endpoint.
206+
// The value is true or false. The default value is true for new accelerators.
207+
// If the value is set to true, the client's IP address is preserved in the X-Forwarded-For request header as traffic travels to applications on the Application Load Balancer endpoint fronted by the accelerator.
208+
// For more information, see Preserve Client IP Addresses in the AWS Global Accelerator Developer Guide:
209+
// https://docs.aws.amazon.com/global-accelerator/latest/dg/preserve-client-ip-address.html
210+
// +kubebuilder:default=true
211+
// +optional
212+
ClientIPPreservationEnabled *bool `json:"clientIPPreservationEnabled,omitempty"`
213+
}
214+
215+
// GlobalAcceleratorSpec defines the desired state of GlobalAccelerator
216+
type GlobalAcceleratorSpec struct {
217+
// Name is the name of the Global Accelerator.
218+
// The name must contain only alphanumeric characters or hyphens (-), and must not begin or end with a hyphen.
219+
// +kubebuilder:validation:Pattern="^[a-zA-Z0-9_-]{1,64}$"
220+
// +kubebuilder:validation:MinLength=1
221+
// +kubebuilder:validation:MaxLength=64
222+
// +optional
223+
Name *string `json:"name,omitempty"`
224+
225+
// Type is the type of accelerator.
226+
// +kubebuilder:default="STANDARD"
227+
// +optional
228+
Type AcceleratorType `json:"type,omitempty"`
229+
230+
// IPAddressType is the value for the address type.
231+
// +kubebuilder:default="IPV4"
232+
// +optional
233+
IPAddressType IPAddressType `json:"ipAddressType,omitempty"`
234+
235+
// Tags defines list of Tags on the Global Accelerator.
236+
// +optional
237+
Tags *map[string]string `json:"tags,omitempty"`
238+
239+
// Listeners defines the listeners for the Global Accelerator.
240+
// +optional
241+
Listeners []GlobalAcceleratorListener `json:"listeners,omitempty"`
242+
}
243+
244+
// GlobalAcceleratorStatus defines the observed state of GlobalAccelerator
245+
type GlobalAcceleratorStatus struct {
246+
// The generation observed by the GlobalAccelerator controller.
247+
// +optional
248+
ObservedGeneration *int64 `json:"observedGeneration,omitempty"`
249+
250+
// AcceleratorARN is the Amazon Resource Name (ARN) of the accelerator.
251+
// +optional
252+
AcceleratorARN *string `json:"acceleratorARN,omitempty"`
253+
254+
// DNSName is the Domain Name System (DNS) name that Global Accelerator creates that points to your accelerator's static IP addresses.
255+
// +optional
256+
DNSName *string `json:"dnsName,omitempty"`
257+
258+
// IPSets is information about the IP address type.
259+
// +optional
260+
IPSets []IPSet `json:"ipSets,omitempty"`
261+
262+
// Status is the current status of the accelerator.
263+
// +optional
264+
Status *string `json:"status,omitempty"`
265+
266+
// Conditions represent the current conditions of the GlobalAccelerator.
267+
// +optional
268+
Conditions []metav1.Condition `json:"conditions,omitempty"`
269+
}
270+
271+
// IPSet contains information about the IP address type.
272+
type IPSet struct {
273+
// IpFamily is the IP address version.
274+
// +optional
275+
IpFamily *string `json:"ipFamily,omitempty"`
276+
277+
// IpAddresses is the array of IP addresses in the IP address set.
278+
// +optional
279+
IpAddresses []string `json:"ipAddresses,omitempty"`
280+
281+
// IpAddressFamily is the types of IP addresses included in this IP set.
282+
// +optional
283+
IpAddressFamily *string `json:"ipAddressFamily,omitempty"`
284+
}
285+
286+
// +kubebuilder:object:root=true
287+
// +kubebuilder:subresource:status
288+
// +kubebuilder:storageversion
289+
// +kubebuilder:printcolumn:name="NAME",type="string",JSONPath=".spec.name",description="The Global Accelerator name"
290+
// +kubebuilder:printcolumn:name="DNS-NAME",type="string",JSONPath=".status.dnsName",description="The Global Accelerator DNS name"
291+
// +kubebuilder:printcolumn:name="TYPE",type="string",JSONPath=".spec.type",description="The Global Accelerator type"
292+
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.status",description="The Global Accelerator status"
293+
// +kubebuilder:printcolumn:name="ARN",type="string",JSONPath=".status.acceleratorARN",description="The Global Accelerator ARN",priority=1
294+
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
295+
// GlobalAccelerator is the Schema for the GlobalAccelerator API
296+
type GlobalAccelerator struct {
297+
metav1.TypeMeta `json:",inline"`
298+
metav1.ObjectMeta `json:"metadata,omitempty"`
299+
300+
Spec GlobalAcceleratorSpec `json:"spec,omitempty"`
301+
Status GlobalAcceleratorStatus `json:"status,omitempty"`
302+
}
303+
304+
// +kubebuilder:object:root=true
305+
// GlobalAcceleratorList contains a list of GlobalAccelerator
306+
type GlobalAcceleratorList struct {
307+
metav1.TypeMeta `json:",inline"`
308+
metav1.ListMeta `json:"metadata,omitempty"`
309+
Items []GlobalAccelerator `json:"items"`
310+
}
311+
312+
func init() {
313+
SchemeBuilder.Register(&GlobalAccelerator{}, &GlobalAcceleratorList{})
314+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the aga v1beta1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=aga.k8s.aws
20+
package v1beta1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "aga.k8s.aws", Version: "v1beta1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)