Only listen on loopback when resetting

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/5731/head
Brad Davidson 3 years ago committed by Brad Davidson
parent 3399afed83
commit 6fad63583b

@ -756,35 +756,57 @@ func (e *ETCD) migrateFromSQLite(ctx context.Context) error {
return os.Rename(sqliteFile(e.config), sqliteFile(e.config)+".migrated") return os.Rename(sqliteFile(e.config), sqliteFile(e.config)+".migrated")
} }
// peerURL returns the peer access address for the local node // peerURL returns the external peer access address for the local node.
func (e *ETCD) peerURL() string { func (e *ETCD) peerURL() string {
return fmt.Sprintf("https://%s", net.JoinHostPort(e.address, "2380")) return fmt.Sprintf("https://%s", net.JoinHostPort(e.address, "2380"))
} }
// clientURL returns the client access address for the local node // listenClientURLs returns a list of URLs to bind to for peer connections.
// During cluster reset/restore, we only listen on loopback to avoid having peers
// connect mid-process.
func (e *ETCD) listenPeerURLs(reset bool) string {
peerURLs := fmt.Sprintf("https://%s:2380", e.config.Loopback())
if !reset {
peerURLs += "," + e.peerURL()
}
return peerURLs
}
// clientURL returns the external client access address for the local node.
func (e *ETCD) clientURL() string { func (e *ETCD) clientURL() string {
return fmt.Sprintf("https://%s", net.JoinHostPort(e.address, "2379")) return fmt.Sprintf("https://%s", net.JoinHostPort(e.address, "2379"))
} }
// metricsURL returns the metrics access address // listenClientURLs returns a list of URLs to bind to for client connections.
func (e *ETCD) metricsURL(expose bool) string { // During cluster reset/restore, we only listen on loopback to avoid having the apiserver
address := fmt.Sprintf("http://%s:2381", e.config.Loopback()) // connect mid-process.
if expose { func (e *ETCD) listenClientURLs(reset bool) string {
address = fmt.Sprintf("http://%s,%s", net.JoinHostPort(e.address, "2381"), address) clientURLs := fmt.Sprintf("https://%s:2379", e.config.Loopback())
if !reset {
clientURLs += "," + e.clientURL()
}
return clientURLs
}
// listenMetricsURLs returns a list of URLs to bind to for metrics connections.
func (e *ETCD) listenMetricsURLs(reset bool) string {
metricsURLs := fmt.Sprintf("http://%s:2381", e.config.Loopback())
if !reset && e.config.EtcdExposeMetrics {
metricsURLs += "," + fmt.Sprintf("http://%s", net.JoinHostPort(e.address, "2381"))
} }
return address return metricsURLs
} }
// cluster returns ETCDConfig for a cluster // cluster calls the executor to start etcd running with the provided configuration.
func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.InitialOptions) error { func (e *ETCD) cluster(ctx context.Context, reset bool, options executor.InitialOptions) error {
ctx, e.cancel = context.WithCancel(ctx) ctx, e.cancel = context.WithCancel(ctx)
return executor.ETCD(ctx, executor.ETCDConfig{ return executor.ETCD(ctx, executor.ETCDConfig{
Name: e.name, Name: e.name,
InitialOptions: options, InitialOptions: options,
ForceNewCluster: forceNew, ForceNewCluster: reset,
ListenClientURLs: e.clientURL() + "," + fmt.Sprintf("https://%s:2379", e.config.Loopback()), ListenClientURLs: e.listenClientURLs(reset),
ListenMetricsURLs: e.metricsURL(e.config.EtcdExposeMetrics), ListenMetricsURLs: e.listenMetricsURLs(reset),
ListenPeerURLs: e.peerURL(), ListenPeerURLs: e.listenPeerURLs(reset),
AdvertiseClientURLs: e.clientURL(), AdvertiseClientURLs: e.clientURL(),
DataDir: DBDir(e.config), DataDir: DBDir(e.config),
ServerTrust: executor.ServerTrust{ ServerTrust: executor.ServerTrust{
@ -799,6 +821,7 @@ func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.Init
ClientCertAuth: true, ClientCertAuth: true,
TrustedCAFile: e.config.Runtime.ETCDPeerCA, TrustedCAFile: e.config.Runtime.ETCDPeerCA,
}, },
SnapshotCount: 10000,
ElectionTimeout: 5000, ElectionTimeout: 5000,
HeartbeatInterval: 500, HeartbeatInterval: 500,
Logger: "zap", Logger: "zap",
@ -842,6 +865,7 @@ func (e *ETCD) StartEmbeddedTemporary(ctx context.Context) error {
Logger: "zap", Logger: "zap",
HeartbeatInterval: 500, HeartbeatInterval: 500,
ElectionTimeout: 5000, ElectionTimeout: 5000,
SnapshotCount: 10000,
Name: e.name, Name: e.name,
LogOutputs: []string{"stderr"}, LogOutputs: []string{"stderr"},
ExperimentalInitialCorruptCheck: true, ExperimentalInitialCorruptCheck: true,

Loading…
Cancel
Save