Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support LB priority for non xRoute endpoints #4033

Merged
merged 22 commits into from
Aug 17, 2024
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
8 changes: 8 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,14 @@ type BackendRef struct {
// BackendObjectReference references a Kubernetes object that represents the backend.
// Only Service kind is supported for now.
gwapiv1.BackendObjectReference `json:",inline"`
// Failover This indicates whether the backend is designated as a failover.
// Multiple failover backends can be configured.
// It is highly recommended to configure active or passive health checks to ensure that failover can be detected
// when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
// The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
// the health of the active backends falls below 72%.
// +optional
Copy link
Contributor

Choose a reason for hiding this comment

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

"Its strongly recommended to configure active or passive healthchecks to ensure failover can be detected when the active backends are unhealthy and can be readjusted once the primary backends are healthy again. The overprovisioning factor is set to 1.4 i.e. the failover backends will receive traffic only once the health of the active backends drops below 72%"

Failover *bool `json:"failover,omitempty"`
}

// BackendCluster contains all the configuration required for configuring access
Expand Down
5 changes: 5 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 @@ -143,6 +143,15 @@ spec:
description: BackendRef defines how an ObjectReference that
is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10398,6 +10398,15 @@ spec:
description: BackendRef defines how an ObjectReference
that is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down Expand Up @@ -11288,6 +11297,15 @@ spec:
description: BackendRef defines how an ObjectReference
that is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down Expand Up @@ -12256,6 +12274,15 @@ spec:
description: BackendRef defines how an ObjectReference
that is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down Expand Up @@ -13159,6 +13186,15 @@ spec:
description: BackendRef defines how an ObjectReference
that is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ spec:
description: BackendRef defines how an ObjectReference that
is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down Expand Up @@ -1148,6 +1157,15 @@ spec:
description: BackendRef defines how an ObjectReference that
is specific to BackendRef.
properties:
failover:
description: |-
Failover This indicates whether the backend is designated as a failover.
Multiple failover backends can be configured.
It is highly recommended to configure active or passive health checks to ensure that failover can be detected
when the active backends become unhealthy and to automatically readjust once the primary backends are healthy again.
The overprovisioning factor is set to 1.4, meaning the failover backends will only start receiving traffic when
the health of the active backends falls below 72%.
type: boolean
group:
default: ""
description: |-
Expand Down
2 changes: 1 addition & 1 deletion internal/gatewayapi/envoyextensionpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (t *Translator) buildExtProc(
}

ds, err = t.processExtServiceDestination(
&extProc.BackendRefs[i].BackendObjectReference,
&extProc.BackendRefs[i],
policyNamespacedName,
egv1a1.KindEnvoyExtensionPolicy,
ir.GRPC,
Expand Down
15 changes: 10 additions & 5 deletions internal/gatewayapi/ext_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

// TODO: zhaohuabing combine this function with the one in the route translator
func (t *Translator) processExtServiceDestination(
backendRef *gwapiv1.BackendObjectReference,
backendRef *egv1a1.BackendRef,
policyNamespacedName types.NamespacedName,
policyKind string,
protocol ir.AppProtocol,
Expand All @@ -37,12 +37,12 @@ func (t *Translator) processExtServiceDestination(

switch KindDerefOr(backendRef.Kind, KindService) {
case KindService:
ds = t.processServiceDestinationSetting(*backendRef, backendNamespace, protocol, resources, envoyProxy)
ds = t.processServiceDestinationSetting(backendRef.BackendObjectReference, backendNamespace, protocol, resources, envoyProxy)
case egv1a1.KindBackend:
if !t.BackendEnabled {
return nil, fmt.Errorf("resource %s of type Backend cannot be used since Backend is disabled in Envoy Gateway configuration", string(backendRef.Name))
}
ds = t.processBackendDestinationSetting(*backendRef, backendNamespace, resources)
ds = t.processBackendDestinationSetting(backendRef.BackendObjectReference, backendNamespace, resources)
ds.Protocol = protocol
}

Expand All @@ -58,7 +58,7 @@ func (t *Translator) processExtServiceDestination(
}

backendTLS = t.applyBackendTLSSetting(
*backendRef,
backendRef.BackendObjectReference,
backendNamespace,
// Gateway is not the appropriate parent reference here because the owner
// of the BackendRef is the policy, and there is no hierarchy
Expand All @@ -78,7 +78,12 @@ func (t *Translator) processExtServiceDestination(

// TODO: support weighted non-xRoute backends
ds.Weight = ptr.To(uint32(1))

if backendRef.Failover != nil {
// set only the secondary priority, the backend defaults to a primary priority if unset.
if ptr.Deref(backendRef.Failover, false) {
ds.Priority = ptr.To(uint32(1))
}
}
return ds, nil
}

Expand Down
5 changes: 4 additions & 1 deletion internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ func (t *Translator) buildExtAuth(policy *egv1a1.SecurityPolicy, resources *Reso
authority string
err error
traffic *ir.TrafficFeatures
failover *bool
)

switch {
Expand All @@ -824,6 +825,7 @@ func (t *Translator) buildExtAuth(policy *egv1a1.SecurityPolicy, resources *Reso
backendRef = http.BackendRef
if len(http.BackendRefs) != 0 {
backendRef = egv1a1.ToBackendObjectReference(http.BackendRefs[0])
failover = http.BackendRefs[0].Failover
}
protocol = ir.HTTP
if traffic, err = translateTrafficFeatures(http.BackendSettings); err != nil {
Expand All @@ -833,6 +835,7 @@ func (t *Translator) buildExtAuth(policy *egv1a1.SecurityPolicy, resources *Reso
backendRef = grpc.BackendRef
if len(grpc.BackendRefs) != 0 {
backendRef = egv1a1.ToBackendObjectReference(grpc.BackendRefs[0])
failover = grpc.BackendRefs[0].Failover
}
protocol = ir.GRPC
if traffic, err = translateTrafficFeatures(grpc.BackendSettings); err != nil {
Expand All @@ -851,7 +854,7 @@ func (t *Translator) buildExtAuth(policy *egv1a1.SecurityPolicy, resources *Reso
authority = backendRefAuthority(resources, backendRef, policy)
pnn := utils.NamespacedName(policy)
if ds, err = t.processExtServiceDestination(
backendRef,
&egv1a1.BackendRef{BackendObjectReference: *backendRef, Failover: failover},
pnn,
KindSecurityPolicy,
protocol,
Expand Down
Loading
Loading