diff --git a/client/allocrunner/consul_hook.go b/client/allocrunner/consul_hook.go index b1385a73771..8fa23078657 100644 --- a/client/allocrunner/consul_hook.go +++ b/client/allocrunner/consul_hook.go @@ -98,13 +98,12 @@ func (h *consulHook) Prerun() error { } func (h *consulHook) prepareConsulTokensForTask(job *structs.Job, task *structs.Task, tgName string, tokens map[string]map[string]string) error { - var consulClusterName string - if task.Consul != nil && task.Consul.Cluster != "" { - consulClusterName = task.Consul.Cluster - } else { - consulClusterName = structs.ConsulDefaultCluster + if task.Consul == nil { + return nil } + consulClusterName := task.Consul.Cluster + // get consul config consulConfig := h.consulConfigs[consulClusterName] diff --git a/nomad/job_endpoint_hook_consul_ce.go b/nomad/job_endpoint_hook_consul_ce.go index 32fa3659f21..320856ef3a9 100644 --- a/nomad/job_endpoint_hook_consul_ce.go +++ b/nomad/job_endpoint_hook_consul_ce.go @@ -44,7 +44,7 @@ func (h jobConsulHook) Validate(job *structs.Job) ([]error, error) { } func (h jobConsulHook) validateCluster(name string) error { - if name != "default" { + if name != structs.ConsulDefaultCluster { return errors.New("non-default Consul cluster requires Nomad Enterprise") } return nil @@ -55,19 +55,19 @@ func (h jobConsulHook) validateCluster(name string) error { func (j jobConsulHook) Mutate(job *structs.Job) (*structs.Job, []error, error) { for _, group := range job.TaskGroups { if group.Consul != nil && group.Consul.Cluster == "" { - group.Consul.Cluster = "default" + group.Consul.Cluster = structs.ConsulDefaultCluster } for _, service := range group.Services { if service.IsConsul() && service.Cluster == "" { - service.Cluster = "default" + service.Cluster = structs.ConsulDefaultCluster } } for _, task := range group.Tasks { for _, service := range task.Services { if service.IsConsul() && service.Cluster == "" { - service.Cluster = "default" + service.Cluster = structs.ConsulDefaultCluster } } }