Skip to content

Commit

Permalink
Fixes based on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanStough committed Feb 2, 2023
1 parent 1013326 commit 8a2ca08
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
11 changes: 0 additions & 11 deletions agent/configentry/merge_service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,6 @@ func MergeServiceConfig(defaults *structs.ServiceConfigResponse, service *struct
// remoteUpstreams contains synthetic Upstreams generated from central config (service-defaults.UpstreamConfigs).
remoteUpstreams := make(map[structs.PeeredServiceName]structs.Upstream)

var hasPeerUpstream bool
for _, us := range defaults.UpstreamConfigs {
if us.Upstream.Peer != "" {
hasPeerUpstream = true
}
}
legacyUpstreams := len(defaults.UpstreamIDConfigs) > 0 || !hasPeerUpstream
if len(defaults.UpstreamIDConfigs) > 0 {
// Handle legacy upstreams. This should be removed in Consul 1.16.
for _, us := range defaults.UpstreamIDConfigs {
Expand Down Expand Up @@ -216,10 +209,6 @@ func MergeServiceConfig(defaults *structs.ServiceConfigResponse, service *struct
}

uid := us.DestinationID()
if legacyUpstreams {
// Erase the peer field when doing a lookup so that configs are found.
uid.Peer = ""
}
localUpstreams[uid] = struct{}{}
remoteCfg, ok := remoteUpstreams[uid]
if !ok {
Expand Down
29 changes: 27 additions & 2 deletions agent/configentry/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,23 @@ func ComputeResolvedServiceConfig(
resolvedConfigs[wildcard] = wildcardUpstreamDefaults
}

// For Consul 1.14.x, service-defaults would apply to either local or peer services as long
// as the `name` matched. We introduce `legacyUpstreams` as a compatibility mode for:
// 1. old agents, that are using the deprecated UpstreamIDs api
// 2. Migrations to 1.15 that do not specify the "peer" field. The behavior should remain the same
// until the config entries are updates.
//
// This should be remove in Consul 1.16
var hasPeerUpstream bool
for _, override := range upstreamOverrides {
if override.Peer != "" {
hclog.Default().Error("*** Found peer name in service-defaults", "name", override.Name)
hasPeerUpstream = true
break
}
}
legacyUpstreams := len(args.UpstreamIDs) > 0 || !hasPeerUpstream

for upstream := range seenUpstreams {
resolvedCfg := make(map[string]interface{})

Expand Down Expand Up @@ -254,8 +271,16 @@ func ComputeResolvedServiceConfig(
}

// Merge in Overrides for the upstream (step 5).
if upstreamOverrides[upstream] != nil {
upstreamOverrides[upstream].MergeInto(resolvedCfg)
if legacyUpstreams {
peerlessUpstream := upstream
peerlessUpstream.Peer = ""
if upstreamOverrides[peerlessUpstream] != nil {
upstreamOverrides[peerlessUpstream].MergeInto(resolvedCfg)
}
} else {
if upstreamOverrides[upstream] != nil {
upstreamOverrides[upstream].MergeInto(resolvedCfg)
}
}

if len(resolvedCfg) > 0 {
Expand Down
2 changes: 0 additions & 2 deletions agent/structs/config_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

"github.com/miekg/dns"

"github.com/hashicorp/consul/api"

"github.com/hashicorp/go-multierror"
"github.com/mitchellh/hashstructure"
"github.com/mitchellh/mapstructure"
Expand Down

0 comments on commit 8a2ca08

Please sign in to comment.