Skip to content

Commit

Permalink
xds: Remove usages of grpc.WithInsecure(). (#4028)
Browse files Browse the repository at this point in the history
  • Loading branch information
easwars committed Nov 12, 2020
1 parent d2629bd commit 22dba5e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 22 deletions.
3 changes: 2 additions & 1 deletion xds/internal/client/bootstrap/bootstrap.go
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/google"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/credentials/tls/certprovider"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/xds/internal/env"
Expand Down Expand Up @@ -183,7 +184,7 @@ func NewConfig() (*Config, error) {
config.Creds = grpc.WithCredentialsBundle(google.NewDefaultCredentials())
break
} else if cc.Type == credsInsecure {
config.Creds = grpc.WithInsecure()
config.Creds = grpc.WithTransportCredentials(insecure.NewCredentials())
break
}
}
Expand Down
5 changes: 3 additions & 2 deletions xds/internal/client/bootstrap/bootstrap_test.go
Expand Up @@ -33,6 +33,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/google"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/credentials/tls/certprovider"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/xds/internal/env"
Expand Down Expand Up @@ -207,7 +208,7 @@ var (
}
nilCredsConfigV2 = &Config{
BalancerName: "trafficdirector.googleapis.com:443",
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: v2NodeProto,
}
nonNilCredsConfigV2 = &Config{
Expand Down Expand Up @@ -362,7 +363,7 @@ func TestNewConfigV2ProtoSuccess(t *testing.T) {
{
"emptyNodeProto", &Config{
BalancerName: "trafficdirector.googleapis.com:443",
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: &v2corepb.Node{
BuildVersion: gRPCVersion,
UserAgentName: gRPCUserAgentName,
Expand Down
7 changes: 4 additions & 3 deletions xds/internal/client/client_loadreport_test.go
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/status"
"google.golang.org/grpc/xds/internal/client"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (s) TestLRSClient(t *testing.T) {

xdsC, err := client.NewWithConfigForTesting(&bootstrap.Config{
BalancerName: fs.Address,
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: &v2corepb.Node{},
TransportAPI: version.TransportV2,
}, defaultClientWatchExpiryTimeout)
Expand Down Expand Up @@ -128,12 +129,12 @@ func (s) TestLRSClient(t *testing.T) {
t.Fatalf("unexpected load received, want load for cluster, eds, dropped for test")
}
receivedLoad[0].LoadReportInterval = nil
want := (&endpointpb.ClusterStats{
want := &endpointpb.ClusterStats{
ClusterName: "cluster",
ClusterServiceName: "eds",
TotalDroppedRequests: 1,
DroppedRequests: []*endpointpb.ClusterStats_DroppedRequests{{Category: "test", DroppedCount: 1}},
})
}
if d := cmp.Diff(want, receivedLoad[0], protocmp.Transform()); d != "" {
t.Fatalf("unexpected load received, want load for cluster, eds, dropped for test, diff (-want +got):\n%s", d)
}
Expand Down
3 changes: 2 additions & 1 deletion xds/internal/client/client_test.go
Expand Up @@ -29,6 +29,7 @@ import (
"google.golang.org/grpc/internal/grpcsync"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/xds/internal/client/bootstrap"
Expand Down Expand Up @@ -64,7 +65,7 @@ func clientOpts(balancerName string, overrideWatchExpiryTimeout bool) (*bootstra
}
return &bootstrap.Config{
BalancerName: balancerName,
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: xdstestutils.EmptyNodeProtoV2,
}, watchExpiryTimeout
}
Expand Down
11 changes: 5 additions & 6 deletions xds/internal/client/tests/client_test.go
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpctest"
xdsclient "google.golang.org/grpc/xds/internal/client"
"google.golang.org/grpc/xds/internal/client/bootstrap"
Expand All @@ -39,9 +40,7 @@ func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

const (
testXDSServer = "xds-server"
)
const testXDSServer = "xds-server"

func (s) TestNew(t *testing.T) {
tests := []struct {
Expand All @@ -57,7 +56,7 @@ func (s) TestNew(t *testing.T) {
{
name: "empty-balancer-name",
config: &bootstrap.Config{
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: testutils.EmptyNodeProtoV2,
},
wantErr: true,
Expand All @@ -74,15 +73,15 @@ func (s) TestNew(t *testing.T) {
name: "empty-node-proto",
config: &bootstrap.Config{
BalancerName: testXDSServer,
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
},
wantErr: true,
},
{
name: "node-proto-version-mismatch",
config: &bootstrap.Config{
BalancerName: testXDSServer,
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: testutils.EmptyNodeProtoV3,
TransportAPI: version.TransportV2,
},
Expand Down
4 changes: 2 additions & 2 deletions xds/internal/client/v2/client_test.go
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/grpclog"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/internal/testutils"
Expand Down Expand Up @@ -60,7 +61,6 @@ const (
goodRouteName1 = "GoodRouteConfig1"
goodRouteName2 = "GoodRouteConfig2"
goodEDSName = "GoodClusterAssignment1"
uninterestingRouteName = "UninterestingRouteName"
uninterestingDomain = "uninteresting.domain"
goodClusterName1 = "GoodClusterName1"
goodClusterName2 = "GoodClusterName2"
Expand Down Expand Up @@ -635,7 +635,7 @@ func (s) TestV2ClientWatchWithoutStream(t *testing.T) {
rb := manual.NewBuilderWithScheme(scheme)
rb.InitialState(resolver.State{Addresses: []resolver.Address{{Addr: "no.such.server"}}})

cc, err := grpc.Dial(scheme+":///whatever", grpc.WithInsecure(), grpc.WithResolvers(rb))
cc, err := grpc.Dial(scheme+":///whatever", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(rb))
if err != nil {
t.Fatalf("Failed to dial ClientConn: %v", err)
}
Expand Down
5 changes: 1 addition & 4 deletions xds/internal/resolver/xds_resolver_test.go
Expand Up @@ -42,14 +42,11 @@ const (
targetStr = "target"
routeStr = "route"
cluster = "cluster"
balancerName = "dummyBalancer"
defaultTestTimeout = 1 * time.Second
defaultTestShortTimeout = 100 * time.Microsecond
)

var (
target = resolver.Target{Endpoint: targetStr}
)
var target = resolver.Target{Endpoint: targetStr}

type s struct {
grpctest.Tester
Expand Down
3 changes: 2 additions & 1 deletion xds/internal/testutils/fakeserver/server.go
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -138,7 +139,7 @@ func (xdsS *Server) XDSClientConn() (*grpc.ClientConn, func(), error) {
ctx, cancel := context.WithTimeout(context.Background(), defaultDialTimeout)
defer cancel()

cc, err := grpc.DialContext(ctx, xdsS.Address, grpc.WithInsecure(), grpc.WithBlock())
cc, err := grpc.DialContext(ctx, xdsS.Address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
return nil, nil, fmt.Errorf("grpc.DialContext(%s) failed: %v", xdsS.Address, err)
}
Expand Down
4 changes: 2 additions & 2 deletions xds/server_test.go
Expand Up @@ -190,7 +190,7 @@ func setupOverrides(t *testing.T) (*fakeGRPCServer, *testutils.Channel, func())
newXDSConfig = func() (*bootstrap.Config, error) {
return &bootstrap.Config{
BalancerName: "dummyBalancer",
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: xdstestutils.EmptyNodeProtoV3,
}, nil
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func (s) TestServeNewClientFailure(t *testing.T) {
newXDSConfig = func() (*bootstrap.Config, error) {
return &bootstrap.Config{
BalancerName: "dummyBalancer",
Creds: grpc.WithInsecure(),
Creds: grpc.WithTransportCredentials(insecure.NewCredentials()),
NodeProto: xdstestutils.EmptyNodeProtoV3,
}, nil
}
Expand Down

0 comments on commit 22dba5e

Please sign in to comment.