Skip to content

Commit

Permalink
DNS is also a feature that can be enabled for extProc and extAuth
Browse files Browse the repository at this point in the history
clusters, so treat it as such.

Signed-off-by: Lior Okman <lior.okman@sap.com>
  • Loading branch information
liorokman committed Aug 2, 2024
1 parent f2e9788 commit 6c44912
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 94 deletions.
10 changes: 5 additions & 5 deletions api/v1alpha1/backendtrafficpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ type BackendTrafficPolicySpec struct {
// +optional
// +notImplementedHide
Compression []*Compression `json:"compression,omitempty"`

// DNS includes dns resolution settings.
//
// +optional
DNS *DNS `json:"dns,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -139,6 +134,11 @@ type ClusterSettings struct {
//
// +optional
Connection *BackendConnection `json:"connection,omitempty"`

// DNS includes dns resolution settings.
//
// +optional
DNS *DNS `json:"dns,omitempty"`
}

func init() {
Expand Down
10 changes: 5 additions & 5 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 @@ -126,6 +126,21 @@ spec:
Note: that when the suffix is not provided, the value is interpreted as bytes.
x-kubernetes-int-or-string: true
type: object
dns:
description: DNS includes dns resolution settings.
properties:
dnsRefreshRate:
description: |-
DNSRefreshRate specifies the rate at which DNS records should be refreshed.
Defaults to 30 seconds.
type: string
respectDnsTtl:
description: |-
RespectDNSTTL indicates whether the DNS Time-To-Live (TTL) should be respected.
If the value is set to true, the DNS refresh rate will be set to the resource record’s TTL.
Defaults to true.
type: boolean
type: object
healthCheck:
description: HealthCheck allows gateway to perform active
health checking on backends.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ spec:
Note: that when the suffix is not provided, the value is interpreted as bytes.
x-kubernetes-int-or-string: true
type: object
dns:
description: DNS includes dns resolution settings.
properties:
dnsRefreshRate:
description: |-
DNSRefreshRate specifies the rate at which DNS records should be refreshed.
Defaults to 30 seconds.
type: string
respectDnsTtl:
description: |-
RespectDNSTTL indicates whether the DNS Time-To-Live (TTL) should be respected.
If the value is set to true, the DNS refresh rate will be set to the resource record’s TTL.
Defaults to true.
type: boolean
type: object
healthCheck:
description: HealthCheck allows gateway to perform active
health checking on backends.
Expand Down Expand Up @@ -1039,6 +1054,21 @@ spec:
Note: that when the suffix is not provided, the value is interpreted as bytes.
x-kubernetes-int-or-string: true
type: object
dns:
description: DNS includes dns resolution settings.
properties:
dnsRefreshRate:
description: |-
DNSRefreshRate specifies the rate at which DNS records should be refreshed.
Defaults to 30 seconds.
type: string
respectDnsTtl:
description: |-
RespectDNSTTL indicates whether the DNS Time-To-Live (TTL) should be respected.
If the value is set to true, the DNS refresh rate will be set to the resource record’s TTL.
Defaults to true.
type: boolean
type: object
healthCheck:
description: HealthCheck allows gateway to perform active
health checking on backends.
Expand Down
77 changes: 19 additions & 58 deletions internal/gatewayapi/backendtrafficpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
errs = errors.Join(errs, err)
}

if policy.Spec.DNS != nil {
ds = t.translateDNS(policy)
}
ds = translateDNS(policy.Spec.DNS)

// Early return if got any errors
if errs != nil {
Expand Down Expand Up @@ -389,9 +387,9 @@ func (t *Translator) translateBackendTrafficPolicyForRoute(policy *egv1a1.Backen
TCPKeepalive: ka,
Retry: rt,
BackendConnection: bc,
DNS: ds,
}

r.DNS = ds
// Update the Host field in HealthCheck, now that we have access to the Route Hostname.
r.Traffic.HealthCheck.SetHTTPHostIfAbsent(r.Hostname)

Expand Down Expand Up @@ -458,9 +456,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
errs = errors.Join(errs, err)
}

if policy.Spec.DNS != nil {
ds = t.translateDNS(policy)
}
ds = translateDNS(policy.Spec.DNS)

// Early return if got any errors
if errs != nil {
Expand All @@ -483,26 +479,15 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
}

for _, r := range tcp.Routes {
// policy(targeting xRoute) has already set it, so we skip it.
if r.LoadBalancer != nil || r.ProxyProtocol != nil ||
r.HealthCheck != nil || r.CircuitBreaker != nil ||
r.TCPKeepalive != nil || r.Timeout != nil {
continue
}

r.LoadBalancer = lb
r.ProxyProtocol = pp
r.HealthCheck = hc
r.CircuitBreaker = cb
r.TCPKeepalive = ka

if r.Timeout == nil {
r.Timeout = ct
}

if r.DNS == nil {
r.DNS = ds
}
// only set attributes which weren't already set by a more
// specific policy
setIfNil(&r.LoadBalancer, lb)
setIfNil(&r.ProxyProtocol, pp)
setIfNil(&r.HealthCheck, hc)
setIfNil(&r.CircuitBreaker, cb)
setIfNil(&r.TCPKeepalive, ka)
setIfNil(&r.Timeout, ct)
setIfNil(&r.DNS, ds)
}
}

Expand All @@ -518,19 +503,11 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back

route := udp.Route

// policy(targeting xRoute) has already set it, so we skip it.
if route.LoadBalancer != nil || route.Timeout != nil {
continue
}

route.LoadBalancer = lb
if route.Timeout == nil {
route.Timeout = ct
}

if route.DNS == nil {
route.DNS = ds
}
// only set attributes which weren't already set by a more
// specific policy
setIfNil(&route.LoadBalancer, lb)
setIfNil(&route.Timeout, ct)
setIfNil(&route.DNS, ds)
}

for _, http := range x.HTTP {
Expand All @@ -557,10 +534,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
FaultInjection: fi,
TCPKeepalive: ka,
Retry: rt,
}

if r.DNS == nil {
r.DNS = ds
DNS: ds,
}

// Update the Host field in HealthCheck, now that we have access to the Route Hostname.
Expand All @@ -571,9 +545,7 @@ func (t *Translator) translateBackendTrafficPolicyForGateway(policy *egv1a1.Back
}

if policy.Spec.UseClientProtocol != nil {
if r.UseClientProtocol == nil {
r.UseClientProtocol = policy.Spec.UseClientProtocol
}
setIfNil(&r.UseClientProtocol, policy.Spec.UseClientProtocol)
}
}
}
Expand Down Expand Up @@ -766,17 +738,6 @@ func buildRateLimitRule(rule egv1a1.RateLimitRule) (*ir.RateLimitRule, error) {
return irRule, nil
}

func (t *Translator) translateDNS(policy *egv1a1.BackendTrafficPolicy) *ir.DNS {
ds := &ir.DNS{}
if policy.Spec.DNS.RespectDNSTTL != nil {
ds.RespectDNSTTL = policy.Spec.DNS.RespectDNSTTL
}
if policy.Spec.DNS.DNSRefreshRate != nil {
ds.DNSRefreshRate = policy.Spec.DNS.DNSRefreshRate
}
return ds
}

func ratelimitUnitToDuration(unit egv1a1.RateLimitUnit) int64 {
var seconds int64

Expand Down
10 changes: 10 additions & 0 deletions internal/gatewayapi/clustersettings.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,13 @@ func translateActiveHealthCheckPayload(p *egv1a1.ActiveHealthCheckPayload) *ir.H

return irPayload
}

func translateDNS(policy *egv1a1.DNS) *ir.DNS {
if policy == nil {
return nil
}
return &ir.DNS{
RespectDNSTTL: policy.RespectDNSTTL,
DNSRefreshRate: policy.DNSRefreshRate,
}
}
7 changes: 7 additions & 0 deletions internal/gatewayapi/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,10 @@ func getPolicyTargetRefs[T client.Object](policy egv1a1.PolicyTargetReferences,

return ret
}

// Sets *target to value if and only if *target is nil
func setIfNil[T any](target **T, value *T) {
if *target == nil {
*target = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,6 @@ xdsIR:
port: 8080
protocol: HTTP
weight: 1
dns:
dnsRefreshRate: 10s
respectDnsTtl: true
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
Expand All @@ -356,7 +353,10 @@ xdsIR:
distinct: false
name: ""
prefix: /v3
traffic: {}
traffic:
dns:
dnsRefreshRate: 10s
respectDnsTtl: true
envoy-gateway/gateway-2:
accessLog:
text:
Expand Down Expand Up @@ -386,9 +386,6 @@ xdsIR:
port: 8080
protocol: HTTP
weight: 1
dns:
dnsRefreshRate: 5s
respectDnsTtl: false
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
Expand All @@ -400,7 +397,10 @@ xdsIR:
distinct: false
name: ""
prefix: /v2
traffic: {}
traffic:
dns:
dnsRefreshRate: 5s
respectDnsTtl: false
- destination:
name: httproute/default/httproute-1/rule/0
settings:
Expand All @@ -410,9 +410,6 @@ xdsIR:
port: 8080
protocol: HTTP
weight: 1
dns:
dnsRefreshRate: 1s
respectDnsTtl: true
hostname: gateway.envoyproxy.io
isHTTP2: false
metadata:
Expand All @@ -424,4 +421,7 @@ xdsIR:
distinct: false
name: ""
prefix: /
traffic: {}
traffic:
dns:
dnsRefreshRate: 1s
respectDnsTtl: true
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ envoyExtensionPolicies:
Kind: Backend
Group: gateway.envoyproxy.io
backendConfig:
dns:
respectDnsTtl: true
loadBalancer:
type: ConsistentHash
consistentHash:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ envoyExtensionPolicies:
maxConnections: 2048
connection:
bufferLimit: 20Mi
dns:
respectDnsTtl: true
healthCheck:
passive:
consecutiveGatewayErrors: 4
Expand Down
7 changes: 4 additions & 3 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,6 @@ type HTTPRoute struct {
UseClientProtocol *bool `json:"useClientProtocol,omitempty" yaml:"useClientProtocol,omitempty"`
// Metadata is used to enrich envoy route metadata with user and provider-specific information
Metadata *ResourceMetadata `json:"metadata,omitempty" yaml:"metadata,omitempty"`
// DNS is used to configure how DNS resolution is handled for the route
DNS *DNS `json:"dns,omitempty" yaml:"dns,omitempty"`
}

// DNS contains configuration options for DNS resolution.
Expand Down Expand Up @@ -600,6 +598,8 @@ type TrafficFeatures struct {
Retry *Retry `json:"retry,omitempty" yaml:"retry,omitempty"`
// settings of upstream connection
BackendConnection *BackendConnection `json:"backendConnection,omitempty" yaml:"backendConnection,omitempty"`
// DNS is used to configure how DNS resolution is handled by the Envoy Proxy cluster
DNS *DNS `json:"dns,omitempty" yaml:"dns,omitempty"`
}

func (b *TrafficFeatures) Validate() error {
Expand Down Expand Up @@ -1512,7 +1512,8 @@ type UDPRoute struct {
Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
// settings of upstream connection
BackendConnection *BackendConnection `json:"backendConnection,omitempty" yaml:"backendConnection,omitempty"`
DNS *DNS `json:"dns,omitempty" yaml:"dns,omitempty"`
// DNS is used to configure how DNS resolution is handled by the Envoy Proxy cluster
DNS *DNS `json:"dns,omitempty" yaml:"dns,omitempty"`
}

// Validate the fields within the UDPListener structure
Expand Down
Loading

0 comments on commit 6c44912

Please sign in to comment.