Skip to content

Commit

Permalink
support gateway mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Jul 22, 2021
1 parent f5069ab commit 09903f4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 9 deletions.
31 changes: 22 additions & 9 deletions jobspec/parse_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func parseGateway(o *ast.ObjectItem) (*api.ConsulGateway, error) {
"proxy",
"ingress",
"terminating",
"mesh",
}

if err := checkHCLKeys(o.Val, valid); err != nil {
Expand All @@ -242,6 +243,7 @@ func parseGateway(o *ast.ObjectItem) (*api.ConsulGateway, error) {
delete(m, "proxy")
delete(m, "ingress")
delete(m, "terminating")
delete(m, "mesh")

dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
Expand Down Expand Up @@ -275,30 +277,41 @@ func parseGateway(o *ast.ObjectItem) (*api.ConsulGateway, error) {
gateway.Proxy = proxy

// extract and parse the ingress block
io := listVal.Filter("ingress")
if len(io.Items) == 1 {
if io := listVal.Filter("ingress"); len(io.Items) > 0 {
if len(io.Items) > 1 {
return nil, fmt.Errorf("ingress, %s", "multiple ingress stanzas not allowed")
}

ingress, err := parseIngressConfigEntry(io.Items[0])
if err != nil {
return nil, fmt.Errorf("ingress, %v", err)
}
gateway.Ingress = ingress
}

if len(io.Items) > 1 {
return nil, fmt.Errorf("ingress, %s", "multiple ingress stanzas not allowed")
}
if to := listVal.Filter("terminating"); len(to.Items) > 0 {
if len(to.Items) > 1 {
return nil, fmt.Errorf("terminating, %s", "multiple terminating stanzas not allowed")
}

to := listVal.Filter("terminating")
if len(to.Items) == 1 {
terminating, err := parseTerminatingConfigEntry(to.Items[0])
if err != nil {
return nil, fmt.Errorf("terminating, %v", err)
}
gateway.Terminating = terminating
}

if len(to.Items) > 1 {
return nil, fmt.Errorf("terminating, %s", "multiple terminating stanzas not allowed")
if mo := listVal.Filter("mesh"); len(mo.Items) > 0 {
if len(mo.Items) > 1 {
return nil, fmt.Errorf("mesh, %s", "multiple mesh stanzas not allowed")
}

// mesh should have no keys
if err := checkHCLKeys(mo.Items[0].Val, []string{}); err != nil {
return nil, fmt.Errorf("mesh, %s", err)
}

gateway.Mesh = &api.ConsulMeshConfigEntry{}
}

return &gateway, nil
Expand Down
22 changes: 22 additions & 0 deletions jobspec/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,28 @@ func TestParse(t *testing.T) {
},
false,
},
{
"tg-service-connect-gateway-mesh.hcl",
&api.Job{
ID: stringToPtr("connect_gateway_mesh"),
Name: stringToPtr("connect_gateway_mesh"),
TaskGroups: []*api.TaskGroup{{
Name: stringToPtr("group"),
Services: []*api.Service{{
Name: "mesh-gateway-service",
Connect: &api.ConsulConnect{
Gateway: &api.ConsulGateway{
Proxy: &api.ConsulGatewayProxy{
Config: map[string]interface{}{"foo": "bar"},
},
Mesh: &api.ConsulMeshConfigEntry{},
},
},
}},
}},
},
false,
},
{
"tg-scaling-policy-minimal.hcl",
&api.Job{
Expand Down
19 changes: 19 additions & 0 deletions jobspec/test-fixtures/tg-service-connect-gateway-mesh.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
job "connect_gateway_mesh" {
group "group" {
service {
name = "mesh-gateway-service"

connect {
gateway {
proxy {
config {
foo = "bar"
}
}

mesh {}
}
}
}
}
}

0 comments on commit 09903f4

Please sign in to comment.