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

[release-1.5] empty strict dns cluster fix cherry-pick envoyproxy #10728 #200

Merged
merged 1 commit into from
Apr 24, 2020
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
5 changes: 5 additions & 0 deletions source/common/upstream/strict_dns_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ void StrictDnsClusterImpl::startPreInit() {
for (const ResolveTargetPtr& target : resolve_targets_) {
target->startResolve();
}
// If the config provides no endpoints, the cluster is initialized immediately as if all hosts are
// resolved in failure.
if (resolve_targets_.empty()) {
onPreInitComplete();
}
}

void StrictDnsClusterImpl::updateAllHosts(const HostVector& hosts_added,
Expand Down
28 changes: 28 additions & 0 deletions test/common/upstream/upstream_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@ class StrictDnsClusterImplTest : public testing::Test, public UpstreamImplTestBa
std::make_shared<Network::MockDnsResolver>();
};

TEST_F(StrictDnsClusterImplTest, ZeroHostsIsInializedImmediately) {
ReadyWatcher initialized;

const std::string yaml = R"EOF(
name: name
connect_timeout: 0.25s
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
endpoints:
- lb_endpoints:
)EOF";

envoy::config::cluster::v3::Cluster cluster_config = parseClusterFromV2Yaml(yaml);
Envoy::Stats::ScopePtr scope = stats_.createScope(fmt::format(
"cluster.{}.", cluster_config.alt_stat_name().empty() ? cluster_config.name()
: cluster_config.alt_stat_name()));
Envoy::Server::Configuration::TransportSocketFactoryContextImpl factory_context(
admin_, ssl_context_manager_, *scope, cm_, local_info_, dispatcher_, random_, stats_,
singleton_manager_, tls_, validation_visitor_, *api_);
StrictDnsClusterImpl cluster(cluster_config, runtime_, dns_resolver_, factory_context,
std::move(scope), false);
EXPECT_CALL(initialized, ready());
cluster.initialize([&]() -> void { initialized.ready(); });
EXPECT_EQ(0UL, cluster.prioritySet().hostSetsPerPriority()[0]->hosts().size());
EXPECT_EQ(0UL, cluster.prioritySet().hostSetsPerPriority()[0]->healthyHosts().size());
}

// Resolve zero hosts, while using health checking.
TEST_F(StrictDnsClusterImplTest, ZeroHostsHealthChecker) {
ReadyWatcher initialized;
Expand Down