Do not pass the config object to newCluster

Decouple the config structure from the cluster management and
stop passing the config object around.
This commit is contained in:
kaiyou 2020-05-06 19:19:55 +02:00 committed by Leo Antunes
parent 97525f4b10
commit 366f906d5d
2 changed files with 8 additions and 10 deletions

View File

@ -34,11 +34,9 @@ type cluster struct {
const statePath = "/var/lib/wesher/state.json"
func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) {
clusterKey := config.ClusterKey
func newCluster(init bool, clusterKey []byte, bindAddr string, bindIface string, bindPort int, useIPAsName bool, getMeta func(int) []byte) (*cluster, error) {
state := &ClusterState{}
if !config.Init {
if !init {
loadState(state)
}
@ -47,7 +45,7 @@ func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) {
return nil, err
}
bindAddr, err := computeBindAddr(config.BindAddr, config.BindIface)
bindAddr, err = computeBindAddr(bindAddr, bindIface)
if err != nil {
return nil, err
}
@ -56,10 +54,10 @@ func newCluster(config *config, getMeta func(int) []byte) (*cluster, error) {
mlConfig.LogOutput = logrus.StandardLogger().WriterLevel(logrus.DebugLevel)
mlConfig.SecretKey = clusterKey
mlConfig.BindAddr = bindAddr
mlConfig.BindPort = config.ClusterPort
mlConfig.AdvertisePort = config.ClusterPort
if config.UseIPAsName && config.BindAddr != "0.0.0.0" {
mlConfig.Name = config.BindAddr
mlConfig.BindPort = bindPort
mlConfig.AdvertisePort = bindPort
if useIPAsName && bindAddr != "0.0.0.0" {
mlConfig.Name = bindAddr
}
ml, err := memberlist.Create(mlConfig)

View File

@ -42,7 +42,7 @@ func main() {
}, limit)
}
cluster, err := newCluster(config, getMeta)
cluster, err := newCluster(config.Init, config.ClusterKey, config.BindAddr, config.BindIface, config.ClusterPort, config.UseIPAsName, getMeta)
if err != nil {
logrus.WithError(err).Fatal("could not create cluster")
}