consul: fix lookups of default cluster across upgrades (#18945)

Allocations that were created before Nomad 1.7 will not have the cluster field
set for their Consul blocks. While this can be corrected server-side, that
doesn't help allocations already on clients.
This commit is contained in:
Tim Gross
2023-11-01 10:11:54 -04:00
committed by GitHub
parent 4ec27a97d1
commit d62213a135
3 changed files with 16 additions and 3 deletions

View File

@@ -180,7 +180,12 @@ func (h *consulHook) prepareConsulTokensForServices(services []*structs.Service,
continue
}
if err := h.getConsulTokens(service.Cluster, service.Identity.Name, tokens, req); err != nil {
cluster := service.Cluster
if cluster == "" {
cluster = structs.ConsulDefaultCluster
}
if err := h.getConsulTokens(cluster, service.Identity.Name, tokens, req); err != nil {
mErr.Errors = append(mErr.Errors, err)
continue
}

View File

@@ -267,7 +267,11 @@ func (h *groupServiceHook) getWorkloadServicesLocked() *serviceregistration.Work
tokens := map[string]string{}
for _, service := range h.services {
if token, ok := allocTokens[service.Cluster][service.MakeUniqueIdentityName()]; ok {
cluster := service.Cluster
if cluster == "" {
cluster = structs.ConsulDefaultCluster
}
if token, ok := allocTokens[cluster][service.MakeUniqueIdentityName()]; ok {
tokens[service.Name] = token
}
}

View File

@@ -234,7 +234,11 @@ func (h *serviceHook) getWorkloadServices() *serviceregistration.WorkloadService
tokens := map[string]string{}
for _, service := range h.services {
if token, ok := allocTokens[service.Cluster][service.MakeUniqueIdentityName()]; ok {
cluster := service.Cluster
if cluster == "" {
cluster = structs.ConsulDefaultCluster
}
if token, ok := allocTokens[cluster][service.MakeUniqueIdentityName()]; ok {
tokens[service.Name] = token
}
}