Skip to content

Instantly share code, notes, and snippets.

@Stoakes
Created December 27, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stoakes/1f525fbc12d54703cfec08f526e0d1a6 to your computer and use it in GitHub Desktop.
Save Stoakes/1f525fbc12d54703cfec08f526e0d1a6 to your computer and use it in GitHub Desktop.
gRPC xds Resolver
{
"xds_servers": [
{
"server_uri": "istio-pilot:15010",
"channel_creds": [{}]
}],
"node": {
"id": "sidecar~192.168.0.1~xds.default~default.svc.cluster.local"
}
}
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()}...,
)
}
#!/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