Created
December 27, 2019 20:26
-
-
Save Stoakes/1f525fbc12d54703cfec08f526e0d1a6 to your computer and use it in GitHub Desktop.
gRPC xds Resolver
This file contains 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
{ | |
"xds_servers": [ | |
{ | |
"server_uri": "istio-pilot:15010", | |
"channel_creds": [{}] | |
}], | |
"node": { | |
"id": "sidecar~192.168.0.1~xds.default~default.svc.cluster.local" | |
} | |
} |
This file contains 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
package main | |
import ( | |
"io/ioutil" | |
"os" | |
"github.com/Stoakes/go-pkg/log" | |
"golang.org/x/net/context" | |
"google.golang.org/grpc" | |
"google.golang.org/grpc/grpclog" | |
_ "google.golang.org/grpc/xds/experimental" | |
) | |
var ( | |
xdsScheme = "xds-experimental-new" | |
helloService = "localhost:8080" | |
) | |
func main() { | |
logg := grpclog.NewLoggerV2(os.Stdout, ioutil.Discard, ioutil.Discard) | |
grpclog.SetLoggerV2(logg) | |
ctx, cancel := context.WithCancel(context.Background()) | |
defer cancel() | |
log.Setup(ctx, log.Options{ | |
Debug: true, | |
LogLevel: "debug", | |
AppName: "xds-demo", | |
AppID: "appId", | |
Version: "0.0.1", | |
}) | |
log.For(ctx).Info("Connecting to hello service at " + helloService) | |
_, err := dial(helloService) | |
if err != nil { | |
log.For(ctx).Fatalf("Connection to hello-service error :%v", err) | |
} | |
} | |
// Dial dial an headless service with loadBalancing Options | |
func dial(targetStr string, dialOpts ...grpc.DialOption) (*grpc.ClientConn, error) { | |
log.Bg().Debug("Dialing " + xdsScheme + ":///" + targetStr) | |
return grpc.Dial(xdsScheme+":///"+targetStr, []grpc.DialOption{ | |
grpc.WithBlock(), | |
grpc.WithInsecure()}..., | |
) | |
} |
This file contains 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
#!/bin/bash | |
GRPC_GO_LOG_SEVERITY_LEVEL=16 GRPC_XDS_BOOTSTRAP=$(pwd)/config.json ./xds-demo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment