Skip to content

Commit

Permalink
client: correct consul block validation in the consul_hook (#18751)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkazmierczak authored Oct 13, 2023
1 parent 0931f2b commit b697de9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions client/allocrunner/consul_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
8 changes: 4 additions & 4 deletions nomad/job_endpoint_hook_consul_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit b697de9

Please sign in to comment.