Skip to content
Open
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
25 changes: 25 additions & 0 deletions api/v1alpha1/backendpolicy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
)

// BackendPolicy allows the user to configure the behavior of the connection
// between the Envoy Proxy and the backend service.
type BackendPolicy struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sounds like a good solution for #7520

metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec defines the desired state of BackendPolicySpec.
Spec BackendPolicySpec `json:"spec"`

// status defines the current status of BackendPolicySpec.
Status gwapiv1.PolicyStatus `json:"status,omitempty"`
}

// BackendPolicySpec defines the desired state of BackendPolicy.
type BackendPolicySpec struct {
PolicyTargetReferences `json:",inline"`
ClusterSettings `json:",inline"`
}
4 changes: 2 additions & 2 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const (
KindBackendTrafficPolicy = "BackendTrafficPolicy"
)

// BackendTrafficPolicy allows the user to configure the behavior of the connection
// between the Envoy Proxy listener and the backend service.
// BackendTrafficPolicy allows the user to override the behavior of the connection
// between the Envoy Proxy listener and the backend service for a specific xRoute.
//
// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=envoy-gateway,shortName=btp
Expand Down
9 changes: 9 additions & 0 deletions api/v1alpha1/envoyproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ type EnvoyProxySpec struct {
// +optional
MergeGateways *bool `json:"mergeGateways,omitempty"`

// MergeBackends defines if backends with the same identity across different xRoutes
// should be merged to reduce the number of clusters in the Envoy configuration.
// When set to true, backends that share the same identity (i.e., same namespace and name)
// will be consolidated into a single cluster, even if they are referenced by different HTTPRoutes.
// This can help optimize resource usage and improve performance by minimizing redundant clusters.
//
// +optional
MergeBackends *bool `json:"mergeBackends,omitempty"`

// Shutdown defines configuration for graceful envoy shutdown process.
//
// +optional
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ spec:
schema:
openAPIV3Schema:
description: |-
BackendTrafficPolicy allows the user to configure the behavior of the connection
between the Envoy Proxy listener and the backend service.
BackendTrafficPolicy allows the user to override the behavior of the connection
between the Envoy Proxy listener and the backend service for a specific xRoute.
properties:
apiVersion:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ spec:
- Strict
- Disabled
type: string
mergeBackends:
description: |-
MergeBackends defines if backends with the same identity across different xRoutes
should be merged to reduce the number of clusters in the Envoy configuration.
When set to true, backends that share the same identity (i.e., same namespace and name)
will be consolidated into a single cluster, even if they are referenced by different HTTPRoutes.
This can help optimize resource usage and improve performance by minimizing redundant clusters.
type: boolean
mergeGateways:
description: |-
MergeGateways defines if Gateway resources should be merged onto the same Envoy Proxy Infrastructure.
Expand Down
1,429 changes: 1,429 additions & 0 deletions charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendpolicies.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ spec:
schema:
openAPIV3Schema:
description: |-
BackendTrafficPolicy allows the user to configure the behavior of the connection
between the Envoy Proxy listener and the backend service.
BackendTrafficPolicy allows the user to override the behavior of the connection
between the Envoy Proxy listener and the backend service for a specific xRoute.
properties:
apiVersion:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ spec:
- Strict
- Disabled
type: string
mergeBackends:
description: |-
MergeBackends defines if backends with the same identity across different xRoutes
should be merged to reduce the number of clusters in the Envoy configuration.
When set to true, backends that share the same identity (i.e., same namespace and name)
will be consolidated into a single cluster, even if they are referenced by different HTTPRoutes.
This can help optimize resource usage and improve performance by minimizing redundant clusters.
type: boolean
mergeGateways:
description: |-
MergeGateways defines if Gateway resources should be merged onto the same Envoy Proxy Infrastructure.
Expand Down
4 changes: 4 additions & 0 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ func IsMergeGatewaysEnabled(resources *resource.Resources) bool {
return resources.EnvoyProxyForGatewayClass != nil && resources.EnvoyProxyForGatewayClass.Spec.MergeGateways != nil && *resources.EnvoyProxyForGatewayClass.Spec.MergeGateways
}

func IsMergeBackendsEnabled(resources *resource.Resources) bool {
return resources.EnvoyProxyForGatewayClass != nil && resources.EnvoyProxyForGatewayClass.Spec.MergeBackends != nil && *resources.EnvoyProxyForGatewayClass.Spec.MergeBackends
}

func protocolSliceToStringSlice(protocols []gwapiv1.ProtocolType) []string {
protocolStrings := make([]string, 0, len(protocols))
for _, protocol := range protocols {
Expand Down
1 change: 1 addition & 0 deletions internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (r *Runner) subscribeAndTranslate(sub <-chan watchable.Snapshot[string, *re
ControllerNamespace: r.ControllerNamespace,
GatewayNamespaceMode: r.EnvoyGateway.GatewayNamespaceMode(),
MergeGateways: gatewayapi.IsMergeGatewaysEnabled(resources),
MergeBackends: gatewayapi.IsMergeBackendsEnabled(resources),
WasmCache: r.wasmCache,
RunningOnHost: r.EnvoyGateway.Provider != nil && r.EnvoyGateway.Provider.IsRunningOnHost(),
Logger: r.Logger,
Expand Down
4 changes: 4 additions & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ type Translator struct {
// should be merged under the parent GatewayClass.
MergeGateways bool

// MergeBackends is true when Backend resources with same identity
// should be merged under the Gateway.
MergeBackends bool

// GatewayNamespaceMode is true if controller uses gateway namespace mode for infra deployments.
GatewayNamespaceMode bool

Expand Down