Merge 3d8fe917f9c36ae4cc4d02f534706b106f02e8b6 into c86c93ca2951338115159dcdd20711603044e1f1

This commit is contained in:
chengjoey 2024-09-27 01:33:13 +00:00 committed by GitHub
commit edae2a1095
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"go.uber.org/zap" "go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
"go.etcd.io/etcd/client/pkg/v3/logutil" "go.etcd.io/etcd/client/pkg/v3/logutil"
@ -151,6 +152,11 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
return mustClient(cfg) return mustClient(cfg)
} }
func mustBlockClientFromCmd(cmd *cobra.Command) *clientv3.Client {
cfg := clientConfigFromCmd(cmd)
return mustBlockClient(cfg)
}
func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client { func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel) lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
cfg, err := clientv3.NewClientConfig(cc, lg) cfg, err := clientv3.NewClientConfig(cc, lg)
@ -166,6 +172,23 @@ func mustClient(cc *clientv3.ConfigSpec) *clientv3.Client {
return client return client
} }
// mustBlockClient same as mustClient but with grpc.WithBlock dial option, detail see #18335
func mustBlockClient(cc *clientv3.ConfigSpec) *clientv3.Client {
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel)
cfg, err := clientv3.NewClientConfig(cc, lg)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
}
cfg.DialOptions = append(cfg.DialOptions, grpc.WithBlock())
client, err := clientv3.New(*cfg)
if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadConnection, err)
}
return client
}
func argOrStdin(args []string, stdin io.Reader, i int) (string, error) { func argOrStdin(args []string, stdin io.Reader, i int) (string, error) {
if i < len(args) { if i < len(args) {
return args[i], nil return args[i], nil

View File

@ -78,7 +78,7 @@ func watchCommandFunc(cmd *cobra.Command, args []string) {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err) cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)
} }
c := mustClientFromCmd(cmd) c := mustBlockClientFromCmd(cmd)
wc, err := getWatchChan(c, watchArgs) wc, err := getWatchChan(c, watchArgs)
if err != nil { if err != nil {
cobrautl.ExitWithError(cobrautl.ExitBadArgs, err) cobrautl.ExitWithError(cobrautl.ExitBadArgs, err)