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

Omit non-IP defined endpoints from clusters #1452

Merged
merged 4 commits into from
Aug 31, 2022
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
7 changes: 5 additions & 2 deletions cli/cmd/proxy/read/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"strings"

Expand Down Expand Up @@ -198,8 +199,10 @@ func parseClusters(rawCfg map[string]interface{}, clusterMapping map[string][]st
endpoints := make([]string, 0)
for _, endpoint := range cluster.Cluster.LoadAssignment.Endpoints {
for _, lbEndpoint := range endpoint.LBEndpoints {
endpoints = append(endpoints, fmt.Sprintf("%s:%d", lbEndpoint.Endpoint.Address.SocketAddress.Address,
int(lbEndpoint.Endpoint.Address.SocketAddress.PortValue)))
// Only add endpoints defined by IP addresses.
if addr := lbEndpoint.Endpoint.Address.SocketAddress.Address; net.ParseIP(addr) != nil {
endpoints = append(endpoints, fmt.Sprintf("%s:%d", addr, int(lbEndpoint.Endpoint.Address.SocketAddress.PortValue)))
}
}
}

Expand Down
74 changes: 74 additions & 0 deletions cli/cmd/proxy/read/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,80 @@ func TestFormatFilters(t *testing.T) {
}
}

// TestClusterParsingEndpoints checks that the parseClusters function correctly
// maps endpoints from the config dump and cluster mapping into a config object.
// This includes omitting endpoints that are defined by domain names as seen in
// Logical DNS clusters.
func TestClusterParsingEndpoints(t *testing.T) {
expected := []Cluster{
{
Name: "logical_dns_cluster",
FullyQualifiedDomainName: "logical_dns_cluster.service.host",
Endpoints: []string{"192.168.18.110:20000", "192.168.52.101:20000", "192.168.65.131:20000"},
Type: "LOGICAL_DNS",
LastUpdated: "2022-08-30T12:31:03.354Z",
},
}

rawCfg := map[string]interface{}{
"dynamic_active_clusters": []map[string]interface{}{
{
"cluster": map[string]interface{}{
"name": "logical_dns_cluster.service.host",
"type": "LOGICAL_DNS",
"load_assignment": map[string]interface{}{
"endpoints": []map[string]interface{}{
{
"lb_endpoints": []map[string]interface{}{
{
"endpoint": map[string]interface{}{
"address": map[string]interface{}{
"socket_address": map[string]interface{}{
"address": "192.168.18.110",
"port_value": 20000,
},
},
},
},
{
"endpoints": map[string]interface{}{
"address": map[string]interface{}{
"socket_address": map[string]interface{}{
"address": "192.168.52.101",
"port_value": 20000,
},
},
},
},
{
"endpoints": map[string]interface{}{
"address": map[string]interface{}{
"socket_address": map[string]interface{}{
"address": "domain-name",
"port_value": 20000,
},
},
},
},
},
},
},
},
},
"last_updated": "2022-08-30T12:31:03.354Z",
},
},
}
clusterMapping := map[string][]string{
"logical_dns_cluster.service.host": {"192.168.52.101:20000", "192.168.65.131:20000"},
}

actual, err := parseClusters(rawCfg, clusterMapping)
require.NoError(t, err)

require.Equal(t, expected, actual)
}

type mockPortForwarder struct {
openBehavior func(context.Context) (string, error)
}
Expand Down