From 33fcc83d000f521cdb549019c540589443fa166c Mon Sep 17 00:00:00 2001 From: "R.B. Boyer" Date: Wed, 30 Mar 2022 13:27:49 -0500 Subject: [PATCH] fail on error and use ptypes.MarshalAny for now instead of anypb.New --- agent/xds/clusters.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index fac6d0cfd2..d9906058d5 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -488,7 +488,9 @@ func (s *ResourceGenerator) makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot, nam protocol = cfg.Protocol } if protocol == "http2" || protocol == "grpc" { - s.setHttp2ProtocolOptions(c) + if err := s.setHttp2ProtocolOptions(c); err != nil { + return c, err + } } return c, err @@ -539,7 +541,9 @@ func (s *ResourceGenerator) makeUpstreamClusterForPreparedQuery(upstream structs OutlierDetection: ToOutlierDetection(cfg.PassiveHealthCheck), } if cfg.Protocol == "http2" || cfg.Protocol == "grpc" { - s.setHttp2ProtocolOptions(c) + if err := s.setHttp2ProtocolOptions(c); err != nil { + return c, err + } } } @@ -744,7 +748,9 @@ func (s *ResourceGenerator) makeUpstreamClustersForDiscoveryChain( } if proto == "http2" || proto == "grpc" { - s.setHttp2ProtocolOptions(c) + if err := s.setHttp2ProtocolOptions(c); err != nil { + return nil, err + } } commonTLSContext := makeCommonTLSContextFromLeafWithoutParams(cfgSnap, cfgSnap.Leaf()) @@ -1040,8 +1046,8 @@ func injectLBToCluster(ec *structs.LoadBalancer, c *envoy_cluster_v3.Cluster) er return nil } -func (s *ResourceGenerator) setHttp2ProtocolOptions(c *envoy_cluster_v3.Cluster) { - typedExtensionProtocolOptions := &envoy_upstreams_v3.HttpProtocolOptions{ +func (s *ResourceGenerator) setHttp2ProtocolOptions(c *envoy_cluster_v3.Cluster) error { + cfg := &envoy_upstreams_v3.HttpProtocolOptions{ UpstreamProtocolOptions: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig_{ ExplicitHttpConfig: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig{ ProtocolConfig: &envoy_upstreams_v3.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{ @@ -1050,10 +1056,13 @@ func (s *ResourceGenerator) setHttp2ProtocolOptions(c *envoy_cluster_v3.Cluster) }, }, } - typedExtensionProtocolOptionsEncoded, err := anypb.New(typedExtensionProtocolOptions) + any, err := ptypes.MarshalAny(cfg) if err != nil { - s.Logger.Warn("failed to convert http protocol options to anypb") + return err + } + c.TypedExtensionProtocolOptions = map[string]*anypb.Any{ + "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": any, } - c.TypedExtensionProtocolOptions = make(map[string]*anypb.Any) - c.TypedExtensionProtocolOptions["envoy.extensions.upstreams.http.v3.HttpProtocolOptions"] = typedExtensionProtocolOptionsEncoded + + return nil }