Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 55 additions & 9 deletions api/adc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,13 @@ type Timeout struct {

// +k8s:deepcopy-gen=true
type StreamRoute struct {
Description string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Name string `json:"name"`
Plugins Plugins `json:"plugins,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
ServerAddr string `json:"server_addr,omitempty"`
ServerPort *int64 `json:"server_port,omitempty"`
Sni string `json:"sni,omitempty"`
Metadata `json:",inline" yaml:",inline"`

Plugins Plugins `json:"plugins,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
ServerAddr string `json:"server_addr,omitempty"`
ServerPort int32 `json:"server_port,omitempty"`
SNI string `json:"sni,omitempty"`
}

// +k8s:deepcopy-gen=true
Expand Down Expand Up @@ -536,6 +534,24 @@ func ComposeRouteName(namespace, name string, rule string) string {
return buf.String()
}

// ComposeStreamRouteName uses namespace, name and rule name to compose
// the stream_route name.
func ComposeStreamRouteName(namespace, name string, rule string) string {
// FIXME Use sync.Pool to reuse this buffer if the upstream
// name composing code path is hot.
p := make([]byte, 0, len(namespace)+len(name)+len(rule)+6)
buf := bytes.NewBuffer(p)

buf.WriteString(namespace)
buf.WriteByte('_')
buf.WriteString(name)
buf.WriteByte('_')
buf.WriteString(rule)
buf.WriteString("_tcp")

return buf.String()
}

func ComposeServiceNameWithRule(namespace, name string, rule string) string {
// FIXME Use sync.Pool to reuse this buffer if the upstream
// name composing code path is hot.
Expand All @@ -553,6 +569,24 @@ func ComposeServiceNameWithRule(namespace, name string, rule string) string {
return buf.String()
}

func ComposeServiceNameWithStream(namespace, name string, rule string) string {
// FIXME Use sync.Pool to reuse this buffer if the upstream
// name composing code path is hot.
var p []byte
plen := len(namespace) + len(name) + 6

p = make([]byte, 0, plen)
buf := bytes.NewBuffer(p)
buf.WriteString(namespace)
buf.WriteByte('_')
buf.WriteString(name)
buf.WriteByte('_')
buf.WriteString(rule)
buf.WriteString("_stream")

return buf.String()
}

func ComposeConsumerName(namespace, name string) string {
// FIXME Use sync.Pool to reuse this buffer if the upstream
// name composing code path is hot.
Expand Down Expand Up @@ -603,6 +637,18 @@ func NewDefaultRoute() *Route {
}
}

// NewDefaultStreamRoute returns an empty StreamRoute with default values.
func NewDefaultStreamRoute() *StreamRoute {
return &StreamRoute{
Metadata: Metadata{
Desc: "Created by apisix-ingress-controller, DO NOT modify it manually",
Labels: map[string]string{
"managed-by": "apisix-ingress-controller",
},
},
}
}

const (
PluginProxyRewrite string = "proxy-rewrite"
PluginRedirect string = "redirect"
Expand Down
13 changes: 1 addition & 12 deletions api/adc/zz_generated.deepcopy.go

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

15 changes: 11 additions & 4 deletions api/v2/apisixroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type ApisixRouteSpec struct {
HTTP []ApisixRouteHTTP `json:"http,omitempty" yaml:"http,omitempty"`
// Stream defines a list of stream route rules.
// Each rule specifies conditions to match TCP/UDP traffic and how to forward them.
// Stream is currently not supported.
Stream []ApisixRouteStream `json:"stream,omitempty" yaml:"stream,omitempty"`
}

Expand Down Expand Up @@ -111,7 +110,9 @@ type ApisixRouteHTTP struct {
type ApisixRouteStream struct {
// Name is a unique identifier for the route. This field must not be empty.
Name string `json:"name" yaml:"name"`
// Protocol specifies the L4 protocol to match. Can be `tcp` or `udp`.
// Protocol specifies the L4 protocol to match. Can be `TCP` or `UDP`.
//
// +kubebuilder:validation:Enum=TCP;UDP
Protocol string `json:"protocol" yaml:"protocol"`
// Match defines the criteria used to match incoming TCP or UDP connections.
Match ApisixRouteStreamMatch `json:"match" yaml:"match"`
Expand Down Expand Up @@ -226,6 +227,9 @@ type ApisixRouteAuthentication struct {
type ApisixRouteStreamMatch struct {
// IngressPort is the port on which the APISIX Ingress proxy server listens.
// This must be a statically configured port, as APISIX does not support dynamic port binding.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=65535
IngressPort int32 `json:"ingressPort" yaml:"ingressPort"`
// Host is the destination host address used to match the incoming TCP/UDP traffic.
Host string `json:"host,omitempty" yaml:"host,omitempty"`
Expand All @@ -241,9 +245,12 @@ type ApisixRouteStreamBackend struct {
// This can be either the port name or port number.
ServicePort intstr.IntOrString `json:"servicePort" yaml:"servicePort"`
// ResolveGranularity determines how the backend service is resolved.
// Valid values are `endpoints` and `service`. When set to `endpoints`,
// Valid values are `endpoint` and `service`. When set to `endpoint`,
// individual pod IPs will be used; otherwise, the Service's ClusterIP or ExternalIP is used.
// The default is `endpoints`.
// The default is `endpoint`.
//
// +kubebuilder:default=endpoint
// +kubebuilder:validation:Enum=endpoint;service
ResolveGranularity string `json:"resolveGranularity,omitempty" yaml:"resolveGranularity,omitempty"`
// Subset specifies a named subset of the target Service.
// The subset must be pre-defined in the corresponding ApisixUpstream resource.
Expand Down
5 changes: 5 additions & 0 deletions api/v2/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const (
DefaultWeight = 100
)

const (
ResolveGranularityService = "service"
ResolveGranularityEndpoint = "endpoint"
)

const (
// OpEqual means the equal ("==") operator in nginxVars.
OpEqual = "Equal"
Expand Down
16 changes: 12 additions & 4 deletions config/crd/bases/apisix.apache.org_apisixroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ spec:
description: |-
Stream defines a list of stream route rules.
Each rule specifies conditions to match TCP/UDP traffic and how to forward them.
Stream is currently not supported.
items:
description: ApisixRouteStream defines the configuration for a Layer
4 (TCP/UDP) route. Currently not supported.
Expand All @@ -366,11 +365,15 @@ spec:
traffic should be forwarded.
properties:
resolveGranularity:
default: endpoint
description: |-
ResolveGranularity determines how the backend service is resolved.
Valid values are `endpoints` and `service`. When set to `endpoints`,
Valid values are `endpoint` and `service`. When set to `endpoint`,
individual pod IPs will be used; otherwise, the Service's ClusterIP or ExternalIP is used.
The default is `endpoints`.
The default is `endpoint`.
enum:
- endpoint
- service
type: string
serviceName:
description: |-
Expand Down Expand Up @@ -408,6 +411,8 @@ spec:
IngressPort is the port on which the APISIX Ingress proxy server listens.
This must be a statically configured port, as APISIX does not support dynamic port binding.
format: int32
maximum: 65535
minimum: 0
type: integer
required:
- ingressPort
Expand Down Expand Up @@ -443,7 +448,10 @@ spec:
type: array
protocol:
description: Protocol specifies the L4 protocol to match. Can
be `tcp` or `udp`.
be `TCP` or `UDP`.
enum:
- TCP
- UDP
type: string
required:
- backend
Expand Down
6 changes: 3 additions & 3 deletions docs/en/latest/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ It defines routing rules for both HTTP and stream traffic.
| --- | --- |
| `ingressClassName` _string_ | IngressClassName is the name of the IngressClass this route belongs to. It allows multiple controllers to watch and reconcile different routes. |
| `http` _[ApisixRouteHTTP](#apisixroutehttp) array_ | HTTP defines a list of HTTP route rules. Each rule specifies conditions to match HTTP requests and how to forward them. |
| `stream` _[ApisixRouteStream](#apisixroutestream) array_ | Stream defines a list of stream route rules. Each rule specifies conditions to match TCP/UDP traffic and how to forward them. Stream is currently not supported. |
| `stream` _[ApisixRouteStream](#apisixroutestream) array_ | Stream defines a list of stream route rules. Each rule specifies conditions to match TCP/UDP traffic and how to forward them. |


_Appears in:_
Expand All @@ -1194,7 +1194,7 @@ ApisixRouteStream defines the configuration for a Layer 4 (TCP/UDP) route. Curre
| Field | Description |
| --- | --- |
| `name` _string_ | Name is a unique identifier for the route. This field must not be empty. |
| `protocol` _string_ | Protocol specifies the L4 protocol to match. Can be `tcp` or `udp`. |
| `protocol` _string_ | Protocol specifies the L4 protocol to match. Can be `TCP` or `UDP`. |
| `match` _[ApisixRouteStreamMatch](#apisixroutestreammatch)_ | Match defines the criteria used to match incoming TCP or UDP connections. |
| `backend` _[ApisixRouteStreamBackend](#apisixroutestreambackend)_ | Backend specifies the destination service to which traffic should be forwarded. |
| `plugins` _[ApisixRoutePlugin](#apisixrouteplugin) array_ | Plugins defines a list of plugins to apply to this route. |
Expand All @@ -1214,7 +1214,7 @@ ApisixRouteStreamBackend represents the backend service for a TCP or UDP stream
| --- | --- |
| `serviceName` _string_ | ServiceName is the name of the Kubernetes Service. Cross-namespace references are not supported—ensure the ApisixRoute and the Service are in the same namespace. |
| `servicePort` _[IntOrString](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#intorstring-intstr-util)_ | ServicePort is the port of the Kubernetes Service. This can be either the port name or port number. |
| `resolveGranularity` _string_ | ResolveGranularity determines how the backend service is resolved. Valid values are `endpoints` and `service`. When set to `endpoints`, individual pod IPs will be used; otherwise, the Service's ClusterIP or ExternalIP is used. The default is `endpoints`. |
| `resolveGranularity` _string_ | ResolveGranularity determines how the backend service is resolved. Valid values are `endpoint` and `service`. When set to `endpoint`, individual pod IPs will be used; otherwise, the Service's ClusterIP or ExternalIP is used. The default is `endpoint`. |
| `subset` _string_ | Subset specifies a named subset of the target Service. The subset must be pre-defined in the corresponding ApisixUpstream resource. |


Expand Down
Loading
Loading