Merge pull request #11927 from hashicorp/b-hcl1-sidecar_task-resources

connect: fix bug where sidecar_task.resources was ignored with hcl1
This commit is contained in:
Seth Hoenig 2022-01-26 06:32:52 -06:00 committed by GitHub
commit b5c5d59fa3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 18 deletions

4
.changelog/11927.txt Normal file
View file

@ -0,0 +1,4 @@
```
release-note:bug
Fixed a bug where connect sidecar resources were ignored when using HCL1
```

View file

@ -104,12 +104,10 @@ func parseService(o *ast.ObjectItem) (*api.Service, error) {
if len(co.Items) > 1 {
return nil, fmt.Errorf("connect '%s': cannot have more than 1 connect stanza", service.Name)
}
c, err := parseConnect(co.Items[0])
if err != nil {
return nil, multierror.Prefix(err, fmt.Sprintf("'%s',", service.Name))
}
service.Connect = c
}
@ -191,33 +189,29 @@ func parseConnect(co *ast.ObjectItem) (*api.ConsulConnect, error) {
// Parse the sidecar_service
o = connectList.Filter("sidecar_service")
if len(o.Items) == 0 {
return &connect, nil
}
if len(o.Items) > 1 {
return nil, fmt.Errorf("only one 'sidecar_service' block allowed per task")
}
r, err := parseSidecarService(o.Items[0])
if err != nil {
return nil, fmt.Errorf("sidecar_service, %v", err)
if len(o.Items) == 1 {
r, err := parseSidecarService(o.Items[0])
if err != nil {
return nil, fmt.Errorf("sidecar_service, %v", err)
}
connect.SidecarService = r
}
connect.SidecarService = r
// Parse the sidecar_task
o = connectList.Filter("sidecar_task")
if len(o.Items) == 0 {
return &connect, nil
}
if len(o.Items) > 1 {
return nil, fmt.Errorf("only one 'sidecar_task' block allowed per task")
}
t, err := parseSidecarTask(o.Items[0])
if err != nil {
return nil, fmt.Errorf("sidecar_task, %v", err)
if len(o.Items) == 1 {
t, err := parseSidecarTask(o.Items[0])
if err != nil {
return nil, fmt.Errorf("sidecar_task, %v", err)
}
connect.SidecarTask = t
}
connect.SidecarTask = t
return &connect, nil
}

View file

@ -1285,6 +1285,30 @@ func TestParse(t *testing.T) {
},
false,
},
{
"tg-service-connect-resources.hcl",
&api.Job{
ID: stringToPtr("sidecar_task_resources"),
Name: stringToPtr("sidecar_task_resources"),
Type: stringToPtr("service"),
TaskGroups: []*api.TaskGroup{{
Name: stringToPtr("group"),
Services: []*api.Service{{
Name: "example",
Connect: &api.ConsulConnect{
SidecarTask: &api.SidecarTask{
Resources: &api.Resources{
CPU: intToPtr(111),
MemoryMB: intToPtr(222),
MemoryMaxMB: intToPtr(333),
},
},
},
}},
}},
},
false,
},
{
"tg-service-connect-proxy.hcl",
&api.Job{

View file

@ -0,0 +1,20 @@
job "sidecar_task_resources" {
type = "service"
group "group" {
service {
name = "example"
connect {
# should still work without sidecar_service being set (i.e. connect gateway)
sidecar_task {
resources {
cpu = 111
memory = 222
memory_max = 333
}
}
}
}
}
}