Skip to content

Commit

Permalink
consul/connect: remove envoy dns option from gateway proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig committed Aug 24, 2020
1 parent 7b3f77d commit 36a743f
Show file tree
Hide file tree
Showing 15 changed files with 9 additions and 86 deletions.
11 changes: 0 additions & 11 deletions api/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ type ConsulGatewayBindAddress struct {
Port int `mapstructure:"port"`
}

const (
defaultDNSDiscoveryType = "LOGICAL_DNS"
)

var (
defaultGatewayConnectTimeout = 5 * time.Second
)
Expand All @@ -349,7 +345,6 @@ type ConsulGatewayProxy struct {
EnvoyGatewayBindTaggedAddresses bool `mapstructure:"envoy_gateway_bind_tagged_addresses"`
EnvoyGatewayBindAddresses map[string]*ConsulGatewayBindAddress `mapstructure:"envoy_gateway_bind_addresses"`
EnvoyGatewayNoDefaultBind bool `mapstructure:"envoy_gateway_no_default_bind"`
EnvoyDNSDiscoveryType string `mapstructure:"envoy_dns_discovery_type"`
Config map[string]interface{} // escape hatch envoy config
}

Expand All @@ -363,11 +358,6 @@ func (p *ConsulGatewayProxy) Canonicalize() {
p.ConnectTimeout = timeToPtr(defaultGatewayConnectTimeout)
}

if p.EnvoyDNSDiscoveryType == "" {
// same as default from consul
p.EnvoyDNSDiscoveryType = defaultDNSDiscoveryType
}

