|
|
@@ -20,21 +20,17 @@ import (
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"io/ioutil"
|
|
|
- "net/url"
|
|
|
"os"
|
|
|
"runtime"
|
|
|
"strings"
|
|
|
|
|
|
- "github.com/coreos/etcd/etcdserver"
|
|
|
- "github.com/coreos/etcd/pkg/cors"
|
|
|
+ "github.com/coreos/etcd/embed"
|
|
|
"github.com/coreos/etcd/pkg/flags"
|
|
|
- "github.com/coreos/etcd/pkg/transport"
|
|
|
- "github.com/coreos/etcd/pkg/types"
|
|
|
"github.com/coreos/etcd/version"
|
|
|
"github.com/ghodss/yaml"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
+var (
|
|
|
proxyFlagOff = "off"
|
|
|
proxyFlagReadonly = "readonly"
|
|
|
proxyFlagOn = "on"
|
|
|
@@ -42,21 +38,6 @@ const (
|
|
|
fallbackFlagExit = "exit"
|
|
|
fallbackFlagProxy = "proxy"
|
|
|
|
|
|
- clusterStateFlagNew = "new"
|
|
|
- clusterStateFlagExisting = "existing"
|
|
|
-
|
|
|
- defaultName = "default"
|
|
|
- defaultInitialAdvertisePeerURLs = "http://localhost:2380"
|
|
|
- defaultAdvertiseClientURLs = "http://localhost:2379"
|
|
|
- defaultListenPeerURLs = "http://localhost:2380"
|
|
|
- defaultListenClientURLs = "http://localhost:2379"
|
|
|
-
|
|
|
- // maxElectionMs specifies the maximum value of election timeout.
|
|
|
- // More details are listed in ../Documentation/tuning.md#time-parameters.
|
|
|
- maxElectionMs = 50000
|
|
|
-)
|
|
|
-
|
|
|
-var (
|
|
|
ignored = []string{
|
|
|
"cluster-active-size",
|
|
|
"cluster-remove-delay",
|
|
|
@@ -72,105 +53,60 @@ var (
|
|
|
"v",
|
|
|
"vv",
|
|
|
}
|
|
|
-
|
|
|
- ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " +
|
|
|
- "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"")
|
|
|
- errUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly")
|
|
|
)
|
|
|
|
|
|
-type config struct {
|
|
|
- *flag.FlagSet
|
|
|
-
|
|
|
- // member
|
|
|
- corsInfo *cors.CORSInfo
|
|
|
- lpurls, lcurls []url.URL
|
|
|
- Dir string `json:"data-dir"`
|
|
|
- WalDir string `json:"wal-dir"`
|
|
|
- MaxSnapFiles uint `json:"max-snapshots"`
|
|
|
- MaxWalFiles uint `json:"max-wals"`
|
|
|
- Name string `json:"name"`
|
|
|
- SnapCount uint64 `json:"snapshot-count"`
|
|
|
- LPUrlsCfgFile string `json:"listen-peer-urls"`
|
|
|
- LCUrlsCfgFile string `json:"listen-client-urls"`
|
|
|
- CorsCfgFile string `json:"cors"`
|
|
|
-
|
|
|
- // TickMs is the number of milliseconds between heartbeat ticks.
|
|
|
- // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1).
|
|
|
- // make ticks a cluster wide configuration.
|
|
|
- TickMs uint `json:"heartbeat-interval"`
|
|
|
- ElectionMs uint `json:"election-timeout"`
|
|
|
- QuotaBackendBytes int64 `json:"quota-backend-bytes"`
|
|
|
-
|
|
|
- // clustering
|
|
|
- apurls, acurls []url.URL
|
|
|
- clusterState *flags.StringsFlag
|
|
|
- DNSCluster string `json:"discovery-srv"`
|
|
|
- Dproxy string `json:"discovery-proxy"`
|
|
|
- Durl string `json:"discovery"`
|
|
|
- fallback *flags.StringsFlag
|
|
|
- InitialCluster string `json:"initial-cluster"`
|
|
|
- InitialClusterToken string `json:"initial-cluster-token"`
|
|
|
- StrictReconfigCheck bool `json:"strict-reconfig-check"`
|
|
|
- ApurlsCfgFile string `json:"initial-advertise-peer-urls"`
|
|
|
- AcurlsCfgFile string `json:"advertise-client-urls"`
|
|
|
- ClusterStateCfgFile string `json:"initial-cluster-state"`
|
|
|
- FallbackCfgFile string `json:"discovery-fallback"`
|
|
|
-
|
|
|
- // proxy
|
|
|
- proxy *flags.StringsFlag
|
|
|
- ProxyFailureWaitMs uint `json:"proxy-failure-wait"`
|
|
|
- ProxyRefreshIntervalMs uint `json:"proxy-refresh-interval"`
|
|
|
- ProxyDialTimeoutMs uint `json:"proxy-dial-timeout"`
|
|
|
- ProxyWriteTimeoutMs uint `json:"proxy-write-timeout"`
|
|
|
- ProxyReadTimeoutMs uint `json:"proxy-read-timeout"`
|
|
|
- ProxyCfgFile string `json:"proxy"`
|
|
|
-
|
|
|
- // security
|
|
|
- clientTLSInfo, peerTLSInfo transport.TLSInfo
|
|
|
- ClientAutoTLS bool
|
|
|
- PeerAutoTLS bool
|
|
|
- ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
|
|
|
- PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
|
|
|
-
|
|
|
- // Debug logging
|
|
|
- Debug bool `json:"debug"`
|
|
|
- LogPkgLevels string `json:"log-package-levels"`
|
|
|
-
|
|
|
- // ForceNewCluster is unsafe
|
|
|
- ForceNewCluster bool `json:"force-new-cluster"`
|
|
|
+type configProxy struct {
|
|
|
+ ProxyFailureWaitMs uint `json:"proxy-failure-wait"`
|
|
|
+ ProxyRefreshIntervalMs uint `json:"proxy-refresh-interval"`
|
|
|
+ ProxyDialTimeoutMs uint `json:"proxy-dial-timeout"`
|
|
|
+ ProxyWriteTimeoutMs uint `json:"proxy-write-timeout"`
|
|
|
+ ProxyReadTimeoutMs uint `json:"proxy-read-timeout"`
|
|
|
+ Fallback string
|
|
|
+ Proxy string
|
|
|
+ ProxyJSON string `json:"proxy"`
|
|
|
+ FallbackJSON string `json:"discovery-fallback"`
|
|
|
+}
|
|
|
|
|
|
+// config holds the config for a command line invocation of etcd
|
|
|
+type config struct {
|
|
|
+ embed.Config
|
|
|
+ configProxy
|
|
|
+ configFlags
|
|
|
+ configFile string
|
|
|
printVersion bool
|
|
|
-
|
|
|
- autoCompactionRetention int
|
|
|
-
|
|
|
- enablePprof bool
|
|
|
-
|
|
|
- configFile string
|
|
|
-
|
|
|
- ignored []string
|
|
|
+ ignored []string
|
|
|
}
|
|
|
|
|
|
-type securityConfig struct {
|
|
|
- CAFile string `json:"ca-file"`
|
|
|
- CertFile string `json:"cert-file"`
|
|
|
- KeyFile string `json:"key-file"`
|
|
|
- CertAuth bool `json:"client-cert-auth"`
|
|
|
- TrustedCAFile string `json:"trusted-ca-file"`
|
|
|
- AutoTLS bool `json:"auto-tls"`
|
|
|
+// configFlags has the set of flags used for command line parsing a Config
|
|
|
+type configFlags struct {
|
|
|
+ *flag.FlagSet
|
|
|
+ clusterState *flags.StringsFlag
|
|
|
+ fallback *flags.StringsFlag
|
|
|
+ proxy *flags.StringsFlag
|
|
|
}
|
|
|
|
|
|
-func NewConfig() *config {
|
|
|
+func newConfig() *config {
|
|
|
cfg := &config{
|
|
|
- corsInfo: &cors.CORSInfo{},
|
|
|
+ Config: *embed.NewConfig(),
|
|
|
+ configProxy: configProxy{
|
|
|
+ Proxy: proxyFlagOff,
|
|
|
+ ProxyFailureWaitMs: 5000,
|
|
|
+ ProxyRefreshIntervalMs: 30000,
|
|
|
+ ProxyDialTimeoutMs: 1000,
|
|
|
+ ProxyWriteTimeoutMs: 5000,
|
|
|
+ },
|
|
|
+ ignored: ignored,
|
|
|
+ }
|
|
|
+ cfg.configFlags = configFlags{
|
|
|
+ FlagSet: flag.NewFlagSet("etcd", flag.ContinueOnError),
|
|
|
clusterState: flags.NewStringsFlag(
|
|
|
- clusterStateFlagNew,
|
|
|
- clusterStateFlagExisting,
|
|
|
+ embed.ClusterStateFlagNew,
|
|
|
+ embed.ClusterStateFlagExisting,
|
|
|
),
|
|
|
fallback: flags.NewStringsFlag(
|
|
|
fallbackFlagExit,
|
|
|
fallbackFlagProxy,
|
|
|
),
|
|
|
- ignored: ignored,
|
|
|
proxy: flags.NewStringsFlag(
|
|
|
proxyFlagOff,
|
|
|
proxyFlagReadonly,
|
|
|
@@ -178,7 +114,6 @@ func NewConfig() *config {
|
|
|
),
|
|
|
}
|
|
|
|
|
|
- cfg.FlagSet = flag.NewFlagSet("etcd", flag.ContinueOnError)
|
|
|
fs := cfg.FlagSet
|
|
|
fs.Usage = func() {
|
|
|
fmt.Println(usageline)
|
|
|
@@ -187,38 +122,38 @@ func NewConfig() *config {
|
|
|
fs.StringVar(&cfg.configFile, "config-file", "", "Path to the server configuration file")
|
|
|
|
|
|
// member
|
|
|
- fs.Var(cfg.corsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
|
|
|
- fs.StringVar(&cfg.Dir, "data-dir", "", "Path to the data directory.")
|
|
|
- fs.StringVar(&cfg.WalDir, "wal-dir", "", "Path to the dedicated wal directory.")
|
|
|
- fs.Var(flags.NewURLsValue(defaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.")
|
|
|
- fs.Var(flags.NewURLsValue(defaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.")
|
|
|
- fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", defaultMaxSnapshots, "Maximum number of snapshot files to retain (0 is unlimited).")
|
|
|
- fs.UintVar(&cfg.MaxWalFiles, "max-wals", defaultMaxWALs, "Maximum number of wal files to retain (0 is unlimited).")
|
|
|
- fs.StringVar(&cfg.Name, "name", defaultName, "Human-readable name for this member.")
|
|
|
- fs.Uint64Var(&cfg.SnapCount, "snapshot-count", etcdserver.DefaultSnapCount, "Number of committed transactions to trigger a snapshot to disk.")
|
|
|
- fs.UintVar(&cfg.TickMs, "heartbeat-interval", 100, "Time (in milliseconds) of a heartbeat interval.")
|
|
|
- fs.UintVar(&cfg.ElectionMs, "election-timeout", 1000, "Time (in milliseconds) for an election to timeout.")
|
|
|
- fs.Int64Var(&cfg.QuotaBackendBytes, "quota-backend-bytes", 0, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.")
|
|
|
+ fs.Var(cfg.CorsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
|
|
|
+ fs.StringVar(&cfg.Dir, "data-dir", cfg.Dir, "Path to the data directory.")
|
|
|
+ fs.StringVar(&cfg.WalDir, "wal-dir", cfg.WalDir, "Path to the dedicated wal directory.")
|
|
|
+ fs.Var(flags.NewURLsValue(embed.DefaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.")
|
|
|
+ fs.Var(flags.NewURLsValue(embed.DefaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.")
|
|
|
+ fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", cfg.MaxSnapFiles, "Maximum number of snapshot files to retain (0 is unlimited).")
|
|
|
+ fs.UintVar(&cfg.MaxWalFiles, "max-wals", cfg.MaxWalFiles, "Maximum number of wal files to retain (0 is unlimited).")
|
|
|
+ fs.StringVar(&cfg.Name, "name", cfg.Name, "Human-readable name for this member.")
|
|
|
+ fs.Uint64Var(&cfg.SnapCount, "snapshot-count", cfg.SnapCount, "Number of committed transactions to trigger a snapshot to disk.")
|
|
|
+ fs.UintVar(&cfg.TickMs, "heartbeat-interval", cfg.TickMs, "Time (in milliseconds) of a heartbeat interval.")
|
|
|
+ fs.UintVar(&cfg.ElectionMs, "election-timeout", cfg.ElectionMs, "Time (in milliseconds) for an election to timeout.")
|
|
|
+ fs.Int64Var(&cfg.QuotaBackendBytes, "quota-backend-bytes", cfg.QuotaBackendBytes, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.")
|
|
|
|
|
|
// clustering
|
|
|
- fs.Var(flags.NewURLsValue(defaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.")
|
|
|
- fs.Var(flags.NewURLsValue(defaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.")
|
|
|
- fs.StringVar(&cfg.Durl, "discovery", "", "Discovery URL used to bootstrap the cluster.")
|
|
|
+ fs.Var(flags.NewURLsValue(embed.DefaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.")
|
|
|
+ fs.Var(flags.NewURLsValue(embed.DefaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.")
|
|
|
+ fs.StringVar(&cfg.Durl, "discovery", cfg.Durl, "Discovery URL used to bootstrap the cluster.")
|
|
|
fs.Var(cfg.fallback, "discovery-fallback", fmt.Sprintf("Valid values include %s", strings.Join(cfg.fallback.Values, ", ")))
|
|
|
if err := cfg.fallback.Set(fallbackFlagProxy); err != nil {
|
|
|
// Should never happen.
|
|
|
plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
|
|
|
}
|
|
|
- fs.StringVar(&cfg.Dproxy, "discovery-proxy", "", "HTTP proxy to use for traffic to discovery service.")
|
|
|
- fs.StringVar(&cfg.DNSCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster.")
|
|
|
- fs.StringVar(&cfg.InitialCluster, "initial-cluster", initialClusterFromName(defaultName), "Initial cluster configuration for bootstrapping.")
|
|
|
- fs.StringVar(&cfg.InitialClusterToken, "initial-cluster-token", "etcd-cluster", "Initial cluster token for the etcd cluster during bootstrap.")
|
|
|
+ fs.StringVar(&cfg.Dproxy, "discovery-proxy", cfg.Dproxy, "HTTP proxy to use for traffic to discovery service.")
|
|
|
+ fs.StringVar(&cfg.DNSCluster, "discovery-srv", cfg.DNSCluster, "DNS domain used to bootstrap initial cluster.")
|
|
|
+ fs.StringVar(&cfg.InitialCluster, "initial-cluster", cfg.InitialCluster, "Initial cluster configuration for bootstrapping.")
|
|
|
+ fs.StringVar(&cfg.InitialClusterToken, "initial-cluster-token", cfg.InitialClusterToken, "Initial cluster token for the etcd cluster during bootstrap.")
|
|
|
fs.Var(cfg.clusterState, "initial-cluster-state", "Initial cluster state ('new' or 'existing').")
|
|
|
- if err := cfg.clusterState.Set(clusterStateFlagNew); err != nil {
|
|
|
+ if err := cfg.clusterState.Set(embed.ClusterStateFlagNew); err != nil {
|
|
|
// Should never happen.
|
|
|
plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
|
|
|
}
|
|
|
- fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", false, "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.")
|
|
|
|
|
|
// proxy
|
|
|
fs.Var(cfg.proxy, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(cfg.proxy.Values, ", ")))
|
|
|
@@ -226,24 +161,24 @@ func NewConfig() *config {
|
|
|
// Should never happen.
|
|
|
plog.Panicf("unexpected error setting up proxyFlag: %v", err)
|
|
|
}
|
|
|
- fs.UintVar(&cfg.ProxyFailureWaitMs, "proxy-failure-wait", 5000, "Time (in milliseconds) an endpoint will be held in a failed state.")
|
|
|
- fs.UintVar(&cfg.ProxyRefreshIntervalMs, "proxy-refresh-interval", 30000, "Time (in milliseconds) of the endpoints refresh interval.")
|
|
|
- fs.UintVar(&cfg.ProxyDialTimeoutMs, "proxy-dial-timeout", 1000, "Time (in milliseconds) for a dial to timeout.")
|
|
|
- fs.UintVar(&cfg.ProxyWriteTimeoutMs, "proxy-write-timeout", 5000, "Time (in milliseconds) for a write to timeout.")
|
|
|
- fs.UintVar(&cfg.ProxyReadTimeoutMs, "proxy-read-timeout", 0, "Time (in milliseconds) for a read to timeout.")
|
|
|
+ fs.UintVar(&cfg.ProxyFailureWaitMs, "proxy-failure-wait", cfg.ProxyFailureWaitMs, "Time (in milliseconds) an endpoint will be held in a failed state.")
|
|
|
+ fs.UintVar(&cfg.ProxyRefreshIntervalMs, "proxy-refresh-interval", cfg.ProxyRefreshIntervalMs, "Time (in milliseconds) of the endpoints refresh interval.")
|
|
|
+ fs.UintVar(&cfg.ProxyDialTimeoutMs, "proxy-dial-timeout", cfg.ProxyDialTimeoutMs, "Time (in milliseconds) for a dial to timeout.")
|
|
|
+ fs.UintVar(&cfg.ProxyWriteTimeoutMs, "proxy-write-timeout", cfg.ProxyWriteTimeoutMs, "Time (in milliseconds) for a write to timeout.")
|
|
|
+ fs.UintVar(&cfg.ProxyReadTimeoutMs, "proxy-read-timeout", cfg.ProxyReadTimeoutMs, "Time (in milliseconds) for a read to timeout.")
|
|
|
|
|
|
// security
|
|
|
- fs.StringVar(&cfg.clientTLSInfo.CAFile, "ca-file", "", "DEPRECATED: Path to the client server TLS CA file.")
|
|
|
- fs.StringVar(&cfg.clientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
|
|
|
- fs.StringVar(&cfg.clientTLSInfo.KeyFile, "key-file", "", "Path to the client server TLS key file.")
|
|
|
- fs.BoolVar(&cfg.clientTLSInfo.ClientCertAuth, "client-cert-auth", false, "Enable client cert authentication.")
|
|
|
- fs.StringVar(&cfg.clientTLSInfo.TrustedCAFile, "trusted-ca-file", "", "Path to the client server TLS trusted CA key file.")
|
|
|
+ fs.StringVar(&cfg.ClientTLSInfo.CAFile, "ca-file", "", "DEPRECATED: Path to the client server TLS CA file.")
|
|
|
+ fs.StringVar(&cfg.ClientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
|
|
|
+ fs.StringVar(&cfg.ClientTLSInfo.KeyFile, "key-file", "", "Path to the client server TLS key file.")
|
|
|
+ fs.BoolVar(&cfg.ClientTLSInfo.ClientCertAuth, "client-cert-auth", false, "Enable client cert authentication.")
|
|
|
+ fs.StringVar(&cfg.ClientTLSInfo.TrustedCAFile, "trusted-ca-file", "", "Path to the client server TLS trusted CA key file.")
|
|
|
fs.BoolVar(&cfg.ClientAutoTLS, "auto-tls", false, "Client TLS using generated certificates")
|
|
|
- fs.StringVar(&cfg.peerTLSInfo.CAFile, "peer-ca-file", "", "DEPRECATED: Path to the peer server TLS CA file.")
|
|
|
- fs.StringVar(&cfg.peerTLSInfo.CertFile, "peer-cert-file", "", "Path to the peer server TLS cert file.")
|
|
|
- fs.StringVar(&cfg.peerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.")
|
|
|
- fs.BoolVar(&cfg.peerTLSInfo.ClientCertAuth, "peer-client-cert-auth", false, "Enable peer client cert authentication.")
|
|
|
- fs.StringVar(&cfg.peerTLSInfo.TrustedCAFile, "peer-trusted-ca-file", "", "Path to the peer server TLS trusted CA file.")
|
|
|
+ fs.StringVar(&cfg.PeerTLSInfo.CAFile, "peer-ca-file", "", "DEPRECATED: Path to the peer server TLS CA file.")
|
|
|
+ fs.StringVar(&cfg.PeerTLSInfo.CertFile, "peer-cert-file", "", "Path to the peer server TLS cert file.")
|
|
|
+ fs.StringVar(&cfg.PeerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.")
|
|
|
+ fs.BoolVar(&cfg.PeerTLSInfo.ClientCertAuth, "peer-client-cert-auth", false, "Enable peer client cert authentication.")
|
|
|
+ fs.StringVar(&cfg.PeerTLSInfo.TrustedCAFile, "peer-trusted-ca-file", "", "Path to the peer server TLS trusted CA file.")
|
|
|
fs.BoolVar(&cfg.PeerAutoTLS, "peer-auto-tls", false, "Peer TLS using generated certificates")
|
|
|
|
|
|
// logging
|
|
|
@@ -256,10 +191,10 @@ func NewConfig() *config {
|
|
|
// version
|
|
|
fs.BoolVar(&cfg.printVersion, "version", false, "Print the version and exit.")
|
|
|
|
|
|
- fs.IntVar(&cfg.autoCompactionRetention, "auto-compaction-retention", 0, "Auto compaction retention for mvcc key value store in hour. 0 means disable auto compaction.")
|
|
|
+ fs.IntVar(&cfg.AutoCompactionRetention, "auto-compaction-retention", 0, "Auto compaction retention for mvcc key value store in hour. 0 means disable auto compaction.")
|
|
|
|
|
|
// pprof profiler via HTTP
|
|
|
- fs.BoolVar(&cfg.enablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof/\"")
|
|
|
+ fs.BoolVar(&cfg.EnablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof/\"")
|
|
|
|
|
|
// ignored
|
|
|
for _, f := range cfg.ignored {
|
|
|
@@ -268,7 +203,7 @@ func NewConfig() *config {
|
|
|
return cfg
|
|
|
}
|
|
|
|
|
|
-func (cfg *config) Parse(arguments []string) error {
|
|
|
+func (cfg *config) parse(arguments []string) error {
|
|
|
perr := cfg.FlagSet.Parse(arguments)
|
|
|
switch perr {
|
|
|
case nil:
|
|
|
@@ -293,11 +228,10 @@ func (cfg *config) Parse(arguments []string) error {
|
|
|
var err error
|
|
|
if cfg.configFile != "" {
|
|
|
plog.Infof("Loading server configuration from %q", cfg.configFile)
|
|
|
- err = cfg.configFromFile()
|
|
|
+ err = cfg.configFromFile(cfg.configFile)
|
|
|
} else {
|
|
|
err = cfg.configFromCmdLine()
|
|
|
}
|
|
|
-
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
@@ -307,152 +241,72 @@ func (cfg *config) configFromCmdLine() error {
|
|
|
plog.Fatalf("%v", err)
|
|
|
}
|
|
|
|
|
|
- cfg.lpurls = flags.URLsFromFlag(cfg.FlagSet, "listen-peer-urls")
|
|
|
- cfg.apurls = flags.URLsFromFlag(cfg.FlagSet, "initial-advertise-peer-urls")
|
|
|
- cfg.lcurls = flags.URLsFromFlag(cfg.FlagSet, "listen-client-urls")
|
|
|
- cfg.acurls = flags.URLsFromFlag(cfg.FlagSet, "advertise-client-urls")
|
|
|
-
|
|
|
- return cfg.validateConfig(func(field string) bool {
|
|
|
- return flags.IsSet(cfg.FlagSet, field)
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-func (cfg *config) configFromFile() error {
|
|
|
- b, err := ioutil.ReadFile(cfg.configFile)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ cfg.LPUrls = flags.URLsFromFlag(cfg.FlagSet, "listen-peer-urls")
|
|
|
+ cfg.APUrls = flags.URLsFromFlag(cfg.FlagSet, "initial-advertise-peer-urls")
|
|
|
+ cfg.LCUrls = flags.URLsFromFlag(cfg.FlagSet, "listen-client-urls")
|
|
|
+ cfg.ACUrls = flags.URLsFromFlag(cfg.FlagSet, "advertise-client-urls")
|
|
|
+ cfg.ClusterState = cfg.clusterState.String()
|
|
|
+ cfg.Fallback = cfg.fallback.String()
|
|
|
+ cfg.Proxy = cfg.proxy.String()
|
|
|
+
|
|
|
+ // disable default advertise-client-urls if lcurls is set
|
|
|
+ missingAC := flags.IsSet(cfg.FlagSet, "listen-client-urls") && !flags.IsSet(cfg.FlagSet, "advertise-client-urls")
|
|
|
+ if !cfg.mayBeProxy() && missingAC {
|
|
|
+ cfg.ACUrls = nil
|
|
|
}
|
|
|
|
|
|
- err = yaml.Unmarshal(b, cfg)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ // disable default initial-cluster if discovery is set
|
|
|
+ if (cfg.Durl != "" || cfg.DNSCluster != "") && !flags.IsSet(cfg.FlagSet, "initial-cluster") {
|
|
|
+ cfg.InitialCluster = ""
|
|
|
}
|
|
|
|
|
|
- if cfg.LPUrlsCfgFile != "" {
|
|
|
- u, err := types.NewURLs(strings.Split(cfg.LPUrlsCfgFile, ","))
|
|
|
- if err != nil {
|
|
|
- plog.Fatalf("unexpected error setting up listen-peer-urls: %v", err)
|
|
|
- }
|
|
|
- cfg.lpurls = []url.URL(u)
|
|
|
- }
|
|
|
-
|
|
|
- if cfg.LCUrlsCfgFile != "" {
|
|
|
- u, err := types.NewURLs(strings.Split(cfg.LCUrlsCfgFile, ","))
|
|
|
- if err != nil {
|
|
|
- plog.Fatalf("unexpected error setting up listen-client-urls: %v", err)
|
|
|
- }
|
|
|
- cfg.lcurls = []url.URL(u)
|
|
|
- }
|
|
|
-
|
|
|
- if cfg.CorsCfgFile != "" {
|
|
|
- if err := cfg.corsInfo.Set(cfg.CorsCfgFile); err != nil {
|
|
|
- plog.Panicf("unexpected error setting up cors: %v", err)
|
|
|
- }
|
|
|
- }
|
|
|
+ return cfg.validate()
|
|
|
+}
|
|
|
|
|
|
- if cfg.ApurlsCfgFile != "" {
|
|
|
- u, err := types.NewURLs(strings.Split(cfg.ApurlsCfgFile, ","))
|
|
|
- if err != nil {
|
|
|
- plog.Fatalf("unexpected error setting up initial-advertise-peer-urls: %v", err)
|
|
|
- }
|
|
|
- cfg.apurls = []url.URL(u)
|
|
|
+func (cfg *config) configFromFile(path string) error {
|
|
|
+ eCfg, err := embed.ConfigFromFile(path)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
+ cfg.Config = *eCfg
|
|
|
|
|
|
- if cfg.AcurlsCfgFile != "" {
|
|
|
- u, err := types.NewURLs(strings.Split(cfg.AcurlsCfgFile, ","))
|
|
|
- if err != nil {
|
|
|
- plog.Fatalf("unexpected error setting up advertise-peer-urls: %v", err)
|
|
|
- }
|
|
|
- cfg.acurls = []url.URL(u)
|
|
|
+ // load extra config information
|
|
|
+ b, rerr := ioutil.ReadFile(path)
|
|
|
+ if rerr != nil {
|
|
|
+ return rerr
|
|
|
}
|
|
|
-
|
|
|
- if cfg.ClusterStateCfgFile != "" {
|
|
|
- if err := cfg.clusterState.Set(cfg.ClusterStateCfgFile); err != nil {
|
|
|
- plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
|
|
|
- }
|
|
|
+ if yerr := yaml.Unmarshal(b, &cfg.configProxy); yerr != nil {
|
|
|
+ return yerr
|
|
|
}
|
|
|
-
|
|
|
- if cfg.FallbackCfgFile != "" {
|
|
|
- if err := cfg.fallback.Set(cfg.FallbackCfgFile); err != nil {
|
|
|
+ if cfg.FallbackJSON != "" {
|
|
|
+ if err := cfg.fallback.Set(cfg.FallbackJSON); err != nil {
|
|
|
plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
|
|
|
}
|
|
|
+ cfg.Fallback = cfg.fallback.String()
|
|
|
}
|
|
|
-
|
|
|
- if cfg.ProxyCfgFile != "" {
|
|
|
- if err := cfg.proxy.Set(cfg.ProxyCfgFile); err != nil {
|
|
|
+ if cfg.ProxyJSON != "" {
|
|
|
+ if err := cfg.proxy.Set(cfg.ProxyJSON); err != nil {
|
|
|
plog.Panicf("unexpected error setting up proxyFlag: %v", err)
|
|
|
}
|
|
|
+ cfg.Proxy = cfg.proxy.String()
|
|
|
}
|
|
|
-
|
|
|
- copySecurityDetails := func(tls *transport.TLSInfo, ysc *securityConfig) {
|
|
|
- tls.CAFile = ysc.CAFile
|
|
|
- tls.CertFile = ysc.CertFile
|
|
|
- tls.KeyFile = ysc.KeyFile
|
|
|
- tls.ClientCertAuth = ysc.CertAuth
|
|
|
- tls.TrustedCAFile = ysc.TrustedCAFile
|
|
|
- }
|
|
|
- copySecurityDetails(&cfg.clientTLSInfo, &cfg.ClientSecurityCfgFile)
|
|
|
- copySecurityDetails(&cfg.peerTLSInfo, &cfg.PeerSecurityCfgFile)
|
|
|
- cfg.ClientAutoTLS = cfg.ClientSecurityCfgFile.AutoTLS
|
|
|
- cfg.PeerAutoTLS = cfg.PeerSecurityCfgFile.AutoTLS
|
|
|
-
|
|
|
- fieldsToBeChecked := map[string]bool{
|
|
|
- "discovery": (cfg.Durl != ""),
|
|
|
- "listen-client-urls": (cfg.LCUrlsCfgFile != ""),
|
|
|
- "advertise-client-urls": (cfg.AcurlsCfgFile != ""),
|
|
|
- "initial-cluster": (cfg.InitialCluster != ""),
|
|
|
- "discovery-srv": (cfg.DNSCluster != ""),
|
|
|
- }
|
|
|
-
|
|
|
- return cfg.validateConfig(func(field string) bool {
|
|
|
- return fieldsToBeChecked[field]
|
|
|
- })
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
-func (cfg *config) validateConfig(isSet func(field string) bool) error {
|
|
|
- // when etcd runs in member mode user needs to set --advertise-client-urls if --listen-client-urls is set.
|
|
|
- // TODO(yichengq): check this for joining through discovery service case
|
|
|
- mayFallbackToProxy := isSet("discovery") && cfg.fallback.String() == fallbackFlagProxy
|
|
|
- mayBeProxy := cfg.proxy.String() != proxyFlagOff || mayFallbackToProxy
|
|
|
- if !mayBeProxy {
|
|
|
- if isSet("listen-client-urls") && !isSet("advertise-client-urls") {
|
|
|
- return errUnsetAdvertiseClientURLsFlag
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Check if conflicting flags are passed.
|
|
|
- nSet := 0
|
|
|
- for _, v := range []bool{isSet("discovery"), isSet("initial-cluster"), isSet("discovery-srv")} {
|
|
|
- if v {
|
|
|
- nSet++
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if nSet > 1 {
|
|
|
- return ErrConflictBootstrapFlags
|
|
|
- }
|
|
|
-
|
|
|
- if 5*cfg.TickMs > cfg.ElectionMs {
|
|
|
- return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs)
|
|
|
- }
|
|
|
- if cfg.ElectionMs > maxElectionMs {
|
|
|
- return fmt.Errorf("--election-timeout[%vms] is too long, and should be set less than %vms", cfg.ElectionMs, maxElectionMs)
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
+func (cfg *config) mayBeProxy() bool {
|
|
|
+ mayFallbackToProxy := cfg.Durl != "" && cfg.Fallback == fallbackFlagProxy
|
|
|
+ return cfg.Proxy != proxyFlagOff || mayFallbackToProxy
|
|
|
}
|
|
|
|
|
|
-func initialClusterFromName(name string) string {
|
|
|
- n := name
|
|
|
- if name == "" {
|
|
|
- n = defaultName
|
|
|
+func (cfg *config) validate() error {
|
|
|
+ err := cfg.Config.Validate()
|
|
|
+ // TODO(yichengq): check this for joining through discovery service case
|
|
|
+ if err == embed.ErrUnsetAdvertiseClientURLsFlag && cfg.mayBeProxy() {
|
|
|
+ return nil
|
|
|
}
|
|
|
- return fmt.Sprintf("%s=http://localhost:2380", n)
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
-func (cfg config) isNewCluster() bool { return cfg.clusterState.String() == clusterStateFlagNew }
|
|
|
func (cfg config) isProxy() bool { return cfg.proxy.String() != proxyFlagOff }
|
|
|
func (cfg config) isReadonlyProxy() bool { return cfg.proxy.String() == proxyFlagReadonly }
|
|
|
func (cfg config) shouldFallbackToProxy() bool { return cfg.fallback.String() == fallbackFlagProxy }
|
|
|
-
|
|
|
-func (cfg config) electionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) }
|