|
| 1 | +package v1beta1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | +) |
| 6 | + |
| 7 | +/* |
| 8 | +
|
| 9 | +
|
| 10 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +you may not use this file except in compliance with the License. |
| 12 | +You may obtain a copy of the License at |
| 13 | +
|
| 14 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +
|
| 16 | +Unless required by applicable law or agreed to in writing, software |
| 17 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +See the License for the specific language governing permissions and |
| 20 | +limitations under the License. |
| 21 | +*/ |
| 22 | + |
| 23 | +// Reference defines how to look up the Target Group configuration for a service. |
| 24 | +type Reference struct { |
| 25 | + // Group is the group of the referent. For example, "gateway.networking.k8s.io". |
| 26 | + // When unspecified or empty string, core API group is inferred. |
| 27 | + // |
| 28 | + // +optional |
| 29 | + // +kubebuilder:default="" |
| 30 | + Group *string `json:"group,omitempty"` |
| 31 | + |
| 32 | + // Kind is the Kubernetes resource kind of the referent. For example |
| 33 | + // "Service". |
| 34 | + // |
| 35 | + // Defaults to "Service" when not specified. |
| 36 | + // |
| 37 | + // ExternalName services can refer to CNAME DNS records that may live |
| 38 | + // outside of the cluster and as such are difficult to reason about in |
| 39 | + // terms of conformance. They also may not be safe to forward to (see |
| 40 | + // CVE-2021-25740 for more information). Implementations SHOULD NOT |
| 41 | + // support ExternalName Services. |
| 42 | + // |
| 43 | + // Support: Core (Services with a type other than ExternalName) |
| 44 | + // |
| 45 | + // Support: Implementation-specific (Services with type ExternalName) |
| 46 | + // |
| 47 | + // +optional |
| 48 | + // +kubebuilder:default=Service |
| 49 | + Kind *string `json:"kind,omitempty"` |
| 50 | + |
| 51 | + // Name is the name of the referent. |
| 52 | + Name string `json:"name"` |
| 53 | +} |
| 54 | + |
| 55 | +// TODO: Add a validation in the admission webhook to check if only one of HTTPCode or GRPCCode is set. |
| 56 | +// Information to use when checking for a successful response from a target. |
| 57 | +type HealthCheckMatcher struct { |
| 58 | + // The HTTP codes. |
| 59 | + HTTPCode *string `json:"httpCode,omitempty"` |
| 60 | + |
| 61 | + // The gRPC codes |
| 62 | + GRPCCode *string `json:"grpcCode,omitempty"` |
| 63 | +} |
| 64 | + |
| 65 | +// HealthCheckConfiguration defines the Health Check configuration for a Target Group. |
| 66 | +type HealthCheckConfiguration struct { |
| 67 | + // healthyThresholdCount The number of consecutive health checks successes required before considering an unhealthy target healthy. |
| 68 | + // +optional |
| 69 | + HealthyThresholdCount *int32 `json:"healthyThresholdCount,omitempty"` |
| 70 | + |
| 71 | + // healthCheckInterval The approximate amount of time, in seconds, between health checks of an individual target. |
| 72 | + // +optional |
| 73 | + HealthCheckInterval *int32 `json:"healthCheckInterval,omitempty"` |
| 74 | + |
| 75 | + // healthCheckPath The destination for health checks on the targets. |
| 76 | + // +optional |
| 77 | + HealthCheckPath *string `json:"healthCheckPath,omitempty"` |
| 78 | + |
| 79 | + // healthCheckPort The port to use to connect with the target. |
| 80 | + // +optional |
| 81 | + HealthCheckPort *int32 `json:"healthCheckPort,omitempty"` |
| 82 | + |
| 83 | + // healthCheckProtocol The protocol to use to connect with the target. The GENEVE, TLS, UDP, and TCP_UDP protocols are not supported for health checks. |
| 84 | + // +optional |
| 85 | + HealthCheckProtocol *TargetGroupHealthCheckProtocol `json:"healthCheckProtocol,omitempty"` |
| 86 | + |
| 87 | + // healthCheckTimeout The amount of time, in seconds, during which no response means a failed health check |
| 88 | + // +optional |
| 89 | + HealthCheckTimeout *int32 `json:"healthCheckTimeout,omitempty"` |
| 90 | + |
| 91 | + // unhealthyThresholdCount The number of consecutive health check failures required before considering the target unhealthy. |
| 92 | + // +optional |
| 93 | + UnhealthyThresholdCount *int32 `json:"unhealthyThresholdCount,omitempty"` |
| 94 | + |
| 95 | + // healthCheckCodes The HTTP or gRPC codes to use when checking for a successful response from a target |
| 96 | + // +optional |
| 97 | + Matcher *HealthCheckMatcher `json:"matcher,omitempty"` |
| 98 | +} |
| 99 | + |
| 100 | +// +kubebuilder:validation:Enum=ipv4;ipv6 |
| 101 | +// TargetGroupIPAddressType is the IP Address type of your ELBV2 TargetGroup. |
| 102 | +type TargetGroupIPAddressType string |
| 103 | + |
| 104 | +const ( |
| 105 | + TargetGroupIPAddressTypeIPv4 TargetGroupIPAddressType = "ipv4" |
| 106 | + TargetGroupIPAddressTypeIPv6 TargetGroupIPAddressType = "ipv6" |
| 107 | +) |
| 108 | + |
| 109 | +// +kubebuilder:validation:Enum=instance;ip |
| 110 | +// TargetType is the targetType of your ELBV2 TargetGroup. |
| 111 | +// |
| 112 | +// * with `instance` TargetType, nodes with nodePort for your service will be registered as targets |
| 113 | +// * with `ip` TargetType, Pods with containerPort for your service will be registered as targets |
| 114 | +type TargetType string |
| 115 | + |
| 116 | +const ( |
| 117 | + TargetTypeInstance TargetType = "instance" |
| 118 | + TargetTypeIP TargetType = "ip" |
| 119 | +) |
| 120 | + |
| 121 | +// +kubebuilder:validation:Enum=http;https;tcp |
| 122 | +type TargetGroupHealthCheckProtocol string |
| 123 | + |
| 124 | +const ( |
| 125 | + TargetGroupHealthCheckProtocolHTTP TargetGroupHealthCheckProtocol = "http" |
| 126 | + TargetGroupHealthCheckProtocolHTTPS TargetGroupHealthCheckProtocol = "https" |
| 127 | + TargetGroupHealthCheckProtocolTCP TargetGroupHealthCheckProtocol = "tcp" |
| 128 | +) |
| 129 | + |
| 130 | +// +kubebuilder:validation:Enum=http1;http2;grpc |
| 131 | +type ProtocolVersion string |
| 132 | + |
| 133 | +const ( |
| 134 | + ProtocolVersionHTTP1 ProtocolVersion = "http1" |
| 135 | + ProtocolVersionHTTP2 ProtocolVersion = "http2" |
| 136 | + ProtocolVersionGRPC ProtocolVersion = "grpc" |
| 137 | +) |
| 138 | + |
| 139 | +// TargetGroupConfigurationSpec defines the TargetGroup properties for a route. |
| 140 | +type TargetGroupConfigurationSpec struct { |
| 141 | + |
| 142 | + // targetReference the kubernetes object to attach the Target Group settings to. |
| 143 | + TargetReference Reference `json:"targetReference"` |
| 144 | + |
| 145 | + // routeConfigurations the route configuration for specific routes |
| 146 | + // +optional |
| 147 | + RouteConfigurations []RouteConfiguration `json:"routeConfigurations,omitempty"` |
| 148 | +} |
| 149 | + |
| 150 | +// +kubebuilder:validation:Pattern="^(HTTPRoute|TLSRoute|TCPRoute|UDPRoute|GRPCRoute)?:([^:]+)?:([^:]+)?$" |
| 151 | +type RouteName string |
| 152 | + |
| 153 | +// RouteConfiguration defines the per route configuration |
| 154 | +type RouteConfiguration struct { |
| 155 | + // name the name of the route, it should be in the form of ROUTE:NAME:NAMESPACE |
| 156 | + Name RouteName `json:"name"` |
| 157 | + |
| 158 | + // targetGroupProps the target group specific properties |
| 159 | + TargetGroupProps TargetGroupProps `json:"targetGroupProps"` |
| 160 | +} |
| 161 | + |
| 162 | +// TargetGroupProps defines the target group properties |
| 163 | +type TargetGroupProps struct { |
| 164 | + // ipAddressType specifies whether the target group is of type IPv4 or IPv6. If unspecified, it will be automatically inferred. |
| 165 | + // +optional |
| 166 | + IPAddressType *TargetGroupIPAddressType `json:"ipAddressType,omitempty"` |
| 167 | + |
| 168 | + // healthCheckConfig The Health Check configuration for this backend. |
| 169 | + // +optional |
| 170 | + HealthCheckConfig *HealthCheckConfiguration `json:"healthCheckConfig,omitempty"` |
| 171 | + |
| 172 | + // node selector for instance type target groups to only register certain nodes |
| 173 | + // +optional |
| 174 | + NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"` |
| 175 | + |
| 176 | + // targetGroupAttributes defines the attribute of target group |
| 177 | + // +optional |
| 178 | + TargetGroupAttributes []TargetGroupAttribute `json:"targetGroupAttributes,omitempty"` |
| 179 | + |
| 180 | + // targetType is the TargetType of TargetGroup. If unspecified, it will be automatically inferred as instance. |
| 181 | + // +optional |
| 182 | + TargetType *TargetType `json:"targetType,omitempty"` |
| 183 | + |
| 184 | + // protocolVersion [HTTP/HTTPS protocol] The protocol version. The possible values are GRPC , HTTP1 and HTTP2 |
| 185 | + // +optional |
| 186 | + ProtocolVersion *ProtocolVersion `json:"protocolVersion,omitempty"` |
| 187 | + |
| 188 | + // vpcID is the VPC of the TargetGroup. If unspecified, it will be automatically inferred. |
| 189 | + // +optional |
| 190 | + VpcID *string `json:"vpcID,omitempty"` |
| 191 | + |
| 192 | + // Tags defines list of Tags on target group. |
| 193 | + // +optional |
| 194 | + Tags []Tag `json:"tags,omitempty"` |
| 195 | +} |
| 196 | + |
| 197 | +// TargetGroupAttribute defines target group attribute. |
| 198 | +type TargetGroupAttribute struct { |
| 199 | + // The key of the attribute. |
| 200 | + Key string `json:"key"` |
| 201 | + |
| 202 | + // The value of the attribute. |
| 203 | + Value string `json:"value"` |
| 204 | +} |
| 205 | + |
| 206 | +// Tag defines a AWS Tag on resources. |
| 207 | +type Tag struct { |
| 208 | + // The key of the tag. |
| 209 | + Key string `json:"key"` |
| 210 | + |
| 211 | + // The value of the tag. |
| 212 | + Value string `json:"value"` |
| 213 | +} |
| 214 | + |
| 215 | +// TODO -- these can be used to set what generation the gateway is currently on to track progress on reconcile. |
| 216 | + |
| 217 | +// TargetGroupConfigurationStatus defines the observed state of TargetGroupConfiguration |
| 218 | +type TargetGroupConfigurationStatus struct { |
| 219 | + // The generation of the Gateway Configuration attached to the Gateway object. |
| 220 | + // +optional |
| 221 | + ObservedGatewayConfigurationGeneration *int64 `json:"observedGatewayConfigurationGeneration,omitempty"` |
| 222 | + // The generation of the Gateway Configuration attached to the GatewayClass object. |
| 223 | + // +optional |
| 224 | + ObservedGatewayClassConfigurationGeneration *int64 `json:"observedGatewayClassConfigurationGeneration,omitempty"` |
| 225 | +} |
| 226 | + |
| 227 | +// +kubebuilder:object:root=true |
| 228 | +// +kubebuilder:subresource:status |
| 229 | +// +kubebuilder:storageversion |
| 230 | +// +kubebuilder:printcolumn:name="SERVICE-NAME",type="string",JSONPath=".spec.targetReference.name",description="The Kubernetes Service's name" |
| 231 | +// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp" |
| 232 | +// TargetGroupConfiguration is the Schema for defining TargetGroups with an AWS ELB Gateway |
| 233 | +type TargetGroupConfiguration struct { |
| 234 | + metav1.TypeMeta `json:",inline"` |
| 235 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 236 | + |
| 237 | + Spec TargetGroupConfigurationSpec `json:"spec,omitempty"` |
| 238 | + Status TargetGroupConfigurationStatus `json:"status,omitempty"` |
| 239 | +} |
| 240 | + |
| 241 | +// +kubebuilder:object:root=true |
| 242 | + |
| 243 | +// TargetGroupConfigurationList contains a list of TargetGroupConfiguration |
| 244 | +type TargetGroupConfigurationList struct { |
| 245 | + metav1.TypeMeta `json:",inline"` |
| 246 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 247 | + Items []TargetGroupConfiguration `json:"items"` |
| 248 | +} |
| 249 | + |
| 250 | +func init() { |
| 251 | + SchemeBuilder.Register(&TargetGroupConfiguration{}, &TargetGroupConfigurationList{}) |
| 252 | +} |
0 commit comments