Add some comments to the main function
This commit is contained in:
parent
b0e41d5c35
commit
61104a9272
6
main.go
6
main.go
|
@ -19,6 +19,7 @@ import (
|
||||||
var version = "dev"
|
var version = "dev"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// General initialization
|
||||||
config, err := loadConfig()
|
config, err := loadConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
@ -33,22 +34,24 @@ func main() {
|
||||||
}
|
}
|
||||||
logrus.SetLevel(logLevel)
|
logrus.SetLevel(logLevel)
|
||||||
|
|
||||||
|
// Create the wireguard and cluster configuration
|
||||||
wgstate, err := wg.New(config.Interface, config.WireguardPort)
|
wgstate, err := wg.New(config.Interface, config.WireguardPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("could not instantiate wireguard controller")
|
logrus.WithError(err).Fatal("could not instantiate wireguard controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
cluster, err := cluster.New(config.Init, config.ClusterKey, config.BindAddr, config.ClusterPort, config.UseIPAsName)
|
cluster, err := cluster.New(config.Init, config.ClusterKey, config.BindAddr, config.ClusterPort, config.UseIPAsName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("could not create cluster")
|
logrus.WithError(err).Fatal("could not create cluster")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assign a local node address and propagate it to the cluster
|
||||||
wgstate.AssignOverlayAddr((*net.IPNet)(config.OverlayNet), cluster.LocalName)
|
wgstate.AssignOverlayAddr((*net.IPNet)(config.OverlayNet), cluster.LocalName)
|
||||||
localNode := common.Node{}
|
localNode := common.Node{}
|
||||||
localNode.OverlayAddr = wgstate.OverlayAddr
|
localNode.OverlayAddr = wgstate.OverlayAddr
|
||||||
localNode.PubKey = wgstate.PubKey.String()
|
localNode.PubKey = wgstate.PubKey.String()
|
||||||
cluster.Update(localNode)
|
cluster.Update(localNode)
|
||||||
|
|
||||||
|
// Join the cluster
|
||||||
nodec := cluster.Members() // avoid deadlocks by starting before join
|
nodec := cluster.Members() // avoid deadlocks by starting before join
|
||||||
if err := backoff.RetryNotify(
|
if err := backoff.RetryNotify(
|
||||||
func() error { return cluster.Join(config.Join) },
|
func() error { return cluster.Join(config.Join) },
|
||||||
|
@ -60,6 +63,7 @@ func main() {
|
||||||
logrus.WithError(err).Fatal("could not join cluster")
|
logrus.WithError(err).Fatal("could not join cluster")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main loop
|
||||||
incomingSigs := make(chan os.Signal, 1)
|
incomingSigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(incomingSigs, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(incomingSigs, syscall.SIGTERM, os.Interrupt)
|
||||||
logrus.Debug("waiting for cluster events")
|
logrus.Debug("waiting for cluster events")
|
||||||
|
|
Loading…
Reference in New Issue