2020-12-24 19:11:13 +00:00
|
|
|
package proxycfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/cache"
|
|
|
|
cachetype "github.com/hashicorp/consul/agent/cache-types"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
type handlerConnectProxy struct {
|
|
|
|
handlerState
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize sets up the watches needed based on current proxy registration
|
|
|
|
// state.
|
|
|
|
func (s *handlerConnectProxy) initialize(ctx context.Context) (ConfigSnapshot, error) {
|
|
|
|
snap := newConfigSnapshotFromServiceInstance(s.serviceInstance, s.stateConfig)
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.DiscoveryChain = make(map[UpstreamID]*structs.CompiledDiscoveryChain)
|
|
|
|
snap.ConnectProxy.WatchedDiscoveryChains = make(map[UpstreamID]context.CancelFunc)
|
|
|
|
snap.ConnectProxy.WatchedUpstreams = make(map[UpstreamID]map[string]context.CancelFunc)
|
|
|
|
snap.ConnectProxy.WatchedUpstreamEndpoints = make(map[UpstreamID]map[string]structs.CheckServiceNodes)
|
|
|
|
snap.ConnectProxy.WatchedGateways = make(map[UpstreamID]map[string]context.CancelFunc)
|
|
|
|
snap.ConnectProxy.WatchedGatewayEndpoints = make(map[UpstreamID]map[string]structs.CheckServiceNodes)
|
2020-12-24 19:11:13 +00:00
|
|
|
snap.ConnectProxy.WatchedServiceChecks = make(map[structs.ServiceID][]structs.CheckType)
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.PreparedQueryEndpoints = make(map[UpstreamID]structs.CheckServiceNodes)
|
|
|
|
snap.ConnectProxy.UpstreamConfig = make(map[UpstreamID]*structs.Upstream)
|
2022-01-28 03:52:26 +00:00
|
|
|
snap.ConnectProxy.PassthroughUpstreams = make(map[UpstreamID]map[string]map[string]struct{})
|
2022-01-28 06:49:06 +00:00
|
|
|
snap.ConnectProxy.PassthroughIndices = make(map[string]indexedTarget)
|
2020-12-24 19:11:13 +00:00
|
|
|
|
|
|
|
// Watch for root changes
|
|
|
|
err := s.cache.Notify(ctx, cachetype.ConnectCARootName, &structs.DCSpecificRequest{
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token},
|
|
|
|
Source: *s.source,
|
|
|
|
}, rootsWatchID, s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch the leaf cert
|
|
|
|
err = s.cache.Notify(ctx, cachetype.ConnectCALeafName, &cachetype.ConnectCALeafRequest{
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
Token: s.token,
|
|
|
|
Service: s.proxyCfg.DestinationServiceName,
|
|
|
|
EnterpriseMeta: s.proxyID.EnterpriseMeta,
|
|
|
|
}, leafWatchID, s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch for intention updates
|
|
|
|
err = s.cache.Notify(ctx, cachetype.IntentionMatchName, &structs.IntentionQueryRequest{
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token},
|
|
|
|
Match: &structs.IntentionQueryMatch{
|
|
|
|
Type: structs.IntentionMatchDestination,
|
|
|
|
Entries: []structs.IntentionMatchEntry{
|
|
|
|
{
|
|
|
|
Namespace: s.proxyID.NamespaceOrDefault(),
|
2021-09-15 04:27:39 +00:00
|
|
|
Partition: s.proxyID.PartitionOrDefault(),
|
2020-12-24 19:11:13 +00:00
|
|
|
Name: s.proxyCfg.DestinationServiceName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, intentionsWatchID, s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch for service check updates
|
|
|
|
err = s.cache.Notify(ctx, cachetype.ServiceHTTPChecksName, &cachetype.ServiceHTTPChecksRequest{
|
|
|
|
ServiceID: s.proxyCfg.DestinationServiceID,
|
|
|
|
EnterpriseMeta: s.proxyID.EnterpriseMeta,
|
|
|
|
}, svcChecksWatchIDPrefix+structs.ServiceIDString(s.proxyCfg.DestinationServiceID, &s.proxyID.EnterpriseMeta), s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if s.proxyCfg.Mode == structs.ProxyModeTransparent {
|
|
|
|
// When in transparent proxy we will infer upstreams from intentions with this source
|
|
|
|
err := s.cache.Notify(ctx, cachetype.IntentionUpstreamsName, &structs.ServiceSpecificRequest{
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token},
|
|
|
|
ServiceName: s.proxyCfg.DestinationServiceName,
|
2021-08-19 20:09:42 +00:00
|
|
|
EnterpriseMeta: s.proxyID.EnterpriseMeta,
|
2020-12-24 19:11:13 +00:00
|
|
|
}, intentionUpstreamsID, s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = s.cache.Notify(ctx, cachetype.ConfigEntryName, &structs.ConfigEntryQuery{
|
|
|
|
Kind: structs.MeshConfig,
|
|
|
|
Name: structs.MeshConfigMesh,
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token},
|
2021-09-17 23:19:42 +00:00
|
|
|
EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition(s.proxyID.PartitionOrDefault()),
|
2020-12-24 19:11:13 +00:00
|
|
|
}, meshConfigEntryID, s.ch)
|
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watch for updates to service endpoints for all upstreams
|
|
|
|
for i := range s.proxyCfg.Upstreams {
|
|
|
|
u := s.proxyCfg.Upstreams[i]
|
|
|
|
|
2022-01-20 16:12:04 +00:00
|
|
|
uid := NewUpstreamID(&u)
|
|
|
|
|
2020-12-24 19:11:13 +00:00
|
|
|
// Store defaults keyed under wildcard so they can be applied to centrally configured upstreams
|
|
|
|
if u.DestinationName == structs.WildcardSpecifier {
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.UpstreamConfig[uid] = &u
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// This can be true if the upstream is a synthetic entry populated from centralized upstream config.
|
|
|
|
// Watches should not be created for them.
|
|
|
|
if u.CentrallyConfigured {
|
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.UpstreamConfig[uid] = &u
|
2020-12-24 19:11:13 +00:00
|
|
|
|
|
|
|
dc := s.source.Datacenter
|
|
|
|
if u.Datacenter != "" {
|
|
|
|
dc = u.Datacenter
|
|
|
|
}
|
|
|
|
if s.proxyCfg.Mode == structs.ProxyModeTransparent && (dc == "" || dc == s.source.Datacenter) {
|
|
|
|
// In transparent proxy mode, watches for upstreams in the local DC are handled by the IntentionUpstreams watch.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-12-13 17:43:33 +00:00
|
|
|
// Default the partition and namespace to the namespace of this proxy service.
|
2021-09-07 20:29:32 +00:00
|
|
|
partition := s.proxyID.PartitionOrDefault()
|
|
|
|
if u.DestinationPartition != "" {
|
|
|
|
partition = u.DestinationPartition
|
|
|
|
}
|
2021-12-13 17:43:33 +00:00
|
|
|
ns := s.proxyID.NamespaceOrDefault()
|
|
|
|
if u.DestinationNamespace != "" {
|
|
|
|
ns = u.DestinationNamespace
|
|
|
|
}
|
2021-09-07 20:29:32 +00:00
|
|
|
|
2020-12-24 19:11:13 +00:00
|
|
|
cfg, err := parseReducedUpstreamConfig(u.Config)
|
|
|
|
if err != nil {
|
|
|
|
// Don't hard fail on a config typo, just warn. We'll fall back on
|
|
|
|
// the plain discovery chain if there is an error so it's safe to
|
|
|
|
// continue.
|
|
|
|
s.logger.Warn("failed to parse upstream config",
|
2022-01-20 16:12:04 +00:00
|
|
|
"upstream", uid.String(),
|
2020-12-24 19:11:13 +00:00
|
|
|
"error", err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch u.DestinationType {
|
|
|
|
case structs.UpstreamDestTypePreparedQuery:
|
|
|
|
err = s.cache.Notify(ctx, cachetype.PreparedQueryName, &structs.PreparedQueryExecuteRequest{
|
|
|
|
Datacenter: dc,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token, MaxAge: defaultPreparedQueryPollInterval},
|
|
|
|
QueryIDOrName: u.DestinationName,
|
|
|
|
Connect: true,
|
|
|
|
Source: *s.source,
|
2022-01-20 16:12:04 +00:00
|
|
|
}, "upstream:"+uid.String(), s.ch)
|
2020-12-24 19:11:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return snap, err
|
|
|
|
}
|
|
|
|
|
|
|
|
case structs.UpstreamDestTypeService:
|
|
|
|
fallthrough
|
|
|
|
|
2021-09-07 20:29:32 +00:00
|
|
|
case "":
|
2020-12-24 19:11:13 +00:00
|
|
|
err = s.cache.Notify(ctx, cachetype.CompiledDiscoveryChainName, &structs.DiscoveryChainRequest{
|
|
|
|
Datacenter: s.source.Datacenter,
|
|
|
|
QueryOptions: structs.QueryOptions{Token: s.token},
|
|
|
|
Name: u.DestinationName,
|
|
|
|
EvaluateInDatacenter: dc,
|
|
|
|
EvaluateInNamespace: ns,
|
2021-09-07 20:29:32 +00:00
|
|
|
EvaluateInPartition: partition,
|
2020-12-24 19:11:13 +00:00
|
|
|
OverrideMeshGateway: s.proxyCfg.MeshGateway.OverlayWith(u.MeshGateway),
|
|
|
|
OverrideProtocol: cfg.Protocol,
|
|
|
|
OverrideConnectTimeout: cfg.ConnectTimeout(),
|
2022-01-20 16:12:04 +00:00
|
|
|
}, "discovery-chain:"+uid.String(), s.ch)
|
2020-12-24 19:11:13 +00:00
|
|
|
if err != nil {
|
2022-01-20 16:12:04 +00:00
|
|
|
return snap, fmt.Errorf("failed to watch discovery chain for %s: %v", uid.String(), err)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return snap, fmt.Errorf("unknown upstream type: %q", u.DestinationType)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return snap, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *handlerConnectProxy) handleUpdate(ctx context.Context, u cache.UpdateEvent, snap *ConfigSnapshot) error {
|
|
|
|
if u.Err != nil {
|
|
|
|
return fmt.Errorf("error filling agent cache: %v", u.Err)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case u.CorrelationID == rootsWatchID:
|
|
|
|
roots, ok := u.Result.(*structs.IndexedCARoots)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for response: %T", u.Result)
|
|
|
|
}
|
|
|
|
snap.Roots = roots
|
|
|
|
case u.CorrelationID == intentionsWatchID:
|
|
|
|
resp, ok := u.Result.(*structs.IndexedIntentionMatches)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for response: %T", u.Result)
|
|
|
|
}
|
|
|
|
if len(resp.Matches) > 0 {
|
|
|
|
// RPC supports matching multiple services at once but we only ever
|
|
|
|
// query with the one service we represent currently so just pick
|
|
|
|
// the one result set up.
|
|
|
|
snap.ConnectProxy.Intentions = resp.Matches[0]
|
|
|
|
}
|
|
|
|
snap.ConnectProxy.IntentionsSet = true
|
|
|
|
|
|
|
|
case u.CorrelationID == intentionUpstreamsID:
|
|
|
|
resp, ok := u.Result.(*structs.IndexedServiceList)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for response %T", u.Result)
|
|
|
|
}
|
|
|
|
|
2022-01-20 16:12:04 +00:00
|
|
|
seenUpstreams := make(map[UpstreamID]struct{})
|
2020-12-24 19:11:13 +00:00
|
|
|
for _, svc := range resp.Services {
|
2022-01-20 16:12:04 +00:00
|
|
|
uid := NewUpstreamIDFromServiceName(svc)
|
|
|
|
|
|
|
|
seenUpstreams[uid] = struct{}{}
|
2020-12-24 19:11:13 +00:00
|
|
|
|
|
|
|
cfgMap := make(map[string]interface{})
|
2022-01-20 16:12:04 +00:00
|
|
|
u, ok := snap.ConnectProxy.UpstreamConfig[uid]
|
2020-12-24 19:11:13 +00:00
|
|
|
if ok {
|
|
|
|
cfgMap = u.Config
|
|
|
|
} else {
|
|
|
|
// Use the centralized upstream defaults if they exist and there isn't specific configuration for this upstream
|
|
|
|
// This is only relevant to upstreams from intentions because for explicit upstreams the defaulting is handled
|
|
|
|
// by the ResolveServiceConfig endpoint.
|
2021-09-17 23:36:20 +00:00
|
|
|
wildcardSID := structs.NewServiceID(structs.WildcardSpecifier, s.proxyID.WithWildcardNamespace())
|
2022-01-20 16:12:04 +00:00
|
|
|
wildcardUID := NewUpstreamIDFromServiceID(wildcardSID)
|
|
|
|
defaults, ok := snap.ConnectProxy.UpstreamConfig[wildcardUID]
|
2020-12-24 19:11:13 +00:00
|
|
|
if ok {
|
|
|
|
u = defaults
|
|
|
|
cfgMap = defaults.Config
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.UpstreamConfig[uid] = defaults
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := parseReducedUpstreamConfig(cfgMap)
|
|
|
|
if err != nil {
|
|
|
|
// Don't hard fail on a config typo, just warn. We'll fall back on
|
|
|
|
// the plain discovery chain if there is an error so it's safe to
|
|
|
|
// continue.
|
|
|
|
s.logger.Warn("failed to parse upstream config",
|
2022-01-20 16:12:04 +00:00
|
|
|
"upstream", uid,
|
2020-12-24 19:11:13 +00:00
|
|
|
"error", err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
meshGateway := s.proxyCfg.MeshGateway
|
|
|
|
if u != nil {
|
|
|
|
meshGateway = meshGateway.OverlayWith(u.MeshGateway)
|
|
|
|
}
|
|
|
|
watchOpts := discoveryChainWatchOpts{
|
2022-01-20 16:12:04 +00:00
|
|
|
id: NewUpstreamIDFromServiceName(svc),
|
2020-12-24 19:11:13 +00:00
|
|
|
name: svc.Name,
|
|
|
|
namespace: svc.NamespaceOrDefault(),
|
2021-09-16 19:31:19 +00:00
|
|
|
partition: svc.PartitionOrDefault(),
|
2020-12-24 19:11:13 +00:00
|
|
|
datacenter: s.source.Datacenter,
|
|
|
|
cfg: cfg,
|
|
|
|
meshGateway: meshGateway,
|
|
|
|
}
|
|
|
|
up := &handlerUpstreams{handlerState: s.handlerState}
|
|
|
|
err = up.watchDiscoveryChain(ctx, snap, watchOpts)
|
|
|
|
if err != nil {
|
2022-01-20 16:12:04 +00:00
|
|
|
return fmt.Errorf("failed to watch discovery chain for %s: %v", uid, err)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
snap.ConnectProxy.IntentionUpstreams = seenUpstreams
|
2020-12-24 19:11:13 +00:00
|
|
|
|
|
|
|
// Clean up data from services that were not in the update
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid, targets := range snap.ConnectProxy.WatchedUpstreams {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
2021-12-13 21:56:17 +00:00
|
|
|
for _, cancelFn := range targets {
|
|
|
|
cancelFn()
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
delete(snap.ConnectProxy.WatchedUpstreams, uid)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid := range snap.ConnectProxy.WatchedUpstreamEndpoints {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
|
|
|
delete(snap.ConnectProxy.WatchedUpstreamEndpoints, uid)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid, cancelMap := range snap.ConnectProxy.WatchedGateways {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
2021-12-13 21:56:17 +00:00
|
|
|
for _, cancelFn := range cancelMap {
|
|
|
|
cancelFn()
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
delete(snap.ConnectProxy.WatchedGateways, uid)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid := range snap.ConnectProxy.WatchedGatewayEndpoints {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
|
|
|
delete(snap.ConnectProxy.WatchedGatewayEndpoints, uid)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid, cancelFn := range snap.ConnectProxy.WatchedDiscoveryChains {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2020-12-24 19:11:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
2020-12-24 19:11:13 +00:00
|
|
|
cancelFn()
|
2022-01-20 16:12:04 +00:00
|
|
|
delete(snap.ConnectProxy.WatchedDiscoveryChains, uid)
|
2021-12-13 22:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 06:49:06 +00:00
|
|
|
for uid := range snap.ConnectProxy.PassthroughUpstreams {
|
2022-01-28 03:52:26 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
|
|
|
delete(snap.ConnectProxy.PassthroughUpstreams, uid)
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 06:49:06 +00:00
|
|
|
for addr, indexed := range snap.ConnectProxy.PassthroughIndices {
|
|
|
|
if _, ok := seenUpstreams[indexed.upstreamID]; !ok {
|
|
|
|
delete(snap.ConnectProxy.PassthroughIndices, addr)
|
|
|
|
}
|
|
|
|
}
|
2022-01-28 03:52:26 +00:00
|
|
|
|
2021-12-13 22:40:37 +00:00
|
|
|
// These entries are intentionally handled separately from the WatchedDiscoveryChains above.
|
|
|
|
// There have been situations where a discovery watch was cancelled, then fired.
|
|
|
|
// That update event then re-populated the DiscoveryChain map entry, which wouldn't get cleaned up
|
|
|
|
// since there was no known watch for it.
|
2022-01-20 16:12:04 +00:00
|
|
|
for uid := range snap.ConnectProxy.DiscoveryChain {
|
|
|
|
if upstream, ok := snap.ConnectProxy.UpstreamConfig[uid]; ok && upstream.Datacenter != "" && upstream.Datacenter != s.source.Datacenter {
|
2021-12-13 22:40:37 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-01-20 16:12:04 +00:00
|
|
|
if _, ok := seenUpstreams[uid]; !ok {
|
|
|
|
delete(snap.ConnectProxy.DiscoveryChain, uid)
|
2020-12-24 19:11:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
case strings.HasPrefix(u.CorrelationID, "upstream:"+preparedQueryIDPrefix):
|
|
|
|
resp, ok := u.Result.(*structs.PreparedQueryExecuteResponse)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for response: %T", u.Result)
|
|
|
|
}
|
|
|
|
pq := strings.TrimPrefix(u.CorrelationID, "upstream:")
|
2022-01-20 16:12:04 +00:00
|
|
|
uid := UpstreamIDFromString(pq)
|
|
|
|
snap.ConnectProxy.PreparedQueryEndpoints[uid] = resp.Nodes
|
2020-12-24 19:11:13 +00:00
|
|
|
|
|
|
|
case strings.HasPrefix(u.CorrelationID, svcChecksWatchIDPrefix):
|
|
|
|
resp, ok := u.Result.([]structs.CheckType)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for service checks response: %T, want: []structs.CheckType", u.Result)
|
|
|
|
}
|
|
|
|
svcID := structs.ServiceIDFromString(strings.TrimPrefix(u.CorrelationID, svcChecksWatchIDPrefix))
|
|
|
|
snap.ConnectProxy.WatchedServiceChecks[svcID] = resp
|
|
|
|
|
|
|
|
case u.CorrelationID == meshConfigEntryID:
|
|
|
|
resp, ok := u.Result.(*structs.ConfigEntryResponse)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for response: %T", u.Result)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Entry != nil {
|
|
|
|
meshConf, ok := resp.Entry.(*structs.MeshConfigEntry)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("invalid type for config entry: %T", resp.Entry)
|
|
|
|
}
|
|
|
|
snap.ConnectProxy.MeshConfig = meshConf
|
|
|
|
} else {
|
|
|
|
snap.ConnectProxy.MeshConfig = nil
|
|
|
|
}
|
|
|
|
snap.ConnectProxy.MeshConfigSet = true
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (*handlerUpstreams)(s).handleUpdateUpstreams(ctx, u, snap)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|