Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions apis/v1alpha1/upstreamsettingspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ type UpstreamSettingsPolicySpec struct {
// +optional
KeepAlive *UpstreamKeepAlive `json:"keepAlive,omitempty"`

// LoadBalancingMethod specifies the load balancing algorithm to be used for the upstream.
// If not specified, NGINX Gateway Fabric defaults to `random two least_conn`,
// which differs from the standard NGINX default `round-robin`.
//
// +optional
LoadBalancingMethod *LoadBalancingType `json:"loadBalancingMethod,omitempty"`

// TargetRefs identifies API object(s) to apply the policy to.
// Objects must be in the same namespace as the policy.
// Support: Service
Expand Down Expand Up @@ -98,3 +105,22 @@ type UpstreamKeepAlive struct {
// +optional
Timeout *Duration `json:"timeout,omitempty"`
}

// LoadBalancingType defines the supported load balancing methods.
//
// +kubebuilder:validation:Enum=ip_hash;random two least_conn
type LoadBalancingType string

const (
// LoadBalancingTypeIPHash enables IP hash-based load balancing,
// ensuring requests from the same client IP are routed to the same upstream server.
// NGINX directive: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#ip_hash
LoadBalancingTypeIPHash LoadBalancingType = "ip_hash"

// LoadBalancingTypeRandomTwoLeastConnection enables a variation of least-connections
// balancing that randomly selects two servers and forwards traffic to the one with
// fewer active connections.
// NGINX directive least_conn: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#least_conn
// NGINX directive random: https://nginx.org/en/docs/http/ngx_http_upstream_module.html#random
LoadBalancingTypeRandomTwoLeastConnection LoadBalancingType = "random two least_conn"
)
5 changes: 5 additions & 0 deletions apis/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 @@ -85,6 +85,15 @@ spec:
pattern: ^[0-9]{1,4}(ms|s|m|h)?$
type: string
type: object
loadBalancingMethod:
description: |-
LoadBalancingMethod specifies the load balancing algorithm to be used for the upstream.
If not specified, NGINX Gateway Fabric defaults to `random two least_conn`,
which differs from the standard NGINX default `round-robin`.
enum:
- ip_hash
- random two least_conn
type: string
targetRefs:
description: |-
TargetRefs identifies API object(s) to apply the policy to.
Expand Down
9 changes: 9 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9612,6 +9612,15 @@ spec:
pattern: ^[0-9]{1,4}(ms|s|m|h)?$
type: string
type: object
loadBalancingMethod:
description: |-
LoadBalancingMethod specifies the load balancing algorithm to be used for the upstream.
If not specified, NGINX Gateway Fabric defaults to `random two least_conn`,
which differs from the standard NGINX default `round-robin`.
enum:
- ip_hash
- random two least_conn
type: string
targetRefs:
description: |-
TargetRefs identifies API object(s) to apply the policy to.
Expand Down
Loading