mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
*: add a new option --enable-grpc-gateway for enabling/disabling grpc gateway
This commit is contained in:
@@ -318,6 +318,9 @@ type Config struct {
|
|||||||
loggerCore zapcore.Core
|
loggerCore zapcore.Core
|
||||||
loggerWriteSyncer zapcore.WriteSyncer
|
loggerWriteSyncer zapcore.WriteSyncer
|
||||||
|
|
||||||
|
// EnableGRPCGateway is false to disable grpc gateway.
|
||||||
|
EnableGRPCGateway bool `json:"enable-grpc-gateway"`
|
||||||
|
|
||||||
// TO BE DEPRECATED
|
// TO BE DEPRECATED
|
||||||
|
|
||||||
// LogPkgLevels is being deprecated in v3.5.
|
// LogPkgLevels is being deprecated in v3.5.
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
|
|||||||
LoggerWriteSyncer: cfg.loggerWriteSyncer,
|
LoggerWriteSyncer: cfg.loggerWriteSyncer,
|
||||||
Debug: cfg.Debug,
|
Debug: cfg.Debug,
|
||||||
ForceNewCluster: cfg.ForceNewCluster,
|
ForceNewCluster: cfg.ForceNewCluster,
|
||||||
|
EnableGRPCGateway: cfg.EnableGRPCGateway,
|
||||||
}
|
}
|
||||||
print(e.cfg.logger, *cfg, srvcfg, memberInitialized)
|
print(e.cfg.logger, *cfg, srvcfg, memberInitialized)
|
||||||
if e.Server, err = etcdserver.NewServer(srvcfg); err != nil {
|
if e.Server, err = etcdserver.NewServer(srvcfg); err != nil {
|
||||||
|
|||||||
@@ -118,9 +118,11 @@ func (sctx *serveCtx) serve(
|
|||||||
go func() { errHandler(gs.Serve(grpcl)) }()
|
go func() { errHandler(gs.Serve(grpcl)) }()
|
||||||
|
|
||||||
var gwmux *gw.ServeMux
|
var gwmux *gw.ServeMux
|
||||||
gwmux, err = sctx.registerGateway([]grpc.DialOption{grpc.WithInsecure()})
|
if s.Cfg.EnableGRPCGateway {
|
||||||
if err != nil {
|
gwmux, err = sctx.registerGateway([]grpc.DialOption{grpc.WithInsecure()})
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpmux := sctx.createMux(gwmux, handler)
|
httpmux := sctx.createMux(gwmux, handler)
|
||||||
@@ -156,15 +158,17 @@ func (sctx *serveCtx) serve(
|
|||||||
}
|
}
|
||||||
handler = grpcHandlerFunc(gs, handler)
|
handler = grpcHandlerFunc(gs, handler)
|
||||||
|
|
||||||
dtls := tlscfg.Clone()
|
|
||||||
// trust local server
|
|
||||||
dtls.InsecureSkipVerify = true
|
|
||||||
creds := credentials.NewTLS(dtls)
|
|
||||||
opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)}
|
|
||||||
var gwmux *gw.ServeMux
|
var gwmux *gw.ServeMux
|
||||||
gwmux, err = sctx.registerGateway(opts)
|
if s.Cfg.EnableGRPCGateway {
|
||||||
if err != nil {
|
dtls := tlscfg.Clone()
|
||||||
return err
|
// trust local server
|
||||||
|
dtls.InsecureSkipVerify = true
|
||||||
|
creds := credentials.NewTLS(dtls)
|
||||||
|
opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)}
|
||||||
|
gwmux, err = sctx.registerGateway(opts)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var tlsl net.Listener
|
var tlsl net.Listener
|
||||||
@@ -270,19 +274,21 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
|||||||
httpmux.Handle(path, h)
|
httpmux.Handle(path, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpmux.Handle(
|
if gwmux != nil {
|
||||||
"/v3/",
|
httpmux.Handle(
|
||||||
wsproxy.WebsocketProxy(
|
"/v3/",
|
||||||
gwmux,
|
wsproxy.WebsocketProxy(
|
||||||
wsproxy.WithRequestMutator(
|
gwmux,
|
||||||
// Default to the POST method for streams
|
wsproxy.WithRequestMutator(
|
||||||
func(_ *http.Request, outgoing *http.Request) *http.Request {
|
// Default to the POST method for streams
|
||||||
outgoing.Method = "POST"
|
func(_ *http.Request, outgoing *http.Request) *http.Request {
|
||||||
return outgoing
|
outgoing.Method = "POST"
|
||||||
},
|
return outgoing
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
)
|
}
|
||||||
if handler != nil {
|
if handler != nil {
|
||||||
httpmux.Handle("/", handler)
|
httpmux.Handle("/", handler)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,6 +241,9 @@ func newConfig() *config {
|
|||||||
fs.StringVar(&cfg.ec.AuthToken, "auth-token", cfg.ec.AuthToken, "Specify auth token specific options.")
|
fs.StringVar(&cfg.ec.AuthToken, "auth-token", cfg.ec.AuthToken, "Specify auth token specific options.")
|
||||||
fs.UintVar(&cfg.ec.BcryptCost, "bcrypt-cost", cfg.ec.BcryptCost, "Specify bcrypt algorithm cost factor for auth password hashing.")
|
fs.UintVar(&cfg.ec.BcryptCost, "bcrypt-cost", cfg.ec.BcryptCost, "Specify bcrypt algorithm cost factor for auth password hashing.")
|
||||||
|
|
||||||
|
// gateway
|
||||||
|
fs.BoolVar(&cfg.ec.EnableGRPCGateway, "enable-grpc-gateway", true, "Enable GRPC gateway.")
|
||||||
|
|
||||||
// experimental
|
// experimental
|
||||||
fs.BoolVar(&cfg.ec.ExperimentalInitialCorruptCheck, "experimental-initial-corrupt-check", cfg.ec.ExperimentalInitialCorruptCheck, "Enable to check data corruption before serving any client/peer traffic.")
|
fs.BoolVar(&cfg.ec.ExperimentalInitialCorruptCheck, "experimental-initial-corrupt-check", cfg.ec.ExperimentalInitialCorruptCheck, "Enable to check data corruption before serving any client/peer traffic.")
|
||||||
fs.DurationVar(&cfg.ec.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ec.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.")
|
fs.DurationVar(&cfg.ec.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ec.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.")
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ type ServerConfig struct {
|
|||||||
|
|
||||||
// LeaseCheckpointInterval time.Duration is the wait duration between lease checkpoints.
|
// LeaseCheckpointInterval time.Duration is the wait duration between lease checkpoints.
|
||||||
LeaseCheckpointInterval time.Duration
|
LeaseCheckpointInterval time.Duration
|
||||||
|
|
||||||
|
EnableGRPCGateway bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
// VerifyBootstrap sanity-checks the initial config for bootstrap case
|
||||||
|
|||||||
Reference in New Issue
Block a user