Replace deprecated grpc WithInsecure option (#26259)

Signed-off-by: Congqi Xia <congqi.xia@zilliz.com>
This commit is contained in:
congqixia 2023-08-10 18:57:17 +08:00 committed by GitHub
parent 2ed54f4424
commit 4cea3ac897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/milvus-io/milvus/internal/util/typeutil"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"go.uber.org/zap"
)
@ -221,10 +222,11 @@ func (cm *ConnectionManager) Stop() {
}
}
//go:norace
// fix datarace in unittest
// startWatchService will only be invoked at start procedure
// otherwise, remove the annotation and add atomic protection
//
//go:norace
func (cm *ConnectionManager) processEvent(channel <-chan *sessionutil.SessionEvent) {
for {
select {
@ -393,8 +395,11 @@ func (bct *buildClientTask) Run() {
connectGrpcFunc := func() error {
opts := trace.GetInterceptorOpts()
log.Info("Grpc connect ", zap.String("Address", bct.sess.Address))
conn, err := grpc.DialContext(bct.ctx, bct.sess.Address,
grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(30*time.Second),
ctx, cancel := context.WithTimeout(bct.ctx, time.Second*30)
defer cancel()
conn, err := grpc.DialContext(ctx, bct.sess.Address,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithDisableRetry(),
grpc.WithUnaryInterceptor(
grpc_middleware.ChainUnaryClient(

View File

@ -36,6 +36,7 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
@ -1140,7 +1141,7 @@ func waitForGrpcReady(opt *WaitOption) {
conn.Close()
return
}
if conn, err := grpc.Dial(address, grpc.WithBlock(), grpc.WithInsecure()); true {
if conn, err := grpc.Dial(address, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())); true {
ch <- err
conn.Close()
}

View File

@ -29,6 +29,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
const bufSize = 1024 * 1024
@ -76,7 +77,9 @@ func (suite *ClusterTestSuite) setupServers() {
// check server ready to serve
for _, lis := range suite.listeners {
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithBlock(), grpc.WithInsecure())
conn, err := grpc.Dial(lis.Addr().String(),
grpc.WithBlock(),
grpc.WithTransportCredentials(insecure.NewCredentials()))
suite.NoError(err)
suite.NoError(conn.Close())
}

View File

@ -31,6 +31,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
@ -183,7 +184,6 @@ func (c *ClientBase[T]) connect(ctx context.Context) error {
conn, err = grpc.DialContext(
dialContext,
addr,
//grpc.WithInsecure(),
// #nosec G402
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithBlock(),
@ -220,8 +220,7 @@ func (c *ClientBase[T]) connect(ctx context.Context) error {
conn, err = grpc.DialContext(
dialContext,
addr,
grpc.WithInsecure(),
//grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(c.ClientMaxRecvSize),