Skip to content

Commit

Permalink
add CEL test, optionals, list, init and hide from docs
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc committed May 9, 2024
1 parent 5fd28fe commit d9d30f6
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 5 deletions.
32 changes: 32 additions & 0 deletions api/v1alpha1/backend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
)

// +kubebuilder:validation:Enum=FQDN;UDS;IPv4;IPv6
// +notImplementedHide
type AddressType string

const (
Expand All @@ -29,6 +30,7 @@ const (
)

// +kubebuilder:validation:Enum=TCP;UDP
// +notImplementedHide
type ProtocolType string

const (
Expand All @@ -39,6 +41,7 @@ const (
)

// +kubebuilder:validation:Enum=HTTP2;WS
// +notImplementedHide
type ApplicationProtocolType string

const (
Expand All @@ -53,6 +56,7 @@ const (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.conditions[?(@.type=="Accepted")].reason`
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
// +notImplementedHide
//
// Backend allows the user to configure the behavior of the connection
// between the Envoy Proxy listener and the backend service.
Expand All @@ -72,19 +76,26 @@ type Backend struct {
//
// +kubebuilder:validation:XValidation:rule="(has(self.socketAddress) || has(self.unixDomainSocketAddress))",message="one of socketAddress or unixDomainSocketAddress must be specified"
// +kubebuilder:validation:XValidation:rule="(has(self.socketAddress) && !has(self.unixDomainSocketAddress)) || (!has(self.socketAddress) && has(self.unixDomainSocketAddress))",message="only one of socketAddress or unixDomainSocketAddress can be specified"
// +kubebuilder:validation:XValidation:rule="((has(self.socketAddress) && (self.type == 'FQDN' || self.type == 'IPv4' || self.type == 'IPv6')) || has(self.unixDomainSocketAddress) && self.type == 'UDS')",message="if type is FQDN, IPv4 or IPv6, socketAddress must be set; if type is UDS, unixDomainSocketAddress must be set"
// +notImplementedHide
type BackendAddress struct {
// Type is the the type name of the backend address: FQDN, UDS, IPv4, IPv6
Type AddressType `json:"type"`

// SocketAddress defines a FQDN, IPv4 or IPv6 address
//
// +optional
SocketAddress *SocketAddress `json:"socketAddress,omitempty"`

// UnixDomainSocketAddress defines the unix domain socket path
//
// +optional
UnixDomainSocketAddress *UnixDomainSocketAddress `json:"unixDomainSocketAddress,omitempty"`
}

// SocketAddress describes TCP/UDP socket address, corresponding to Envoy's SocketAddress
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#config-core-v3-socketaddress
// +notImplementedHide
type SocketAddress struct {
// Address defines to the FQDN or IP address of the backend service.
Address string `json:"address"`
Expand All @@ -93,26 +104,34 @@ type SocketAddress struct {
Port int32 `json:"port"`

// Protocol defines to the the transport protocol to use for communication with the backend.
//
// +optional
Protocol *ProtocolType `json:"protocol,omitempty"`
}

// UnixDomainSocketAddress describes TCP/UDP unix domain socket address, corresponding to Envoy's Pipe
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/core/v3/address.proto#config-core-v3-pipe
// +notImplementedHide
type UnixDomainSocketAddress struct {
Path string `json:"path"`
}

// BackendSpec describes the desired state of BackendSpec.
// +notImplementedHide
type BackendSpec struct {
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=4
// +kubebuilder:validation:XValidation:rule="self.all(f, f.type == 'FQDN') || !self.exists(f, f.type == 'FQDN')",message="FQDN addresses cannot be mixed with other address types"
BackendAddresses []BackendAddress `json:"addresses,omitempty"`

// ApplicationProtocol defines the application protocol to be used, e.g. HTTP2.
//
// +optional
ApplicationProtocol *ApplicationProtocolType `json:"applicationProtocol,omitempty"`
}

// BackendStatus defines the state of Backend
// +notImplementedHide
type BackendStatus struct {
// Conditions describe the current conditions of the Backend.
//
Expand All @@ -122,3 +141,16 @@ type BackendStatus struct {
// +kubebuilder:validation:MaxItems=8
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +notImplementedHide
// BackendList contains a list of Backend resources.
type BackendList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backend `json:"items"`
}

func init() {
SchemeBuilder.Register(&Backend{}, &BackendList{})
}
32 changes: 32 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,18 @@ spec:
can be specified
rule: (has(self.socketAddress) && !has(self.unixDomainSocketAddress))
|| (!has(self.socketAddress) && has(self.unixDomainSocketAddress))
- message: if type is FQDN, IPv4 or IPv6, socketAddress must be
set; if type is UDS, unixDomainSocketAddress must be set
rule: ((has(self.socketAddress) && (self.type == 'FQDN' || self.type
== 'IPv4' || self.type == 'IPv6')) || has(self.unixDomainSocketAddress)
&& self.type == 'UDS')
maxItems: 4
minItems: 1
type: array
x-kubernetes-validations:
- message: FQDN addresses cannot be mixed with other address types
rule: self.all(f, f.type == 'FQDN') || !self.exists(f, f.type ==
'FQDN')
applicationProtocol:
description: ApplicationProtocol defines the application protocol
to be used, e.g. HTTP2.
Expand Down
28 changes: 23 additions & 5 deletions site/content/en/latest/api/extension_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ API group.

### Resource Types
- [Backend](#backend)
- [BackendList](#backendlist)
- [BackendTrafficPolicy](#backendtrafficpolicy)
- [BackendTrafficPolicyList](#backendtrafficpolicylist)
- [ClientTrafficPolicy](#clienttrafficpolicy)
Expand Down Expand Up @@ -220,7 +221,8 @@ _Appears in:_
Backend allows the user to configure the behavior of the connection
between the Envoy Proxy listener and the backend service.


_Appears in:_
- [BackendList](#backendlist)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
Expand All @@ -243,8 +245,24 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `type` | _[AddressType](#addresstype)_ | true | Type is the the type name of the backend address: FQDN, UDS, IPv4, IPv6 |
| `socketAddress` | _[SocketAddress](#socketaddress)_ | true | SocketAddress defines a FQDN, IPv4 or IPv6 address |
| `unixDomainSocketAddress` | _[UnixDomainSocketAddress](#unixdomainsocketaddress)_ | true | UnixDomainSocketAddress defines the unix domain socket path |
| `socketAddress` | _[SocketAddress](#socketaddress)_ | false | SocketAddress defines a FQDN, IPv4 or IPv6 address |
| `unixDomainSocketAddress` | _[UnixDomainSocketAddress](#unixdomainsocketaddress)_ | false | UnixDomainSocketAddress defines the unix domain socket path |


#### BackendList



BackendList contains a list of Backend resources.



| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `apiVersion` | _string_ | |`gateway.envoyproxy.io/v1alpha1`
| `kind` | _string_ | |`BackendList`
| `metadata` | _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/#listmeta-v1-meta)_ | true | Refer to Kubernetes API documentation for fields of `metadata`. |
| `items` | _[Backend](#backend) array_ | true | |


#### BackendRef
Expand Down Expand Up @@ -281,7 +299,7 @@ _Appears in:_
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `addresses` | _[BackendAddress](#backendaddress) array_ | true | |
| `applicationProtocol` | _[ApplicationProtocolType](#applicationprotocoltype)_ | true | ApplicationProtocol defines the application protocol to be used, e.g. HTTP2. |
| `applicationProtocol` | _[ApplicationProtocolType](#applicationprotocoltype)_ | false | ApplicationProtocol defines the application protocol to be used, e.g. HTTP2. |



Expand Down Expand Up @@ -3106,7 +3124,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `address` | _string_ | true | Address defines to the FQDN or IP address of the backend service. |
| `port` | _integer_ | true | Port defines to the port of of the backend service. |
| `protocol` | _[ProtocolType](#protocoltype)_ | true | Protocol defines to the the transport protocol to use for communication with the backend. |
| `protocol` | _[ProtocolType](#protocoltype)_ | false | Protocol defines to the the transport protocol to use for communication with the backend. |



Expand Down
Loading

0 comments on commit d9d30f6

Please sign in to comment.