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

Configure DNS refresh rate from DNS record TTL #3807

Merged
merged 3 commits into from
Sep 21, 2021
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
2 changes: 2 additions & 0 deletions charts/ambassador/crds/getambassador.io_mappings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ spec:
- type: array
resolver:
type: string
respect_dns_ttl:
type: boolean
retry_policy:
properties:
num_retries:
Expand Down
2 changes: 2 additions & 0 deletions docs/yaml/ambassador/ambassador-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ spec:
- type: array
resolver:
type: string
respect_dns_ttl:
type: boolean
retry_policy:
properties:
num_retries:
Expand Down
2 changes: 2 additions & 0 deletions docs/yaml/ambassador/ambassador-rbac-prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,8 @@ spec:
- type: array
resolver:
type: string
respect_dns_ttl:
type: boolean
retry_policy:
properties:
num_retries:
Expand Down
2 changes: 2 additions & 0 deletions manifests/ambassador/ambassador-crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ spec:
- type: array
resolver:
type: string
respect_dns_ttl:
type: boolean
retry_policy:
properties:
num_retries:
Expand Down
1 change: 1 addition & 0 deletions pkg/api/getambassador.io/v2/mapping_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type MappingSpec struct {
KeepAlive *KeepAlive `json:"keepalive,omitempty"`
CORS *CORS `json:"cors,omitempty"`
RetryPolicy *RetryPolicy `json:"retry_policy,omitempty"`
RespectDNSTTL *bool `json:"respect_dns_ttl,omitempty"`
GRPC *bool `json:"grpc,omitempty"`
HostRedirect *bool `json:"host_redirect,omitempty"`
HostRewrite string `json:"host_rewrite,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/getambassador.io/v2/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions python/ambassador/envoy/v2/v2cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, config: 'V2Config', cluster: IRCluster) -> None:
'dns_lookup_family': dns_lookup_family
}

if cluster.respect_dns_ttl:
fields['respect_dns_ttl'] = cluster.respect_dns_ttl

if ctype == 'EDS':
fields['eds_cluster_config'] = { 'eds_config': {'ads': {}},
'service_name': cmap_entry['endpoint_path']}
Expand Down
3 changes: 3 additions & 0 deletions python/ambassador/envoy/v3/v3cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __init__(self, config: 'V3Config', cluster: IRCluster) -> None:
'dns_lookup_family': dns_lookup_family
}

if cluster.respect_dns_ttl:
fields['respect_dns_ttl'] = cluster.respect_dns_ttl

if ctype == 'EDS':
fields['eds_cluster_config'] = {
'eds_config': {
Expand Down
2 changes: 2 additions & 0 deletions python/ambassador/ir/ircluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, ir: 'IR', aconf: Config, parent_ir_resource: 'IRResource',
load_balancer: Optional[dict] = None,
keepalive: Optional[dict] = None,
circuit_breakers: Optional[list] = None,
respect_dns_ttl: Optional[bool] = False,

rkey: str="-override-",
kind: str="IRCluster",
Expand Down Expand Up @@ -284,6 +285,7 @@ def __init__(self, ir: 'IR', aconf: Config, parent_ir_resource: 'IRResource',
'connect_timeout_ms': connect_timeout_ms,
'cluster_idle_timeout_ms': cluster_idle_timeout_ms,
'cluster_max_connection_lifetime_ms': cluster_max_connection_lifetime_ms,
'respect_dns_ttl': respect_dns_ttl,
}

if grpc:
Expand Down
1 change: 1 addition & 0 deletions python/ambassador/ir/irhttpmapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class IRHTTPMapping (IRBaseMapping):
"remove_request_headers": True,
"remove_response_headers": True,
"resolver": False,
"respect_dns_ttl": False,
"retry_policy": False,
# Do not include rewrite
"service": False, # See notes above
Expand Down
3 changes: 2 additions & 1 deletion python/ambassador/ir/irhttpmappinggroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ def add_cluster_for_mapping(self, mapping: IRBaseMapping,
cluster_idle_timeout_ms=mapping.get('cluster_idle_timeout_ms', None),
cluster_max_connection_lifetime_ms=mapping.get('cluster_max_connection_lifetime_ms', None),
circuit_breakers=mapping.get('circuit_breakers', None),
marker=marker)
marker=marker,
respect_dns_ttl=mapping.get('respect_dns_ttl', False))

# Make sure that the cluster is actually in our IR...
stored = self.ir.add_cluster(cluster)
Expand Down
1 change: 1 addition & 0 deletions python/schemas/v2/Mapping.schema
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"host_regex": { "type": "boolean" },
"headers": { "$ref": "#/definitions/mapStrStr" },
"regex_headers": { "$ref": "#/definitions/mapStrStr" },
"respect_dns_ttl": { "type": "boolean" },
"labels": {
"type": "object"
},
Expand Down
76 changes: 76 additions & 0 deletions python/tests/kat/t_dns_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,79 @@ def check(self):
# Not getting a 400 bad request is confirmation that this setting works as long as the request can reach the upstream
assert self.results[0].status == 200

# Tests Respecting DNS TTL alone
class DnsTtl(AmbassadorTest):
target: ServiceType

def init(self):
self.target = HTTP(name="target")

def config(self):
yield self, self.format("""
---
apiVersion: ambassador/v2
kind: Mapping
name: {self.target.path.k8s}-foo
prefix: /foo/
service: {self.target.path.fqdn}
respect_dns_ttl: true
""")

def queries(self):
yield Query(self.url("foo/"))

def check(self):
# Not getting a 400 bad request is confirmation that this setting works as long as the request can reach the upstream
assert self.results[0].status == 200

# Tests the DNS TTL with the endpoint resolver
class DnsTtlEndpoint(AmbassadorTest):
target: ServiceType

def init(self):
self.target = HTTP(name="target")

def config(self):
yield self, self.format("""
---
apiVersion: ambassador/v2
kind: Mapping
name: {self.target.path.k8s}-foo
prefix: /foo/
service: {self.target.path.fqdn}
respect_dns_ttl: true
resolver: endpoint
""")

def queries(self):
yield Query(self.url("foo/"))

def check(self):
# Not getting a 400 bad request is confirmation that this setting works as long as the request can reach the upstream
assert self.results[0].status == 200

# Tests the DNS TTL with Logical DNS type
class DnsTtlDnsType(AmbassadorTest):
target: ServiceType

def init(self):
self.target = HTTP(name="target")

def config(self):
yield self, self.format("""
---
apiVersion: ambassador/v2
kind: Mapping
name: {self.target.path.k8s}-foo
prefix: /foo/
service: {self.target.path.fqdn}
respect_dns_ttl: true
dns_type: logical_dns
""")

def queries(self):
yield Query(self.url("foo/"))

def check(self):
# Not getting a 400 bad request is confirmation that this setting works as long as the request can reach the upstream
assert self.results[0].status == 200
17 changes: 17 additions & 0 deletions python/tests/test_cluster_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@ def test_logical_dns_type_wrong():
_test_cluster_setting(yaml, setting="type",
expected="EDS", exists=True, envoy_version=v)

@pytest.mark.compilertest
def test_dns_ttl():
# Test configuring the respect_dns_ttl generates an Envoy config
yaml = module_and_mapping_manifests(None, ["respect_dns_ttl: true"])
for v in SUPPORTED_ENVOY_VERSIONS:
# The dns type is listed as just "type"
_test_cluster_setting(yaml, setting="respect_dns_ttl",
expected="true", exists=True, envoy_version=v)

@pytest.mark.compilertest
def test_dns_ttl():
# Test dns_ttl is not configured when not applied in the Mapping
yaml = module_and_mapping_manifests(None, None)
for v in SUPPORTED_ENVOY_VERSIONS:
# The dns type is listed as just "type"
_test_cluster_setting(yaml, setting="respect_dns_ttl",
expected="false", exists=False, envoy_version=v)