-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NET-6305] xds: Ensure v2 route match and protocol are populated for gRPC #19343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,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 pbproxystate.Protocol, eg *pbproxystate.EndpointGroup) (*envoy_cluster_v3.Cluster, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this protocol prevents importing pbcatalog code into xds resource code and keeps the IR as the intermediate seam that we have to keep strong ties between our data model and xds. |
||
if eg != nil { | ||
switch t := eg.Group.(type) { | ||
case *pbproxystate.EndpointGroup_Dynamic: | ||
|
@@ -103,7 +103,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 pbproxystate.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}, | ||
|
@@ -153,7 +153,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 pbproxystate.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}, | ||
|
@@ -182,11 +182,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 pbproxystate.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 pbproxystate.Protocol, passthrough *pbproxystate.PassthroughEndpointGroup) (*envoy_cluster_v3.Cluster, error) { | ||
cluster := &envoy_cluster_v3.Cluster{ | ||
Name: name, | ||
ConnectTimeout: passthrough.Config.ConnectTimeout, | ||
|
@@ -207,7 +207,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 pbproxystate.Protocol, fg *pbproxystate.FailoverGroup) ([]*envoy_cluster_v3.Cluster, error) { | ||
var clusters []*envoy_cluster_v3.Cluster | ||
if fg != nil { | ||
var egNames []string | ||
|
@@ -250,8 +250,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 pbproxystate.Protocol, c *envoy_cluster_v3.Cluster) error { | ||
if !(protocol == pbproxystate.Protocol_PROTOCOL_HTTP2 || protocol == pbproxystate.Protocol_PROTOCOL_GRPC) { | ||
// do not error. returning nil means it won't get set. | ||
return nil | ||
} | ||
|
@@ -274,8 +274,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 pbproxystate.Protocol, c *envoy_cluster_v3.Cluster) error { | ||
if !(protocol == pbproxystate.Protocol_PROTOCOL_HTTP2 || protocol == pbproxystate.Protocol_PROTOCOL_GRPC) { | ||
// do not error. returning nil means it won't get set. | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,26 +373,6 @@ func TestValidatePortName(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestValidateProtocol(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these removed by accident? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I added those a while back before I found out about |
||
// this test simply verifies that we accept all enum values specified in our proto | ||
// in order to avoid validator drift. | ||
for name, value := range pbcatalog.Protocol_value { | ||
t.Run(name, func(t *testing.T) { | ||
require.NoError(t, validateProtocol(pbcatalog.Protocol(value))) | ||
}) | ||
} | ||
} | ||
|
||
func TestValidateHealth(t *testing.T) { | ||
// this test simply verifies that we accept all enum values specified in our proto | ||
// in order to avoid validator drift. | ||
for name, value := range pbcatalog.Health_value { | ||
t.Run(name, func(t *testing.T) { | ||
require.NoError(t, validateHealth(pbcatalog.Health(value))) | ||
}) | ||
} | ||
} | ||
|
||
func TestValidateWorkloadAddress(t *testing.T) { | ||
type testCase struct { | ||
addr *pbcatalog.WorkloadAddress | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,31 @@ func TestBuildMultiportImplicitDestinations(t *testing.T) { | |
}, | ||
} | ||
|
||
multiportServiceData := &pbcatalog.Service{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously this test used a shared version of this type of data with other tests and it was causing lots of clobbering and coordination. opted to make this local to the test. |
||
Ports: []*pbcatalog.ServicePort{ | ||
{ | ||
TargetPort: "tcp", | ||
VirtualPort: 7070, | ||
Protocol: pbcatalog.Protocol_PROTOCOL_TCP, | ||
}, | ||
{ | ||
TargetPort: "tcp2", | ||
VirtualPort: 8081, | ||
Protocol: pbcatalog.Protocol_PROTOCOL_TCP, | ||
}, | ||
{ | ||
TargetPort: "http", | ||
VirtualPort: 8080, | ||
Protocol: pbcatalog.Protocol_PROTOCOL_HTTP, | ||
}, | ||
{ | ||
TargetPort: "mesh", | ||
VirtualPort: 20000, | ||
Protocol: pbcatalog.Protocol_PROTOCOL_MESH, | ||
}, | ||
}, | ||
} | ||
|
||
multiportEndpointsData := &pbcatalog.ServiceEndpoints{ | ||
Endpoints: []*pbcatalog.Endpoint{ | ||
{ | ||
|
@@ -57,12 +82,12 @@ func TestBuildMultiportImplicitDestinations(t *testing.T) { | |
} | ||
apiAppService := resourcetest.Resource(pbcatalog.ServiceType, apiApp). | ||
WithTenancy(resource.DefaultNamespacedTenancy()). | ||
WithData(t, serviceData). | ||
WithData(t, multiportServiceData). | ||
Build() | ||
|
||
apiApp2Service := resourcetest.Resource(pbcatalog.ServiceType, apiApp2). | ||
WithTenancy(resource.DefaultNamespacedTenancy()). | ||
WithData(t, serviceData). | ||
WithData(t, multiportServiceData). | ||
Build() | ||
|
||
apiAppEndpoints := resourcetest.Resource(pbcatalog.ServiceEndpointsType, apiApp). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proxystate cluster.Protocol is now an enumeration. so we need to convert the string from config entry to the protocol enum.