Skip to content

Commit

Permalink
v2: fix protocol propagation to IR clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
zalimeni authored and jmurret committed Oct 25, 2023
1 parent f4d0e29 commit 3b3dd5b
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 452 deletions.
21 changes: 11 additions & 10 deletions agent/xdsv2/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package xdsv2
import (
"errors"
"fmt"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v2beta1"

envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
Expand Down Expand Up @@ -81,7 +82,7 @@ func (pr *ProxyResources) makeClusters(name string) ([]proto.Message, error) {
return clusters, nil
}

func (pr *ProxyResources) makeEnvoyCluster(name string, protocol string, eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyCluster(name string, protocol pbcatalog.Protocol, eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, error) {
if eg != nil {
switch t := eg.Group.(type) {
case *pbproxystate.EndpointGroup_Dynamic:
Expand All @@ -103,7 +104,7 @@ func (pr *ProxyResources) makeEnvoyCluster(name string, protocol string, eg *pbp
return nil, fmt.Errorf("no endpoint group")
}

func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol string, dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol pbcatalog.Protocol, dynamic *pbproxystate.DynamicEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
cluster := &envoy_cluster_v3.Cluster{
Name: name,
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_EDS},
Expand Down Expand Up @@ -153,7 +154,7 @@ func (pr *ProxyResources) makeEnvoyDynamicCluster(name string, protocol string,

}

func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol string, static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol pbcatalog.Protocol, static *pbproxystate.StaticEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
cluster := &envoy_cluster_v3.Cluster{
Name: name,
ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_STATIC},
Expand Down Expand Up @@ -182,11 +183,11 @@ func (pr *ProxyResources) makeEnvoyStaticCluster(name string, protocol string, s
return cluster, nil
}

func (pr *ProxyResources) makeEnvoyDnsCluster(name string, protocol string, dns *pbproxystate.DNSEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyDnsCluster(name string, protocol pbcatalog.Protocol, dns *pbproxystate.DNSEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
return nil, nil
}

func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol string, passthrough *pbproxystate.PassthroughEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol pbcatalog.Protocol, passthrough *pbproxystate.PassthroughEndpointGroup) (*envoy_cluster_v3.Cluster, error) {
cluster := &envoy_cluster_v3.Cluster{
Name: name,
ConnectTimeout: passthrough.Config.ConnectTimeout,
Expand All @@ -207,7 +208,7 @@ func (pr *ProxyResources) makeEnvoyPassthroughCluster(name string, protocol stri
return cluster, nil
}

func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol string, fg *pbproxystate.FailoverGroup) ([]*envoy_cluster_v3.Cluster, error) {
func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol pbcatalog.Protocol, fg *pbproxystate.FailoverGroup) ([]*envoy_cluster_v3.Cluster, error) {
var clusters []*envoy_cluster_v3.Cluster
if fg != nil {
var egNames []string
Expand Down Expand Up @@ -250,8 +251,8 @@ func (pr *ProxyResources) makeEnvoyAggregateCluster(name string, protocol string
return clusters, nil
}

func addLocalAppHttpProtocolOptions(protocol string, c *envoy_cluster_v3.Cluster) error {
if !(protocol == "http2" || protocol == "grpc") {
func addLocalAppHttpProtocolOptions(protocol pbcatalog.Protocol, c *envoy_cluster_v3.Cluster) error {
if !(protocol == pbcatalog.Protocol_PROTOCOL_HTTP2 || protocol == pbcatalog.Protocol_PROTOCOL_GRPC) {
// do not error. returning nil means it won't get set.
return nil
}
Expand All @@ -274,8 +275,8 @@ func addLocalAppHttpProtocolOptions(protocol string, c *envoy_cluster_v3.Cluster
return nil
}

func addHttpProtocolOptions(protocol string, c *envoy_cluster_v3.Cluster) error {
if !(protocol == "http2" || protocol == "grpc") {
func addHttpProtocolOptions(protocol pbcatalog.Protocol, c *envoy_cluster_v3.Cluster) error {
if !(protocol == pbcatalog.Protocol_PROTOCOL_HTTP2 || protocol == pbcatalog.Protocol_PROTOCOL_GRPC) {
// do not error. returning nil means it won't get set.
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (b *Builder) buildDestination(
}
}

b.addCluster(clusterName, endpointGroups, connectTimeout)
b.addCluster(clusterName, endpointGroups, connectTimeout, effectiveProtocol)
}

return b
Expand All @@ -359,6 +359,7 @@ func (b *Builder) addNullRouteCluster() *Builder {
},
},
},
Protocol: pbcatalog.Protocol_PROTOCOL_TCP,
}

b.proxyStateTemplate.ProxyState.Clusters[cluster.Name] = cluster
Expand Down Expand Up @@ -402,6 +403,7 @@ func (b *Builder) addL4ClusterForDirect(clusterName string) *Builder {
},
},
},
Protocol: pbcatalog.Protocol_PROTOCOL_TCP,
}

b.proxyStateTemplate.ProxyState.Clusters[cluster.Name] = cluster
Expand Down Expand Up @@ -573,10 +575,12 @@ func (b *Builder) addCluster(
clusterName string,
endpointGroups []*pbproxystate.EndpointGroup,
connectTimeout *durationpb.Duration,
protocol pbcatalog.Protocol,
) {
cluster := &pbproxystate.Cluster{
Name: clusterName,
AltStatName: clusterName,
Protocol: protocol,
}
switch len(endpointGroups) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,18 @@ func (b *Builder) buildExposePaths(workload *pbcatalog.Workload) {
addExposePathsRouter(exposePath).
buildListener()

var protocol pbcatalog.Protocol
switch exposePath.Protocol {
case pbmesh.ExposePathProtocol_EXPOSE_PATH_PROTOCOL_HTTP:
protocol = pbcatalog.Protocol_PROTOCOL_HTTP
case pbmesh.ExposePathProtocol_EXPOSE_PATH_PROTOCOL_HTTP2:
protocol = pbcatalog.Protocol_PROTOCOL_HTTP2
default:
panic("unsupported expose paths protocol")
}

b.addExposePathsRoute(exposePath, clusterName).
addLocalAppCluster(clusterName, nil).
addLocalAppCluster(clusterName, nil, protocol).
addLocalAppStaticEndpoints(clusterName, exposePath.LocalPathPort)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (b *Builder) BuildLocalApp(workload *pbcatalog.Workload, ctp *pbauth.Comput
if isL7(port.Protocol) {
b.addLocalAppRoute(routeName, clusterName, portName)
}
b.addLocalAppCluster(clusterName, &portName).
b.addLocalAppCluster(clusterName, &portName, port.Protocol).
addLocalAppStaticEndpoints(clusterName, port.GetPort())
}
}
Expand Down Expand Up @@ -410,7 +410,7 @@ func isL7(protocol pbcatalog.Protocol) bool {
return false
}

func (b *Builder) addLocalAppCluster(clusterName string, portName *string) *Builder {
func (b *Builder) addLocalAppCluster(clusterName string, portName *string, protocol pbcatalog.Protocol) *Builder {
// Make cluster for this router destination.
cluster := &pbproxystate.Cluster{
Group: &pbproxystate.Cluster_EndpointGroup{
Expand All @@ -420,6 +420,7 @@ func (b *Builder) addLocalAppCluster(clusterName string, portName *string) *Buil
},
},
},
Protocol: protocol,
}

// configure inbound connections or connection timeout if either is defined
Expand Down Expand Up @@ -448,7 +449,7 @@ func (b *Builder) addLocalAppCluster(clusterName string, portName *string) *Buil
}

func (b *Builder) addBlackHoleCluster() *Builder {
return b.addLocalAppCluster(xdscommon.BlackHoleClusterName, nil)
return b.addLocalAppCluster(xdscommon.BlackHoleClusterName, nil, pbcatalog.Protocol_PROTOCOL_TCP)
}

func (b *Builder) addLocalAppStaticEndpoints(clusterName string, port uint32) {
Expand Down
Loading

0 comments on commit 3b3dd5b

Please sign in to comment.