etcd: Add advertise urls to cli
This patch adds the option to specify URLs to advertise for clients and peers. This will facilitate etcd communication through nat, where we want to listen on a local IP, but expose a public IP to clients/peers.
This commit is contained in:
19
etcd/etcd.go
19
etcd/etcd.go
@@ -181,6 +181,8 @@ type EmbdEtcd struct { // EMBeddeD etcd
|
||||
endpoints etcdtypes.URLsMap // map of servers a client could connect to
|
||||
clientURLs etcdtypes.URLs // locations to listen for clients if i am a server
|
||||
serverURLs etcdtypes.URLs // locations to listen for servers if i am a server (peer)
|
||||
advertiseClientURLs etcdtypes.URLs // client urls to advertise
|
||||
advertiseServerURLs etcdtypes.URLs // server urls to advertise
|
||||
noServer bool // disable all server peering if true
|
||||
|
||||
// local tracked state
|
||||
@@ -208,7 +210,7 @@ type EmbdEtcd struct { // EMBeddeD etcd
|
||||
}
|
||||
|
||||
// NewEmbdEtcd creates the top level embedded etcd struct client and server obj.
|
||||
func NewEmbdEtcd(hostname string, seeds, clientURLs, serverURLs etcdtypes.URLs, noServer bool, idealClusterSize uint16, flags Flags, prefix string, converger converger.Converger) *EmbdEtcd {
|
||||
func NewEmbdEtcd(hostname string, seeds, clientURLs, serverURLs, advertiseClientURLs, advertiseServerURLs etcdtypes.URLs, noServer bool, idealClusterSize uint16, flags Flags, prefix string, converger converger.Converger) *EmbdEtcd {
|
||||
endpoints := make(etcdtypes.URLsMap)
|
||||
if hostname == seedSentinel { // safety
|
||||
return nil
|
||||
@@ -233,6 +235,8 @@ func NewEmbdEtcd(hostname string, seeds, clientURLs, serverURLs etcdtypes.URLs,
|
||||
endpoints: endpoints,
|
||||
clientURLs: clientURLs,
|
||||
serverURLs: serverURLs,
|
||||
advertiseClientURLs: advertiseClientURLs,
|
||||
advertiseServerURLs: advertiseServerURLs,
|
||||
noServer: noServer,
|
||||
|
||||
idealClusterSize: idealClusterSize,
|
||||
@@ -1647,14 +1651,23 @@ func (obj *EmbdEtcd) StartServer(newCluster bool, peerURLsMap etcdtypes.URLsMap)
|
||||
initialPeerURLsMap[memberName] = peerURLs
|
||||
}
|
||||
|
||||
aCUrls := obj.clientURLs
|
||||
if len(obj.advertiseClientURLs) > 0 {
|
||||
aCUrls = obj.advertiseClientURLs
|
||||
}
|
||||
aPUrls := peerURLs
|
||||
if len(obj.advertiseServerURLs) > 0 {
|
||||
aPUrls = obj.advertiseServerURLs
|
||||
}
|
||||
|
||||
// embed etcd
|
||||
cfg := embed.NewConfig()
|
||||
cfg.Name = memberName // hostname
|
||||
cfg.Dir = obj.dataDir
|
||||
cfg.ACUrls = obj.clientURLs
|
||||
cfg.APUrls = peerURLs
|
||||
cfg.LCUrls = obj.clientURLs
|
||||
cfg.LPUrls = peerURLs
|
||||
cfg.ACUrls = aCUrls
|
||||
cfg.APUrls = aPUrls
|
||||
cfg.StrictReconfigCheck = false // XXX: workaround https://github.com/coreos/etcd/issues/6305
|
||||
|
||||
cfg.InitialCluster = initialPeerURLsMap.String() // including myself!
|
||||
|
||||
16
lib/cli.go
16
lib/cli.go
@@ -114,6 +114,8 @@ func run(c *cli.Context) error {
|
||||
obj.Seeds = c.StringSlice("seeds")
|
||||
obj.ClientURLs = c.StringSlice("client-urls")
|
||||
obj.ServerURLs = c.StringSlice("server-urls")
|
||||
obj.AdvertiseClientURLs = c.StringSlice("advertise-client-urls")
|
||||
obj.AdvertiseServerURLs = c.StringSlice("advertise-server-urls")
|
||||
obj.IdealClusterSize = c.Int("ideal-cluster-size")
|
||||
obj.NoServer = c.Bool("no-server")
|
||||
|
||||
@@ -318,6 +320,20 @@ func CLI(program, version string, flags Flags) error {
|
||||
Usage: "list of URLs to listen on for server (peer) traffic",
|
||||
EnvVar: "MGMT_SERVER_URLS",
|
||||
},
|
||||
// port 2379 and 4001 are common
|
||||
cli.StringSliceFlag{
|
||||
Name: "advertise-client-urls",
|
||||
Value: &cli.StringSlice{},
|
||||
Usage: "list of URLs to listen on for client traffic",
|
||||
EnvVar: "MGMT_ADVERTISE_CLIENT_URLS",
|
||||
},
|
||||
// port 2380 and 7001 are common
|
||||
cli.StringSliceFlag{
|
||||
Name: "advertise-server-urls, advertise-peer-urls",
|
||||
Value: &cli.StringSlice{},
|
||||
Usage: "list of URLs to listen on for server (peer) traffic",
|
||||
EnvVar: "MGMT_ADVERTISE_SERVER_URLS",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "ideal-cluster-size",
|
||||
Value: -1,
|
||||
|
||||
18
lib/main.go
18
lib/main.go
@@ -79,6 +79,8 @@ type Main struct {
|
||||
Seeds []string // default etc client endpoint
|
||||
ClientURLs []string // list of URLs to listen on for client traffic
|
||||
ServerURLs []string // list of URLs to listen on for server (peer) traffic
|
||||
AdvertiseClientURLs []string // list of URLs to advertise for client traffic
|
||||
AdvertiseServerURLs []string // list of URLs to advertise for server (peer) traffic
|
||||
IdealClusterSize int // ideal number of server peers in cluster; only read by initial server
|
||||
NoServer bool // do not let other servers peer with me
|
||||
|
||||
@@ -91,6 +93,8 @@ type Main struct {
|
||||
seeds etcdtypes.URLs // processed seeds value
|
||||
clientURLs etcdtypes.URLs // processed client urls value
|
||||
serverURLs etcdtypes.URLs // processed server urls value
|
||||
advertiseClientURLs etcdtypes.URLs // processed advertise client urls value
|
||||
advertiseServerURLs etcdtypes.URLs // processed advertise server urls value
|
||||
idealClusterSize uint16 // processed ideal cluster size value
|
||||
|
||||
NoPgp bool // disallow pgp functionality
|
||||
@@ -173,6 +177,18 @@ func (obj *Main) Init() error {
|
||||
if err != nil && len(obj.ServerURLs) > 0 {
|
||||
return fmt.Errorf("the ServerURLs didn't parse correctly")
|
||||
}
|
||||
obj.advertiseClientURLs, err = etcdtypes.NewURLs(
|
||||
util.FlattenListWithSplit(obj.AdvertiseClientURLs, []string{",", ";", " "}),
|
||||
)
|
||||
if err != nil && len(obj.AdvertiseClientURLs) > 0 {
|
||||
return fmt.Errorf("the AdvertiseClientURLs didn't parse correctly")
|
||||
}
|
||||
obj.advertiseServerURLs, err = etcdtypes.NewURLs(
|
||||
util.FlattenListWithSplit(obj.AdvertiseServerURLs, []string{",", ";", " "}),
|
||||
)
|
||||
if err != nil && len(obj.AdvertiseServerURLs) > 0 {
|
||||
return fmt.Errorf("the AdvertiseServerURLs didn't parse correctly")
|
||||
}
|
||||
|
||||
obj.exit = make(chan error)
|
||||
return nil
|
||||
@@ -330,6 +346,8 @@ func (obj *Main) Run() error {
|
||||
obj.seeds,
|
||||
obj.clientURLs,
|
||||
obj.serverURLs,
|
||||
obj.advertiseClientURLs,
|
||||
obj.advertiseServerURLs,
|
||||
obj.NoServer,
|
||||
obj.idealClusterSize,
|
||||
etcd.Flags{
|
||||
|
||||
Reference in New Issue
Block a user