Skip to content

Commit

Permalink
consul/connect: fix upstream mesh gateway default mode setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shoenig committed Jun 4, 2021
1 parent 312161c commit 37b49ba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
10 changes: 3 additions & 7 deletions api/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions api/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
10 changes: 3 additions & 7 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.

4 changes: 2 additions & 2 deletions website/content/docs/job-specification/upstreams.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 37b49ba

Please sign in to comment.