Skip to content
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

[Experiment][Don't review]send alternate rsrc version #290

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/cache/v2/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cache

import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"

cluster "github.com/envoyproxy/go-control-plane/envoy/api/v2"
endpoint "github.com/envoyproxy/go-control-plane/envoy/api/v2"
Expand Down Expand Up @@ -69,15 +70,18 @@ func GetResourceName(res types.Resource) string {
}

// MarshalResource converts the Resource to MarshaledResource
func MarshalResource(resource types.Resource) (types.MarshaledResource, error) {
func MarshalResource(rsrc types.Resource, typeURL string) (*any.Any, error) {
b := proto.NewBuffer(nil)
b.SetDeterministic(true)
err := b.Marshal(resource)
err := b.Marshal(rsrc)
if err != nil {
return nil, err
}

return b.Bytes(), nil
return &any.Any{
TypeUrl: resource.ConvertTypeURL(typeURL),
Value: b.Bytes(),
}, nil
}

// GetResourceReferences returns the names for dependent resources (EDS cluster
Expand Down
10 changes: 7 additions & 3 deletions pkg/cache/v3/resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions pkg/resource/v2/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ func GetHTTPConnectionManager(filter *listener.Filter) *hcm.HttpConnectionManage
}
return config
}

// ConvertTypeURL converts typeurl from v2->v3 and vice versa
func ConvertTypeURL(typeURL string) string {
var convertedURL string
switch typeURL {
case EndpointType:
convertedURL = "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment"
case ClusterType:
convertedURL = "type.googleapis.com/envoy.config.cluster.v3.Cluster"
case RouteType:
convertedURL = "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
case ListenerType:
convertedURL = "type.googleapis.com/envoy.config.listener.v3.Listener"
case SecretType:
convertedURL = "type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.Secret"
case RuntimeType:
convertedURL = "type.googleapis.com/envoy.service.runtime.v3.Runtime"
}
return convertedURL
}
20 changes: 20 additions & 0 deletions pkg/resource/v3/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,23 @@ func GetHTTPConnectionManager(filter *listener.Filter) *hcm.HttpConnectionManage
}
return config
}

// ConvertTypeURL converts typeurl from v2->v3 and vice versa
func ConvertTypeURL(typeURL string) string {
var convertedURL string
switch typeURL {
case EndpointType:
convertedURL = "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment"
case ClusterType:
convertedURL = "type.googleapis.com/envoy.api.v2.Cluster"
case RouteType:
convertedURL = "type.googleapis.com/envoy.api.v2.RouteConfiguration"
case ListenerType:
convertedURL = "type.googleapis.com/envoy.api.v2.Listener"
case SecretType:
convertedURL = "type.googleapis.com/envoy.api.v2.auth.Secret"
case RuntimeType:
convertedURL = "type.googleapis.com/envoy.service.discovery.v2.Runtime"
}
return convertedURL
}
7 changes: 2 additions & 5 deletions pkg/server/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,12 @@ func createResponse(resp *cache.Response, typeURL string) (*discovery.DiscoveryR
Value: resp.MarshaledResources[i],
}
} else {
marshaledResource, err := cache.MarshalResource(resp.Resources[i])
marshaledResource, err := cache.MarshalResource(resp.Resources[i], typeURL)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should discovery.DiscoveryResponse.TypeUrl below be updated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see...trying that out.

Copy link
Contributor Author

@jyotimahapatra jyotimahapatra Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There;s still some issue. From envoy logs

[2020-04-17 19:18:00.722][1209][debug][config] [source/common/config/grpc_mux_impl.cc:136] Received gRPC message for type.googleapis.com/envoy.config.cluster.v3.Cluster at version v0
[2020-04-17 19:18:00.722][1209][warning][config] [source/common/config/grpc_mux_impl.cc:139] Ignoring the message for type URL type.googleapis.com/envoy.config.cluster.v3.Cluster as it has no current subscribers.

https://github.com/envoyproxy/envoy/blob/master/source/common/config/grpc_mux_impl.cc#L131

if err != nil {
return nil, err
}

resources[i] = &any.Any{
TypeUrl: typeURL,
Value: marshaledResource,
}
resources[i] = marshaledResource
}
}
out := &discovery.DiscoveryResponse{
Expand Down
7 changes: 2 additions & 5 deletions pkg/server/v3/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.