Skip to content

Commit

Permalink
minor refactor based on comments
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Sarra <[email protected]>
  • Loading branch information
Leonardo Sarra committed Jul 18, 2024
1 parent 3231865 commit 0d65184
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 2 additions & 3 deletions source/extensions/clusters/static/static_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ StaticClusterImpl::StaticClusterImpl(const envoy::config::cluster::v3::Cluster&
for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) {
std::vector<Network::Address::InstanceConstSharedPtr> address_list;
if (!lb_endpoint.endpoint().additional_addresses().empty()) {
const auto address =
address_list.emplace_back(
THROW_OR_RETURN_VALUE(resolveProtoAddress(lb_endpoint.endpoint().address()),
const Network::Address::InstanceConstSharedPtr);
address_list.push_back(address);
const Network::Address::InstanceConstSharedPtr));
for (const auto& additional_address : lb_endpoint.endpoint().additional_addresses()) {
address_list.emplace_back(
THROW_OR_RETURN_VALUE(resolveProtoAddress(additional_address.address()),
Expand Down
1 change: 1 addition & 0 deletions source/server/admin/config_dump_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ void ConfigDumpHandler::addLbEndpoint(
if (host->addressListOrNull() != nullptr) {
const auto& address_list = *host->addressListOrNull();
if (address_list.size() > 1) {
// skip first address of the list as the default address is not an additional one.
for (auto it = std::next(address_list.begin()); it != address_list.end(); ++it) {
auto& new_address = *endpoint.mutable_additional_addresses()->Add();
Network::Utility::addressToProtobufAddress(**it, *new_address.mutable_address());
Expand Down
4 changes: 3 additions & 1 deletion test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6354,6 +6354,7 @@ TEST_F(ClusterManagerImplTest, CheckAddressesList) {
port_value: 11001
)EOF";
create(parseBootstrapFromV3Yaml(bootstrap));
// Verify address list for static cluster in bootstrap.
auto cluster = cluster_manager_->getThreadLocalCluster("cluster_0");
auto hosts = cluster->prioritySet().hostSetsPerPriority()[0]->hosts();
ASSERT_NE(hosts[0]->addressListOrNull(), nullptr);
Expand Down Expand Up @@ -6394,11 +6395,12 @@ TEST_F(ClusterManagerImplTest, CheckAddressesList) {
address: 127.0.0.1
port_value: 11001
)EOF";
// Add static cluster via api and check that addresses list is empty.
EXPECT_TRUE(cluster_manager_->addOrUpdateCluster(parseClusterFromV3Yaml(cluster_api), "v1"));
cluster = cluster_manager_->getThreadLocalCluster("added_via_api");
hosts = cluster->prioritySet().hostSetsPerPriority()[0]->hosts();
ASSERT_EQ(hosts[0]->addressListOrNull(), nullptr);
// Update cluster to have two address
// Update cluster to have additional addresses and check that address list is not empty anymore.
EXPECT_TRUE(
cluster_manager_->addOrUpdateCluster(parseClusterFromV3Yaml(cluster_api_update), "v2"));
cluster = cluster_manager_->getThreadLocalCluster("added_via_api");
Expand Down

0 comments on commit 0d65184

Please sign in to comment.