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

Refactor dns cluster api #36353

Merged
merged 55 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
9048a69
Move cluster dns config and validate in strict dns clusters
Stevenjin8 Aug 19, 2024
3917c63
Roll back incompatible API changes
Stevenjin8 Oct 7, 2024
dab5712
Merge branch 'main' into refactor/dns-api
Stevenjin8 Oct 10, 2024
fd255d0
Use cluster_type as extension point
Stevenjin8 Oct 10, 2024
c944d7e
Revert unecessary changes
Stevenjin8 Oct 10, 2024
8ed51ae
Format
Stevenjin8 Oct 10, 2024
8915b81
Fix logical dns tests
Stevenjin8 Oct 11, 2024
2464e2c
format
Stevenjin8 Oct 11, 2024
821bb34
Remove extra changes
Stevenjin8 Oct 11, 2024
1d54cff
extra change
Stevenjin8 Oct 11, 2024
58dbf1f
Doc fixes in dns cluster proto
Stevenjin8 Oct 11, 2024
9784406
more docs
Stevenjin8 Oct 11, 2024
7309f8d
More logical dns tests
Stevenjin8 Oct 11, 2024
69f9cec
CI please work
Stevenjin8 Oct 14, 2024
5420879
fix tests?
Stevenjin8 Oct 14, 2024
a9a5a5c
Fix integration test (not really)
Stevenjin8 Oct 14, 2024
6da56ce
Merge branch 'main' into refactor/dns-api
Stevenjin8 Oct 15, 2024
16f9cc1
Use Absl StartsWith
Stevenjin8 Oct 15, 2024
d4a0058
Remove FIXME
Stevenjin8 Oct 21, 2024
9586603
Some typos
Stevenjin8 Oct 21, 2024
8a5b9f6
Merge branch 'main' into refactor/dns-api
Stevenjin8 Oct 23, 2024
676a8ba
Merge branch 'main' into refactor/dns-api
Stevenjin8 Nov 6, 2024
bdc8883
Merge branch 'main' into refactor/dns-api
Stevenjin8 Nov 8, 2024
64a6fbd
Add generic factory
Stevenjin8 Nov 8, 2024
52647e3
wip
Stevenjin8 Nov 12, 2024
9fe2bb2
Tests
Stevenjin8 Nov 13, 2024
3dc3fb1
Merge branch 'main' into refactor/dns-api
Stevenjin8 Nov 13, 2024
1c319dc
lint
Stevenjin8 Nov 13, 2024
2e7d6e5
Change visibility
Stevenjin8 Nov 13, 2024
c22edc1
lint
Stevenjin8 Nov 14, 2024
31b9024
extension registration
Stevenjin8 Nov 14, 2024
c348f70
Lints and delete extra diffs
Stevenjin8 Nov 14, 2024
cea08c9
more lint and tests
Stevenjin8 Nov 14, 2024
cb2d8fb
proto docs
Stevenjin8 Nov 14, 2024
199bbb1
fix tests
Stevenjin8 Nov 15, 2024
c0607d3
Mikhail review
Stevenjin8 Nov 15, 2024
05fd078
rst error
Stevenjin8 Nov 15, 2024
684ca7a
rst error and add more coverage
Stevenjin8 Nov 15, 2024
6c36802
docs
Stevenjin8 Nov 15, 2024
0463313
docs
Stevenjin8 Nov 18, 2024
39545a4
Update extensions status
Stevenjin8 Nov 18, 2024
727cf77
release notes
Stevenjin8 Nov 18, 2024
5232706
Merge branch 'main' into refactor/dns-api
Stevenjin8 Nov 21, 2024
df92eef
Register cluster extensions by type
Stevenjin8 Nov 22, 2024
82ae4ce
Better coverage
Stevenjin8 Nov 25, 2024
e8bd59a
Typo
Stevenjin8 Nov 25, 2024
752a805
Merge branch 'main' into refactor/dns-api
Stevenjin8 Nov 25, 2024
bd0ae97
Better docs
Stevenjin8 Dec 12, 2024
1ffdf41
Merge branch 'main' into refactor/dns-api
Stevenjin8 Dec 12, 2024
aeb3302
second merge
Stevenjin8 Dec 16, 2024
0b816c6
third merge
Stevenjin8 Dec 17, 2024
2a7832f
update logical dns api
Stevenjin8 Dec 17, 2024
9b7927c
forgot one!
Stevenjin8 Dec 18, 2024
3078d7c
last one please
Stevenjin8 Dec 18, 2024
e31a09b
API docs clarification
Stevenjin8 Dec 18, 2024
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
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ extensions/filters/http/oauth2 @derekargueta @mattklein123
/*/extensions/clusters/logical_dns/ @UNOWNED @UNOWNED
/*/extensions/clusters/common/ @UNOWNED @UNOWNED
/*/extensions/clusters/eds/ @UNOWNED @UNOWNED
/*/extensions/clusters/dns @UNOWNED @UNOWNED
/*/source/extensions/listener_managers/listener_manager @alyssawilk @ggreenway
/*/source/extensions/listener_managers/validation_listener_manager @alyssawilk @ggreenway
/*/source/extensions/config_subscription/ @adisuissa @UNOWNED
Expand Down
2 changes: 2 additions & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ proto_library(
"//envoy/extensions/access_loggers/wasm/v3:pkg",
"//envoy/extensions/bootstrap/internal_listener/v3:pkg",
"//envoy/extensions/clusters/aggregate/v3:pkg",
"//envoy/extensions/clusters/common/dns/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"//envoy/extensions/clusters/dynamic_forward_proxy/v3:pkg",
"//envoy/extensions/clusters/redis/v3:pkg",
"//envoy/extensions/common/async_files/v3:pkg",
Expand Down
39 changes: 34 additions & 5 deletions api/envoy/config/cluster/v3/cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,13 @@ message Cluster {
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`
// and :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>`
// this setting is ignored.
google.protobuf.Duration dns_refresh_rate = 16
[(validate.rules).duration = {gt {nanos: 1000000}}];
// This field is deprecated in favor of :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` and
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this same comment should apply to all DNS-related fields in the Cluster proto (e.g., dns_lookup_family, dns_resolvers, etc).

We'll need to add corresponding fields to the new DnsCluster message for each of those fields.

Copy link
Member

Choose a reason for hiding this comment

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

Yes agreed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markdroth @mattklein redis cluster uses these fields, so we will have to update that too?

dispatcher_(context.serverFactoryContext().mainThreadDispatcher()),
dns_resolver_(std::move(dns_resolver)),

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not that familiar with the redis cluster type, but I suspect that we do want it to have its own parameters for DNS configuration. But I would also be okay with deferring some of that to a separate PR: we could document that these fields are deprecated for the STRICT_DNS and LOGICAL_DNS cluster types only for now, but add TODO comments indicating that we will eventually deprecate them for redis as well.

// will be ignored if :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` is set.
google.protobuf.Duration dns_refresh_rate = 16 [
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these fields still need to be used for other cluster types, like redis? If so, we probably can't mark them as deprecated yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both redis and dynamic forward proxies define their own refresh rates

message RedisClusterConfig {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.cluster.redis.RedisClusterConfig";
// Interval between successive topology refresh requests. If not set, this defaults to 5s.
google.protobuf.Duration cluster_refresh_rate = 1 [(validate.rules).duration = {gt {}}];
// Timeout for topology refresh request. If not set, this defaults to 3s.
google.protobuf.Duration cluster_refresh_timeout = 2 [(validate.rules).duration = {gt {}}];
// The minimum interval that must pass after triggering a topology refresh request before a new
// request can possibly be triggered again. Any errors received during one of these
// time intervals are ignored. If not set, this defaults to 5s.
google.protobuf.Duration redirect_refresh_interval = 3;
// The number of redirection errors that must be received before
// triggering a topology refresh request. If not set, this defaults to 5.
// If this is set to 0, topology refresh after redirect is disabled.
google.protobuf.UInt32Value redirect_refresh_threshold = 4;
// The number of failures that must be received before triggering a topology refresh request.
// If not set, this defaults to 0, which disables the topology refresh due to failure.
uint32 failure_refresh_threshold = 5;
// The number of hosts became degraded or unhealthy before triggering a topology refresh request.
// If not set, this defaults to 0, which disables the topology refresh due to degraded or
// unhealthy host.
uint32 host_degraded_refresh_threshold = 6;

google.protobuf.Duration dns_refresh_rate = 3

Couldn't find any other ones.

deprecated = true,
(validate.rules).duration = {gt {nanos: 1000000}},
(envoy.annotations.deprecated_at_minor_version) = "3.0"
];

// DNS jitter can be optionally specified if the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
Expand All @@ -965,7 +970,13 @@ message Cluster {
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`
// and :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>`
// this setting is ignored.
google.protobuf.Duration dns_jitter = 58 [(validate.rules).duration = {gte {}}];
// This field is deprecated in favor of :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` and
// will be ignored if :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` is set.
google.protobuf.Duration dns_jitter = 58 [
deprecated = true,
(validate.rules).duration = {gte {}},
(envoy.annotations.deprecated_at_minor_version) = "3.0"
];

// If the DNS failure refresh rate is specified and the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
Expand All @@ -975,16 +986,28 @@ message Cluster {
// other than :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>` and
// :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>` this setting is
// ignored.
RefreshRate dns_failure_refresh_rate = 44;
// This field is deprecated in favor of :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` and
// will be ignored if :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` is set.
RefreshRate dns_failure_refresh_rate = 44
[deprecated = true, (envoy.annotations.deprecated_at_minor_version) = "3.0"];

// Optional configuration for setting cluster's DNS refresh rate. If the value is set to true,
// cluster's DNS refresh rate will be set to resource record's TTL which comes from DNS
// resolution.
bool respect_dns_ttl = 39;
// This field is deprecated in favor of :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` and
// will be ignored if :ref:`cluster_type<envoy_v3_api_field_config.cluster.v3.Cluster.cluster_type>` is set.
bool respect_dns_ttl = 39
[deprecated = true, (envoy.annotations.deprecated_at_minor_version) = "3.0"];

// The DNS IP address resolution policy. If this setting is not specified, the
// value defaults to
// :ref:`AUTO<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DnsLookupFamily.AUTO>`.
// Note that this field is deprecated for cluster types
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
// and :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>` cluster.
// and will be ignored if ``config_type.name`` is ``envoy.cluster.dns``, ``envoy.cluster.logical_dns``, or
// ``envoy.cluster.strict_dns``.
// Use :ref:`config_type<envoy_v3_api_field_extensions.clusters.dns.v3.DnsCluster.config_type>` instead.
DnsLookupFamily dns_lookup_family = 17 [(validate.rules).enum = {defined_only: true}];

// If DNS resolvers are specified and the cluster type is either
Expand Down Expand Up @@ -1024,6 +1047,12 @@ message Cluster {
// During the transition period when both ``dns_resolution_config`` and ``typed_dns_resolver_config`` exists,
// when ``typed_dns_resolver_config`` is in place, Envoy will use it and ignore ``dns_resolution_config``.
// When ``typed_dns_resolver_config`` is missing, the default behavior is in place.
// Also note that this field is deprecated for cluster types
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
// and :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>` cluster.
// and will be ignored if ``config_type.name`` is ``envoy.cluster.dns``, ``envoy.cluster.logical_dns``, or
// ``envoy.cluster.strict_dns``.
// Use :ref:`config_type<envoy_v3_api_field_extensions.clusters.dns.v3.DnsCluster.config_type>` instead.
// [#extension-category: envoy.network.dns_resolver]
core.v3.TypedExtensionConfig typed_dns_resolver_config = 55;

Expand Down
9 changes: 9 additions & 0 deletions api/envoy/extensions/clusters/common/dns/v3/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = ["@com_github_cncf_xds//udpa/annotations:pkg"],
)
20 changes: 20 additions & 0 deletions api/envoy/extensions/clusters/common/dns/v3/dns.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

package envoy.extensions.clusters.common.dns.v3;

import "udpa/annotations/status.proto";

option java_package = "io.envoyproxy.envoy.extensions.clusters.common.dns.v3";
option java_outer_classname = "DnsProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/common/dns/v3;dnsv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

enum DnsLookupFamily {
UNSPECIFIED = 0;
AUTO = 1;
V4_ONLY = 2;
V6_ONLY = 3;
V4_PREFERRED = 4;
ALL = 5;
}
13 changes: 13 additions & 0 deletions api/envoy/extensions/clusters/dns/v3/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/config/core/v3:pkg",
"//envoy/extensions/clusters/common/dns/v3:pkg",
"@com_github_cncf_xds//udpa/annotations:pkg",
],
)
88 changes: 88 additions & 0 deletions api/envoy/extensions/clusters/dns/v3/dns_cluster.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
syntax = "proto3";

package envoy.extensions.clusters.dns.v3;

import "envoy/config/core/v3/extension.proto";
import "envoy/extensions/clusters/common/dns/v3/dns.proto";

import "google/protobuf/duration.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.clusters.dns.v3";
option java_outer_classname = "DnsClusterProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/dns/v3;dnsv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: DNS cluster configuration]

// Configuration for strict and logical DNS clusters.
// [#extension: envoy.clusters.strict_dns]
// [#extension: envoy.clusters.logical_dns]

// [#next-free-field: 10]
message DnsCluster {
enum DnsDiscoveryType {
LOGICAL = 0;
STRICT = 1;
}

message RefreshRate {
// Specifies the base interval between refreshes. This parameter is required and must be greater
// than zero and less than
// :ref:`max_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsCluster.RefreshRate.max_interval>`.
google.protobuf.Duration base_interval = 1 [(validate.rules).duration = {
required: true
gt {nanos: 1000000}
}];

// Specifies the maximum interval between refreshes. This parameter is optional, but must be
// greater than or equal to the
// :ref:`base_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsCluster.RefreshRate.base_interval>` if set. The default
// is 10 times the :ref:`base_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsCluster.RefreshRate.base_interval>`.
google.protobuf.Duration max_interval = 2 [(validate.rules).duration = {gt {nanos: 1000000}}];
}

// This value is the cluster’s DNS refresh rate. The value configured must be at least 1ms.
// If this setting is not specified, the
// value defaults to 5000ms.
google.protobuf.Duration dns_refresh_rate = 3 [(validate.rules).duration = {gt {nanos: 1000000}}];

// This is the cluster’s DNS refresh rate when requests are failing. If this setting is
// not specified, the failure refresh rate defaults to the DNS refresh rate.
RefreshRate dns_failure_refresh_rate = 4;

// Optional configuration for setting cluster's DNS refresh rate. If the value is set to true,
// cluster's DNS refresh rate will be set to resource record's TTL which comes from DNS
// resolution.
bool respect_dns_ttl = 5;

// DNS jitter causes the cluster to refresh DNS entries later by a random amount of time to avoid a
// stampede of DNS requests. This value sets the upper bound (exclusive) for the random amount.
// There will be no jitter if this value is omitted.
google.protobuf.Duration dns_jitter = 6 [(validate.rules).duration = {gte {}}];

// DNS resolver type configuration extension. This extension can be used to configure c-ares, apple,
// or any other DNS resolver types and the related parameters.
// For example, an object of
// :ref:`CaresDnsResolverConfig <envoy_v3_api_msg_extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig>`
// can be packed into this ``typed_dns_resolver_config``. This configuration replaces the
// :ref:`Cluster.dns_resolution_config <envoy_v3_api_field_config.cluster.v3.Cluster.typed_dns_resolution_config>`
// configuration which replaces `Cluster.dns_resolution_config <envoy_v3_api_field_config.cluster.v3.Cluster.dns_resolution_config>`.
// During the transition period when ``DnsCluster.typed_dns_resolver_config``, ``Cluster.dns_resolution_config``, and
// ``Cluster.typed_dns_resolver_config`` exists, Envoy will prefer, ``DnsCluster.typed_dns_resolver_config`` over
// ``Cluster.typed_dns_resolver_config`` over ``cluster.dns_resolver_config``.
// [#extension-category: envoy.network.dns_resolver]
config.core.v3.TypedExtensionConfig typed_dns_resolver_config = 7;

// The DNS IP address resolution policy. If this setting is not specified, the
// value defaults to
// :ref:`AUTO<envoy_v3_api_enum_value_extensions.clusters.dns.v3.DnsCluster.DnsLookupFamily.AUTO>`.
common.dns.v3.DnsLookupFamily dns_lookup_family = 8;

// Whether to do logical or strict dns resolution.
// This field is only considered when the ``name`` field of the ``TypedConfig`` is ``envoy.cluster.dns``.
DnsDiscoveryType dns_discovery_type = 9;
}
2 changes: 2 additions & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ proto_library(
"//envoy/extensions/access_loggers/wasm/v3:pkg",
"//envoy/extensions/bootstrap/internal_listener/v3:pkg",
"//envoy/extensions/clusters/aggregate/v3:pkg",
"//envoy/extensions/clusters/common/dns/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"//envoy/extensions/clusters/dynamic_forward_proxy/v3:pkg",
"//envoy/extensions/clusters/redis/v3:pkg",
"//envoy/extensions/common/async_files/v3:pkg",
Expand Down
1 change: 1 addition & 0 deletions source/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ envoy_cc_library(
"//envoy/network:dns_interface",
"//source/common/network:utility_lib",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/clusters/dns/v3:pkg_cc_proto",
],
)

Expand Down
21 changes: 21 additions & 0 deletions source/common/common/dns_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ getDnsLookupFamilyFromEnum(envoy::config::cluster::v3::Cluster::DnsLookupFamily
return Network::DnsLookupFamily::All;
}

Network::DnsLookupFamily
getDnsLookupFamilyFromEnum(envoy::extensions::clusters::common::dns::v3::DnsLookupFamily family) {
switch (family) {
PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
case envoy::extensions::clusters::common::dns::v3::V6_ONLY:
return Network::DnsLookupFamily::V6Only;
case envoy::extensions::clusters::common::dns::v3::V4_ONLY:
return Network::DnsLookupFamily::V4Only;
case envoy::extensions::clusters::common::dns::v3::AUTO:
case envoy::extensions::clusters::common::dns::v3::UNSPECIFIED:
return Network::DnsLookupFamily::Auto;
case envoy::extensions::clusters::common::dns::v3::V4_PREFERRED:
return Network::DnsLookupFamily::V4Preferred;
case envoy::extensions::clusters::common::dns::v3::ALL:
return Network::DnsLookupFamily::All;
break;
}
IS_ENVOY_BUG("unexpected dns lookup family enum");
return Network::DnsLookupFamily::All;
}

std::vector<Network::Address::InstanceConstSharedPtr>
generateAddressList(const std::list<Network::DnsResponse>& responses, uint32_t port) {
std::vector<Network::Address::InstanceConstSharedPtr> addresses;
Expand Down
3 changes: 3 additions & 0 deletions source/common/common/dns_utils.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"
#include "envoy/network/dns.h"

namespace Envoy {
Expand All @@ -13,6 +14,8 @@ Network::DnsLookupFamily
getDnsLookupFamilyFromCluster(const envoy::config::cluster::v3::Cluster& cluster);
Network::DnsLookupFamily
getDnsLookupFamilyFromEnum(envoy::config::cluster::v3::Cluster::DnsLookupFamily family);
Network::DnsLookupFamily
getDnsLookupFamilyFromEnum(envoy::extensions::clusters::common::dns::v3::DnsLookupFamily family);

// Generates a list of InstanceConstSharedPtr from the DNS responses provided.
std::vector<Network::Address::InstanceConstSharedPtr>
Expand Down
12 changes: 12 additions & 0 deletions source/extensions/clusters/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ envoy_cc_library(
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "dns_cluster_backcompat_lib",
srcs = ["dns_cluster_backcompat.cc"],
hdrs = ["dns_cluster_backcompat.h"],
deps = [
"//source/common/upstream:cluster_factory_includes",
"//source/common/upstream:upstream_includes",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/clusters/dns/v3:pkg_cc_proto",
],
)
59 changes: 59 additions & 0 deletions source/extensions/clusters/common/dns_cluster_backcompat.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "source/extensions/clusters/common/dns_cluster_backcompat.h"

#include "envoy/common/exception.h"
#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"

namespace Envoy {
namespace Upstream {

void createDnsClusterFromLegacyFields(
const envoy::config::cluster::v3::Cluster& cluster,
envoy::extensions::clusters::dns::v3::DnsCluster& dns_cluster) {

// We have to add all these guards because otherwise dns_cluster.mutable_FIELD will initialize the
// field and dns_cluster.has_FIELD will return true
if (cluster.has_dns_refresh_rate()) {
dns_cluster.mutable_dns_refresh_rate()->CopyFrom(cluster.dns_refresh_rate());
}

if (cluster.has_dns_failure_refresh_rate()) {
auto* new_refresh_rate = dns_cluster.mutable_dns_failure_refresh_rate();
const auto& old_refresh_rate = cluster.dns_failure_refresh_rate();

if (old_refresh_rate.has_max_interval()) {
new_refresh_rate->mutable_max_interval()->CopyFrom(old_refresh_rate.max_interval());
}
if (old_refresh_rate.has_base_interval()) {
new_refresh_rate->mutable_base_interval()->CopyFrom(old_refresh_rate.base_interval());
}
}

dns_cluster.set_respect_dns_ttl(cluster.respect_dns_ttl());

if (cluster.has_dns_jitter()) {
dns_cluster.mutable_dns_jitter()->CopyFrom(cluster.dns_jitter());
}

switch (cluster.dns_lookup_family()) {
PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
case envoy::config::cluster::v3::Cluster::AUTO:
dns_cluster.set_dns_lookup_family(envoy::extensions::clusters::common::dns::v3::AUTO);
break;
case envoy::config::cluster::v3::Cluster::V4_ONLY:
dns_cluster.set_dns_lookup_family(envoy::extensions::clusters::common::dns::v3::V4_ONLY);
break;
case envoy::config::cluster::v3::Cluster::V6_ONLY:
dns_cluster.set_dns_lookup_family(envoy::extensions::clusters::common::dns::v3::V6_ONLY);
break;
case envoy::config::cluster::v3::Cluster::V4_PREFERRED:
dns_cluster.set_dns_lookup_family(envoy::extensions::clusters::common::dns::v3::V4_PREFERRED);
break;
case envoy::config::cluster::v3::Cluster::ALL:
dns_cluster.set_dns_lookup_family(envoy::extensions::clusters::common::dns::v3::ALL);
break;
}
}

} // namespace Upstream
} // namespace Envoy
14 changes: 14 additions & 0 deletions source/extensions/clusters/common/dns_cluster_backcompat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"

namespace Envoy {
namespace Upstream {

void createDnsClusterFromLegacyFields(
const envoy::config::cluster::v3::Cluster& cluster,
envoy::extensions::clusters::dns::v3::DnsCluster& new_proto_config);

}
} // namespace Envoy
Loading
Loading