-
Notifications
You must be signed in to change notification settings - Fork 10
Proxy envoy ADS requests to Consul server #4
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fc7c83
Proxy envoy ADS requests to Consul server
jshahriddhi dc8c349
Start,stop,exit the grpc server gracefully
jshahriddhi 4dd7652
Pass flags, add tests, cleanup and polish
jshahriddhi e2c2ec9
Semantic fixes
jshahriddhi 943f7a7
Only allow local xds bind address
jshahriddhi cd799a4
Check loopback
jshahriddhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package consuldp | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net" | ||
| "strings" | ||
|
|
||
| "github.com/adamthesax/grpc-proxy/proxy" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/metadata" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| const metadataKeyToken = "x-consul-token" | ||
|
|
||
| func (cdp *ConsulDataplane) setupGRPCServer() error { | ||
| cdp.logger.Trace("setting up gRPC server") | ||
| // create gRPC listener | ||
| lis, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| cdp.logger.Error("failed to create gRPC/TCP listener: %v", err) | ||
| return err | ||
| } | ||
|
|
||
| // create gRPC server | ||
| // one main role of this gRPC server in consul-dataplane is to proxy envoy ADS requests | ||
| // to the connected Consul server. | ||
| director := func(ctx context.Context, fullMethodName string) (context.Context, *grpc.ClientConn, error) { | ||
| if !strings.Contains(fullMethodName, "envoy.service.discovery.v3.AggregatedDiscoveryService/DeltaAggregatedResources") { | ||
| return ctx, nil, status.Errorf(codes.Unimplemented, fmt.Sprintf("Unknown method %s", fullMethodName)) | ||
| } | ||
|
|
||
| md, _ := metadata.FromIncomingContext(ctx) | ||
| mdCopy := md.Copy() | ||
| // TODO (NET-148): Inject the ACL token acquired from the server discovery library | ||
| mdCopy[metadataKeyToken] = []string{cdp.cfg.Consul.Credentials.Static.Token} | ||
jshahriddhi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| outCtx := metadata.NewOutgoingContext(ctx, mdCopy) | ||
| return outCtx, cdp.consulServer.grpcClientConn, nil | ||
| } | ||
| newGRPCServer := grpc.NewServer(grpc.UnknownServiceHandler(proxy.TransparentHandler(director))) | ||
|
|
||
| cdp.gRPCServer = &gRPCServer{listener: lis, server: newGRPCServer, exitedCh: make(chan struct{})} | ||
| cdp.logger.Trace("created gRPC server", "address", lis.Addr().String()) | ||
| return nil | ||
| } | ||
|
|
||
| func (cdp *ConsulDataplane) startGRPCServer() { | ||
| cdp.logger.Info("starting gRPC server", "address", cdp.gRPCServer.listener.Addr().String()) | ||
|
|
||
| if err := cdp.gRPCServer.server.Serve(cdp.gRPCServer.listener); err != nil { | ||
| cdp.logger.Error("failed to serve gRPC requests", "error", err) | ||
| cdp.gRPCServer.listener.Close() | ||
jshahriddhi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| close(cdp.gRPCServer.exitedCh) | ||
| } | ||
| } | ||
|
|
||
| func (cdp *ConsulDataplane) stopGRPCServer() { | ||
| if cdp.gRPCServer != nil { | ||
| cdp.logger.Debug("stopping gRPC server") | ||
| cdp.gRPCServer.server.Stop() | ||
| } | ||
| } | ||
|
|
||
| func (cdp *ConsulDataplane) gRPCServerExited() chan struct{} { return cdp.gRPCServer.exitedCh } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.