From 37b49ba5731dd889e9d8cf007ccbff992e06049c Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 4 Jun 2021 08:50:14 -0500 Subject: [PATCH] consul/connect: fix upstream mesh gateway default mode setting This PR fixes the API to _not_ set the default mesh gateway mode. Before, the mode would be set to "none" in Canonicalize, which is incorrect. We should pass through the empty string so that folks can make use of Consul service-defaults Config entries to configure the default mode. --- api/services.go | 10 +++------- api/services_test.go | 14 ++++++++------ vendor/github.com/hashicorp/nomad/api/services.go | 10 +++------- .../content/docs/job-specification/upstreams.mdx | 4 ++-- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/api/services.go b/api/services.go index 365bf848463..c9b74dd1586 100644 --- a/api/services.go +++ b/api/services.go @@ -310,13 +310,9 @@ type ConsulMeshGateway struct { } func (c *ConsulMeshGateway) Canonicalize() { - if c == nil { - return - } - - if c.Mode == "" { - c.Mode = "none" - } + // Mode may be empty string, indicating behavior will defer to Consul + // service-defaults config entry. + return } func (c *ConsulMeshGateway) Copy() *ConsulMeshGateway { diff --git a/api/services_test.go b/api/services_test.go index 14cd3827f8e..2ba4452d1e8 100644 --- a/api/services_test.go +++ b/api/services_test.go @@ -613,13 +613,15 @@ func TestService_ConsulMeshGateway_Canonicalize(t *testing.T) { }) t.Run("unset mode", func(t *testing.T) { - c := &ConsulMeshGateway{ - Mode: "", - } + c := &ConsulMeshGateway{Mode: ""} c.Canonicalize() - require.Equal(t, &ConsulMeshGateway{ - Mode: "none", - }, c) + require.Equal(t, "", c.Mode) + }) + + t.Run("set mode", func(t *testing.T) { + c := &ConsulMeshGateway{Mode: "remote"} + c.Canonicalize() + require.Equal(t, "remote", c.Mode) }) } diff --git a/vendor/github.com/hashicorp/nomad/api/services.go b/vendor/github.com/hashicorp/nomad/api/services.go index 365bf848463..c9b74dd1586 100644 --- a/vendor/github.com/hashicorp/nomad/api/services.go +++ b/vendor/github.com/hashicorp/nomad/api/services.go @@ -310,13 +310,9 @@ type ConsulMeshGateway struct { } func (c *ConsulMeshGateway) Canonicalize() { - if c == nil { - return - } - - if c.Mode == "" { - c.Mode = "none" - } + // Mode may be empty string, indicating behavior will defer to Consul + // service-defaults config entry. + return } func (c *ConsulMeshGateway) Copy() *ConsulMeshGateway { diff --git a/website/content/docs/job-specification/upstreams.mdx b/website/content/docs/job-specification/upstreams.mdx index 1b540d219d1..91bb9bd6cdc 100644 --- a/website/content/docs/job-specification/upstreams.mdx +++ b/website/content/docs/job-specification/upstreams.mdx @@ -94,8 +94,8 @@ job "countdash" { ### `mesh_gateway` Parameters -- `mode` `(string: "default")` - The mode of operation in which to use [Connect Mesh Gateways][mesh_gateways] -Defaults to the mode as determined by the Consul [service-defaults][service_defaults_mode] +- `mode` `(string: "")` - The mode of operation in which to use [Connect Mesh Gateways][mesh_gateways]. + If left unset, the mode will default to the mode as determined by the Consul [service-defaults][service_defaults_mode] configuration for the service. Can be configured with the following modes: - `local` - In this mode the Connect proxy makes its outbound connection to a gateway running in the same datacenter. That gateway is then responsible for