mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7170 from vimalk78/make-v2-endpoint-optional-#7100
embed/etcd.go: make v2 endpoint optional. fixes #7100
This commit is contained in:
commit
a630735c29
@ -140,6 +140,12 @@ To start etcd automatically using custom settings at startup in Linux, using a [
|
|||||||
+ default: 0
|
+ default: 0
|
||||||
+ env variable: ETCD_AUTO_COMPACTION_RETENTION
|
+ env variable: ETCD_AUTO_COMPACTION_RETENTION
|
||||||
|
|
||||||
|
|
||||||
|
### --enable-v2
|
||||||
|
+ Accept etcd V2 client requests
|
||||||
|
+ default: true
|
||||||
|
+ env variable: ETCD_ENABLE_V2
|
||||||
|
|
||||||
## Proxy flags
|
## Proxy flags
|
||||||
|
|
||||||
`--proxy` prefix flags configures etcd to run in [proxy mode][proxy]. "proxy" supports v2 API only.
|
`--proxy` prefix flags configures etcd to run in [proxy mode][proxy]. "proxy" supports v2 API only.
|
||||||
|
@ -102,6 +102,7 @@ type Config struct {
|
|||||||
InitialCluster string `json:"initial-cluster"`
|
InitialCluster string `json:"initial-cluster"`
|
||||||
InitialClusterToken string `json:"initial-cluster-token"`
|
InitialClusterToken string `json:"initial-cluster-token"`
|
||||||
StrictReconfigCheck bool `json:"strict-reconfig-check"`
|
StrictReconfigCheck bool `json:"strict-reconfig-check"`
|
||||||
|
EnableV2 bool `json:"enable-v2"`
|
||||||
|
|
||||||
// security
|
// security
|
||||||
|
|
||||||
@ -175,6 +176,7 @@ func NewConfig() *Config {
|
|||||||
InitialClusterToken: "etcd-cluster",
|
InitialClusterToken: "etcd-cluster",
|
||||||
StrictReconfigCheck: true,
|
StrictReconfigCheck: true,
|
||||||
Metrics: "basic",
|
Metrics: "basic",
|
||||||
|
EnableV2: true,
|
||||||
}
|
}
|
||||||
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
|
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
|
||||||
return cfg
|
return cfg
|
||||||
|
@ -319,15 +319,18 @@ func (e *Etcd) serve() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start a client server goroutine for each listen address
|
// Start a client server goroutine for each listen address
|
||||||
ch := http.Handler(&cors.CORSHandler{
|
var v2h http.Handler
|
||||||
Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
|
if e.Config().EnableV2 {
|
||||||
Info: e.cfg.CorsInfo,
|
v2h = http.Handler(&cors.CORSHandler{
|
||||||
})
|
Handler: v2http.NewClientHandler(e.Server, e.Server.Cfg.ReqTimeout()),
|
||||||
|
Info: e.cfg.CorsInfo,
|
||||||
|
})
|
||||||
|
}
|
||||||
for _, sctx := range e.sctxs {
|
for _, sctx := range e.sctxs {
|
||||||
// read timeout does not work with http close notify
|
// read timeout does not work with http close notify
|
||||||
// TODO: https://github.com/golang/go/issues/9524
|
// TODO: https://github.com/golang/go/issues/9524
|
||||||
go func(s *serveCtx) {
|
go func(s *serveCtx) {
|
||||||
e.errc <- s.serve(e.Server, ctlscfg, ch, e.errc)
|
e.errc <- s.serve(e.Server, ctlscfg, v2h, e.errc)
|
||||||
}(sctx)
|
}(sctx)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -122,6 +122,11 @@ func (sctx *serveCtx) serve(s *etcdserver.EtcdServer, tlscfg *tls.Config, handle
|
|||||||
// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
|
// grpcHandlerFunc returns an http.Handler that delegates to grpcServer on incoming gRPC
|
||||||
// connections or otherHandler otherwise. Copied from cockroachdb.
|
// connections or otherHandler otherwise. Copied from cockroachdb.
|
||||||
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
|
func grpcHandlerFunc(grpcServer *grpc.Server, otherHandler http.Handler) http.Handler {
|
||||||
|
if otherHandler == nil {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
grpcServer.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
|
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
|
||||||
grpcServer.ServeHTTP(w, r)
|
grpcServer.ServeHTTP(w, r)
|
||||||
@ -181,7 +186,9 @@ func (sctx *serveCtx) createMux(gwmux *gw.ServeMux, handler http.Handler) *http.
|
|||||||
}
|
}
|
||||||
|
|
||||||
httpmux.Handle("/v3alpha/", gwmux)
|
httpmux.Handle("/v3alpha/", gwmux)
|
||||||
httpmux.Handle("/", handler)
|
if handler != nil {
|
||||||
|
httpmux.Handle("/", handler)
|
||||||
|
}
|
||||||
return httpmux
|
return httpmux
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,9 @@ initial-cluster-state: 'new'
|
|||||||
# Reject reconfiguration requests that would cause quorum loss.
|
# Reject reconfiguration requests that would cause quorum loss.
|
||||||
strict-reconfig-check: false
|
strict-reconfig-check: false
|
||||||
|
|
||||||
|
# Accept etcd V2 client requests
|
||||||
|
enable-v2: true
|
||||||
|
|
||||||
# Valid values include 'on', 'readonly', 'off'
|
# Valid values include 'on', 'readonly', 'off'
|
||||||
proxy: 'off'
|
proxy: 'off'
|
||||||
|
|
||||||
|
@ -155,6 +155,7 @@ func newConfig() *config {
|
|||||||
plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
|
plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
|
||||||
}
|
}
|
||||||
fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", cfg.StrictReconfigCheck, "Reject reconfiguration requests that would cause quorum loss.")
|
fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", cfg.StrictReconfigCheck, "Reject reconfiguration requests that would cause quorum loss.")
|
||||||
|
fs.BoolVar(&cfg.EnableV2, "enable-v2", true, "Accept etcd V2 client requests.")
|
||||||
|
|
||||||
// proxy
|
// proxy
|
||||||
fs.Var(cfg.proxy, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(cfg.proxy.Values, ", ")))
|
fs.Var(cfg.proxy, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(cfg.proxy.Values, ", ")))
|
||||||
|
@ -88,6 +88,8 @@ clustering flags:
|
|||||||
reject reconfiguration requests that would cause quorum loss.
|
reject reconfiguration requests that would cause quorum loss.
|
||||||
--auto-compaction-retention '0'
|
--auto-compaction-retention '0'
|
||||||
auto compaction retention in hour. 0 means disable auto compaction.
|
auto compaction retention in hour. 0 means disable auto compaction.
|
||||||
|
--enable-v2
|
||||||
|
Accept etcd V2 client requests.
|
||||||
|
|
||||||
proxy flags:
|
proxy flags:
|
||||||
"proxy" supports v2 API only.
|
"proxy" supports v2 API only.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user