Parse `job > group > consul` block in HCL1 (#11423)
This commit is contained in:
parent
4fb5b8b6e7
commit
71643263a6
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
cli: Fix support for `group.consul` field in the HCLv1 parser
|
||||
```
|
|
@ -40,6 +40,7 @@ func parseGroups(result *api.Job, list *ast.ObjectList) error {
|
|||
valid := []string{
|
||||
"count",
|
||||
"constraint",
|
||||
"consul",
|
||||
"affinity",
|
||||
"restart",
|
||||
"meta",
|
||||
|
@ -67,6 +68,7 @@ func parseGroups(result *api.Job, list *ast.ObjectList) error {
|
|||
}
|
||||
|
||||
delete(m, "constraint")
|
||||
delete(m, "consul")
|
||||
delete(m, "affinity")
|
||||
delete(m, "meta")
|
||||
delete(m, "task")
|
||||
|
@ -104,6 +106,13 @@ func parseGroups(result *api.Job, list *ast.ObjectList) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Parse consul
|
||||
if o := listVal.Filter("consul"); len(o.Items) > 0 {
|
||||
if err := parseConsul(&g.Consul, o); err != nil {
|
||||
return multierror.Prefix(err, fmt.Sprintf("'%s', consul ->", n))
|
||||
}
|
||||
}
|
||||
|
||||
// Parse affinities
|
||||
if o := listVal.Filter("affinity"); len(o.Items) > 0 {
|
||||
if err := parseAffinities(&g.Affinities, o); err != nil {
|
||||
|
@ -228,6 +237,37 @@ func parseGroups(result *api.Job, list *ast.ObjectList) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func parseConsul(result **api.Consul, list *ast.ObjectList) error {
|
||||
list = list.Elem()
|
||||
if len(list.Items) > 1 {
|
||||
return fmt.Errorf("only one 'consul' block allowed")
|
||||
}
|
||||
|
||||
// Get our consul object
|
||||
obj := list.Items[0]
|
||||
|
||||
// Check for invalid keys
|
||||
valid := []string{
|
||||
"namespace",
|
||||
}
|
||||
if err := checkHCLKeys(obj.Val, valid); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var m map[string]interface{}
|
||||
if err := hcl.DecodeObject(&m, obj.Val); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var consul api.Consul
|
||||
if err := mapstructure.WeakDecode(m, &consul); err != nil {
|
||||
return err
|
||||
}
|
||||
*result = &consul
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseEphemeralDisk(result **api.EphemeralDisk, list *ast.ObjectList) error {
|
||||
list = list.Elem()
|
||||
if len(list.Items) > 1 {
|
||||
|
|
|
@ -1671,6 +1671,22 @@ func TestParse(t *testing.T) {
|
|||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"consul-namespace.hcl",
|
||||
&api.Job{
|
||||
ID: stringToPtr("consul-namespace"),
|
||||
Name: stringToPtr("consul-namespace"),
|
||||
TaskGroups: []*api.TaskGroup{
|
||||
{
|
||||
Name: stringToPtr("group"),
|
||||
Consul: &api.Consul{
|
||||
Namespace: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"multiregion.hcl",
|
||||
&api.Job{
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
job "consul-namespace" {
|
||||
group "group" {
|
||||
consul {
|
||||
namespace = "foo"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue