Skip to content

Commit

Permalink
consul/connect: use block not optional for opaque map (#15765)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoenig authored Jan 12, 2023
1 parent 4698d8d commit 7d2726d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ type ConsulUpstream struct {
Datacenter string `mapstructure:"datacenter" hcl:"datacenter,optional"`
LocalBindAddress string `mapstructure:"local_bind_address" hcl:"local_bind_address,optional"`
MeshGateway *ConsulMeshGateway `mapstructure:"mesh_gateway" hcl:"mesh_gateway,block"`
Config map[string]any `mapstructure:"config" hcl:"config,optional"`
Config map[string]any `mapstructure:"config" hcl:"config,block"`
}

func (cu *ConsulUpstream) Copy() *ConsulUpstream {
Expand Down
16 changes: 16 additions & 0 deletions jobspec2/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/helper/pointer"
"github.com/hashicorp/nomad/jobspec"
"github.com/shoenig/test/must"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -63,6 +64,21 @@ func TestEquivalentToHCL1_ComplexConfig(t *testing.T) {
require.Equal(t, job1, job2)
}

func TestParse_ConnectJob(t *testing.T) {
ci.Parallel(t)

name := "./test-fixtures/connect-example.hcl"
f, err := os.Open(name)
must.NoError(t, err)
t.Cleanup(func() { _ = f.Close() })

job2, err := Parse(name, f)
must.NoError(t, err)

timeout := job2.TaskGroups[0].Services[0].Connect.SidecarService.Proxy.Upstreams[0].Config["connect_timeout_ms"]
must.Eq(t, 9999, timeout)
}

func TestParse_VarsAndFunctions(t *testing.T) {
ci.Parallel(t)

Expand Down
43 changes: 43 additions & 0 deletions jobspec2/test-fixtures/connect-example.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
job "web" {
datacenters = ["dc1"]
group "web" {
network {
mode = "bridge"

port "http" {
static = 80
to = 8080
}
}

service {
name = "website"
port = "8080"

connect {
sidecar_service {
proxy {
upstreams {
destination_name = "database"
local_bind_port = 5432
config {
connect_timeout_ms = 9999
}
}
}
}
}
}

task "httpserver" {
driver = "docker"
env {
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_database}"
}
config {
image = "hashicorp/website:v1"
auth_soft_fail = true
}
}
}
}

0 comments on commit 7d2726d

Please sign in to comment.