From 50a44ae6b5e421f3a007fbda51bd35c3364ee566 Mon Sep 17 00:00:00 2001 From: Shane Utt Date: Mon, 3 Jan 2022 15:13:44 -0500 Subject: [PATCH] fix: distinct address types for Gateways Re-using the Gateway AddressType ended up having problems because it would add extraneous CRD fields, so this patch creates a new type specifically for this purpose with single-purpose validation options. --- apis/v1alpha2/gateway_types.go | 14 ++++++----- apis/v1alpha2/shared_types.go | 8 +++++-- apis/v1alpha2/zz_generated.deepcopy.go | 2 +- .../gateway.networking.k8s.io_tcproutes.yaml | 24 +++++-------------- .../gateway.networking.k8s.io_udproutes.yaml | 24 +++++-------------- .../gateway.networking.k8s.io_tcproutes.yaml | 24 +++++-------------- .../gateway.networking.k8s.io_udproutes.yaml | 24 +++++-------------- 7 files changed, 39 insertions(+), 81 deletions(-) diff --git a/apis/v1alpha2/gateway_types.go b/apis/v1alpha2/gateway_types.go index 52443d1175..398b122d84 100644 --- a/apis/v1alpha2/gateway_types.go +++ b/apis/v1alpha2/gateway_types.go @@ -450,7 +450,7 @@ type GatewayAddress struct { // // +optional // +kubebuilder:default=IPAddress - Type *AddressType `json:"type,omitempty"` + Type *GatewayAddressType `json:"type,omitempty"` // Value of the address. The validity of the values will depend // on the type and support by the controller. @@ -462,14 +462,16 @@ type GatewayAddress struct { Value string `json:"value"` } -// AddressType defines how a network address is represented as a text string. +// GatewayAddressType defines how a network address is represented as a text +// string, specifically in the context of listener addresses for Gateways and +// includes options over the base AddressType type such as Hostname. // // If the requested address is unsupported, the controller // should raise the "Detached" listener status condition on // the Gateway with the "UnsupportedAddress" reason. // // +kubebuilder:validation:Enum=IPAddress;Hostname;NamedAddress -type AddressType string +type GatewayAddressType string const ( // A textual representation of a numeric IP address. IPv4 @@ -482,7 +484,7 @@ const ( // IPAddress). // // Support: Extended - IPAddressType AddressType = "IPAddress" + IPAddressType GatewayAddressType = "IPAddress" // A Hostname represents a DNS based ingress point. This is similar to the // corresponding hostname field in Kubernetes load balancer status. For @@ -490,14 +492,14 @@ const ( // name is used to expose a load balancer. // // Support: Extended - HostnameAddressType AddressType = "Hostname" + HostnameAddressType GatewayAddressType = "Hostname" // A NamedAddress provides a way to reference a specific IP address by name. // For example, this may be a name or other unique identifier that refers // to a resource on a cloud provider such as a static IP. // // Support: Implementation-Specific - NamedAddressType AddressType = "NamedAddress" + NamedAddressType GatewayAddressType = "NamedAddress" ) // GatewayStatus defines the observed state of Gateway. diff --git a/apis/v1alpha2/shared_types.go b/apis/v1alpha2/shared_types.go index 1917aaefaa..5bc7e5a439 100644 --- a/apis/v1alpha2/shared_types.go +++ b/apis/v1alpha2/shared_types.go @@ -414,8 +414,6 @@ type AddressMatch struct { // Support: Custom (NamedAddress) // // +optional - // +kubebuilder:validation:Enum=IPAddress;NamedAddress - // +kubebuilder:default=IPAddress Type *AddressType `json:"type,omitempty"` // Value of the address. The validity of the values will depend @@ -434,3 +432,9 @@ type AddressMatch struct { // +kubebuilder:validation:MaxLength=253 Value string `json:"value"` } + +// AddressType defines how a network address is represented as a text string. +// +// +kubebuilder:validation:Enum=IPAddress;NamedAddress +// +kubebuilder:default=IPAddress +type AddressType string diff --git a/apis/v1alpha2/zz_generated.deepcopy.go b/apis/v1alpha2/zz_generated.deepcopy.go index 6f4fe7f5d0..2ce87444b2 100644 --- a/apis/v1alpha2/zz_generated.deepcopy.go +++ b/apis/v1alpha2/zz_generated.deepcopy.go @@ -183,7 +183,7 @@ func (in *GatewayAddress) DeepCopyInto(out *GatewayAddress) { *out = *in if in.Type != nil { in, out := &in.Type, &out.Type - *out = new(AddressType) + *out = new(GatewayAddressType) **out = **in } } diff --git a/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml index 22a404df56..2bc5a84f3f 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_tcproutes.yaml @@ -231,15 +231,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -247,6 +238,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of @@ -273,15 +267,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -289,6 +274,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of diff --git a/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml index b4543673b0..0002ffb062 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_udproutes.yaml @@ -231,15 +231,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -247,6 +238,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of @@ -273,15 +267,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -289,6 +274,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of diff --git a/config/crd/stable/gateway.networking.k8s.io_tcproutes.yaml b/config/crd/stable/gateway.networking.k8s.io_tcproutes.yaml index 003d3d69ba..6f743aea57 100644 --- a/config/crd/stable/gateway.networking.k8s.io_tcproutes.yaml +++ b/config/crd/stable/gateway.networking.k8s.io_tcproutes.yaml @@ -231,15 +231,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -247,6 +238,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of @@ -273,15 +267,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -289,6 +274,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of diff --git a/config/crd/stable/gateway.networking.k8s.io_udproutes.yaml b/config/crd/stable/gateway.networking.k8s.io_udproutes.yaml index a697577c53..814e3cbed0 100644 --- a/config/crd/stable/gateway.networking.k8s.io_udproutes.yaml +++ b/config/crd/stable/gateway.networking.k8s.io_udproutes.yaml @@ -231,15 +231,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -247,6 +238,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of @@ -273,15 +267,6 @@ spec: addresses by type. properties: type: - allOf: - - enum: - - IPAddress - - Hostname - - NamedAddress - - enum: - - IPAddress - - NamedAddress - default: IPAddress description: "Type of the address, either IPAddress or NamedAddress. \n If NamedAddress is used this is a custom and specific value for each implementation @@ -289,6 +274,9 @@ spec: their own needs. \n For IPAddress the implementor may expect either IPv4 or IPv6. \n Support: Core (IPAddress) Support: Custom (NamedAddress)" + enum: + - IPAddress + - NamedAddress type: string value: description: "Value of the address. The validity of