if len(p.EnvoyGatewayBindAddresses) == 0 {
p.EnvoyGatewayBindAddresses = nil
}
Expand Down Expand Up @@ -403,7 +393,6 @@ func (p *ConsulGatewayProxy) Copy() *ConsulGatewayProxy {
EnvoyGatewayBindTaggedAddresses: p.EnvoyGatewayBindTaggedAddresses,
EnvoyGatewayBindAddresses: binds,
EnvoyGatewayNoDefaultBind: p.EnvoyGatewayNoDefaultBind,
EnvoyDNSDiscoveryType: p.EnvoyDNSDiscoveryType,
Config: config,
}
}
Expand Down
3 changes: 0 additions & 3 deletions api/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ func TestService_ConsulGateway_Canonicalize(t *testing.T) {
EnvoyGatewayBindTaggedAddresses: true,
EnvoyGatewayBindAddresses: make(map[string]*ConsulGatewayBindAddress, 0),
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "",
Config: make(map[string]interface{}, 0),
},
Ingress: &ConsulIngressConfigEntry{
Expand All @@ -290,7 +289,6 @@ func TestService_ConsulGateway_Canonicalize(t *testing.T) {
}
cg.Canonicalize()
require.Equal(t, timeToPtr(5*time.Second), cg.Proxy.ConnectTimeout)
require.Equal(t, "LOGICAL_DNS", cg.Proxy.EnvoyDNSDiscoveryType)
require.Nil(t, cg.Proxy.EnvoyGatewayBindAddresses)
require.Nil(t, cg.Proxy.Config)
require.Nil(t, cg.Ingress.Listeners)
Expand All @@ -314,7 +312,6 @@ func TestService_ConsulGateway_Copy(t *testing.T) {
"listener2": {Address: "10.0.0.1", Port: 2001},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "BAD_TYPE",
Config: map[string]interface{}{
"foo": "bar",
"baz": 3,
Expand Down
4 changes: 0 additions & 4 deletions command/agent/consul/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ func newConnectGateway(serviceName string, connect *structs.ConsulConnect) *api.
envoyConfig["connect_timeout_ms"] = proxy.ConnectTimeout.Milliseconds()
}

if proxy.EnvoyDNSDiscoveryType != "" {
envoyConfig["envoy_dns_discovery_type"] = proxy.EnvoyDNSDiscoveryType
}

if len(proxy.Config) > 0 {
for k, v := range proxy.Config {
envoyConfig[k] = v
Expand Down
6 changes: 1 addition & 5 deletions command/agent/consul/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,13 @@ func TestConnect_newConnectGateway(t *testing.T) {
EnvoyGatewayBindTaggedAddresses: false,
EnvoyGatewayBindAddresses: nil,
EnvoyGatewayNoDefaultBind: false,
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
Config: nil,
},
},
})
require.Equal(t, &api.AgentServiceConnectProxyConfig{
Config: map[string]interface{}{
"connect_timeout_ms": int64(1000),
"envoy_dns_discovery_type": "LOGICAL_DNS",
"connect_timeout_ms": int64(1000),
},
}, result)
})
Expand All @@ -442,7 +440,6 @@ func TestConnect_newConnectGateway(t *testing.T) {
},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{
"foo": 1,
},
Expand All @@ -452,7 +449,6 @@ func TestConnect_newConnectGateway(t *testing.T) {
require.Equal(t, &api.AgentServiceConnectProxyConfig{
Config: map[string]interface{}{
"connect_timeout_ms": int64(1000),
"envoy_dns_discovery_type": "STRICT_DNS",
"envoy_gateway_bind_tagged_addresses": true,
"envoy_gateway_bind_addresses": map[string]*structs.ConsulGatewayBindAddress{
"service1": &structs.ConsulGatewayBindAddress{
Expand Down
1 change: 0 additions & 1 deletion command/agent/job_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,6 @@ func apiConnectGatewayProxyToStructs(in *api.ConsulGatewayProxy) *structs.Consul
EnvoyGatewayBindTaggedAddresses: in.EnvoyGatewayBindTaggedAddresses,
EnvoyGatewayBindAddresses: bindAddresses,
EnvoyGatewayNoDefaultBind: in.EnvoyGatewayNoDefaultBind,
EnvoyDNSDiscoveryType: in.EnvoyDNSDiscoveryType,
Config: helper.CopyMapStringInterface(in.Config),
}
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,7 @@ func TestConversion_apiConnectSidecarServiceProxyToStructs(t *testing.T) {
require.Equal(t, &structs.ConsulProxy{
LocalServiceAddress: "192.168.30.1",
LocalServicePort: 9000,
Config: config,
Config: nil,
Upstreams: []structs.ConsulUpstream{{
DestinationName: "upstream",
}},
Expand Down
1 change: 0 additions & 1 deletion jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,6 @@ func TestParse(t *testing.T) {
"listener2": {Address: "10.0.0.2", Port: 8889},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
Config: map[string]interface{}{"foo": "bar"},
},
Ingress: &api.ConsulIngressConfigEntry{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ job "connect_gateway_ingress" {
port = 8889
}
envoy_gateway_no_default_bind = true
envoy_dns_discovery_type = "LOGICAL_DNS"
config {
foo = "bar"
}
Expand Down
1 change: 0 additions & 1 deletion nomad/job_endpoint_hook_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ func gatewayProxyForBridge(gateway *structs.ConsulGateway) *structs.ConsulGatewa
proxy := new(structs.ConsulGatewayProxy)
if gateway.Proxy != nil {
proxy.ConnectTimeout = gateway.Proxy.ConnectTimeout
proxy.EnvoyDNSDiscoveryType = gateway.Proxy.EnvoyDNSDiscoveryType
proxy.Config = gateway.Proxy.Config
}

Expand Down
11 changes: 4 additions & 7 deletions nomad/job_endpoint_hook_connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,8 @@ func TestJobEndpointConnect_gatewayProxyIsDefault(t *testing.T) {

t.Run("unrelated fields set", func(t *testing.T) {
result := gatewayProxyIsDefault(&structs.ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(2 * time.Second),
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{"foo": 1},
ConnectTimeout: helper.TimeToPtr(2 * time.Second),
Config: map[string]interface{}{"foo": 1},
})
require.True(t, result)
})
Expand Down Expand Up @@ -430,9 +429,8 @@ func TestJobEndpointConnect_gatewayProxyForBridge(t *testing.T) {
t.Run("fill in defaults", func(t *testing.T) {
result := gatewayProxyForBridge(&structs.ConsulGateway{
Proxy: &structs.ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(2 * time.Second),
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{"foo": 1},
ConnectTimeout: helper.TimeToPtr(2 * time.Second),
Config: map[string]interface{}{"foo": 1},
},
Ingress: &structs.ConsulIngressConfigEntry{
Listeners: []*structs.ConsulIngressListener{{
Expand All @@ -446,7 +444,6 @@ func TestJobEndpointConnect_gatewayProxyForBridge(t *testing.T) {
})
require.Equal(t, &structs.ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(2 * time.Second),
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{"foo": 1},
EnvoyGatewayNoDefaultBind: true,
EnvoyGatewayBindTaggedAddresses: false,
Expand Down
1 change: 0 additions & 1 deletion nomad/job_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ func TestJobEndpoint_Register_ConnectIngressGateway_full(t *testing.T) {
},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{
"foo": 1,
"bar": "baz",
Expand Down
8 changes: 0 additions & 8 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,6 @@ func TestTaskGroupDiff(t *testing.T) {
},
},
EnvoyGatewayNoDefaultBind: false,
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
Config: map[string]interface{}{
"foo": 1,
},
Expand Down Expand Up @@ -2704,7 +2703,6 @@ func TestTaskGroupDiff(t *testing.T) {
},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{
"foo": 2,
},
Expand Down Expand Up @@ -3024,12 +3022,6 @@ func TestTaskGroupDiff(t *testing.T) {
Old: "1s",
New: "2s",
},
{
Type: DiffTypeEdited,
Name: "EnvoyDNSDiscoveryType",
Old: "LOGICAL_DNS",
New: "STRICT_DNS",
},
{
Type: DiffTypeEdited,
Name: "EnvoyGatewayBindTaggedAddresses",
Expand Down
11 changes: 0 additions & 11 deletions nomad/structs/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,6 @@ type ConsulGatewayProxy struct {
EnvoyGatewayBindTaggedAddresses bool
EnvoyGatewayBindAddresses map[string]*ConsulGatewayBindAddress
EnvoyGatewayNoDefaultBind bool
EnvoyDNSDiscoveryType string
Config map[string]interface{}
}

Expand All @@ -1301,7 +1300,6 @@ func (p *ConsulGatewayProxy) Copy() *ConsulGatewayProxy {
EnvoyGatewayBindTaggedAddresses: p.EnvoyGatewayBindTaggedAddresses,
EnvoyGatewayBindAddresses: bindAddresses,
EnvoyGatewayNoDefaultBind: p.EnvoyGatewayNoDefaultBind,
EnvoyDNSDiscoveryType: p.EnvoyDNSDiscoveryType,
Config: helper.CopyMapStringInterface(p.Config),
}
}
Expand Down Expand Up @@ -1341,10 +1339,6 @@ func (p *ConsulGatewayProxy) Equals(o *ConsulGatewayProxy) bool {
return false
}

if p.EnvoyDNSDiscoveryType != o.EnvoyDNSDiscoveryType {
return false
}

if !opaqueMapsEqual(p.Config, o.Config) {
return false
}
Expand All @@ -1361,11 +1355,6 @@ func (p *ConsulGatewayProxy) Validate() error {
return fmt.Errorf("Consul Gateway Proxy connection_timeout must be set")
}

dnsTypes := []string{"STRICT_DNS", "LOGICAL_DNS"}
if !helper.SliceStringContains(dnsTypes, p.EnvoyDNSDiscoveryType) {
return fmt.Errorf("Consul Gateway Proxy does not support DNS discovery type %q", p.EnvoyDNSDiscoveryType)
}

for _, bindAddr := range p.EnvoyGatewayBindAddresses {
if err := bindAddr.Validate(); err != nil {
return err
Expand Down
23 changes: 3 additions & 20 deletions nomad/structs/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ var (
"listener2": &ConsulGatewayBindAddress{Address: "10.0.0.1", Port: 2002},
},
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "STRICT_DNS",
Config: map[string]interface{}{
"foo": 1,
},
Expand Down Expand Up @@ -582,10 +581,6 @@ func TestConsulGateway_Equals_ingress(t *testing.T) {
try(t, func(g *gway) { g.Proxy.EnvoyGatewayNoDefaultBind = false })
})

t.Run("mod gateway envoy_dns_discovery_type", func(t *testing.T) {
try(t, func(g *gway) { g.Proxy.EnvoyDNSDiscoveryType = "LOGICAL_DNS" })
})

t.Run("mod gateway config", func(t *testing.T) {
try(t, func(g *gway) {
g.Proxy.Config = map[string]interface{}{
Expand Down Expand Up @@ -733,16 +728,14 @@ func TestConsulGatewayBindAddress_Validate(t *testing.T) {
func TestConsulGatewayProxy_Validate(t *testing.T) {
t.Run("no timeout", func(t *testing.T) {
err := (&ConsulGatewayProxy{
ConnectTimeout: nil,
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
ConnectTimeout: nil,
}).Validate()
require.EqualError(t, err, "Consul Gateway Proxy connection_timeout must be set")
})

t.Run("invalid bind address", func(t *testing.T) {
err := (&ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(1 * time.Second),
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
ConnectTimeout: helper.TimeToPtr(1 * time.Second),
EnvoyGatewayBindAddresses: map[string]*ConsulGatewayBindAddress{
"service1": {
Address: "10.0.0.1",
Expand All @@ -752,18 +745,9 @@ func TestConsulGatewayProxy_Validate(t *testing.T) {
require.EqualError(t, err, "Consul Gateway Bind Address must set valid Port")
})

t.Run("invalid dns discovery type", func(t *testing.T) {
err := (&ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(1 * time.Second),
EnvoyDNSDiscoveryType: "INVALID_DNS",
}).Validate()
require.EqualError(t, err, `Consul Gateway Proxy does not support DNS discovery type "INVALID_DNS"`)
})

t.Run("ok with nothing set", func(t *testing.T) {
err := (&ConsulGatewayProxy{
ConnectTimeout: helper.TimeToPtr(1 * time.Second),
EnvoyDNSDiscoveryType: "LOGICAL_DNS",
ConnectTimeout: helper.TimeToPtr(1 * time.Second),
}).Validate()
require.NoError(t, err)
})
Expand All @@ -778,7 +762,6 @@ func TestConsulGatewayProxy_Validate(t *testing.T) {
}},
EnvoyGatewayBindTaggedAddresses: true,
EnvoyGatewayNoDefaultBind: true,
EnvoyDNSDiscoveryType: "STRICT_DNS",
}).Validate()
require.NoError(t, err)
})
Expand Down
11 changes: 0 additions & 11 deletions vendor/github.com/hashicorp/nomad/api/services.go

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

0 comments on commit 36a743f

Please sign in to comment.