mirror of
https://github.com/spaytac/orbiter.git
synced 2026-01-22 10:24:41 +00:00
Bootstrap autodetection and swarm zero conf
Fixed #9 This PR bootstrap the autodetection feature: 1. It works when the configuration file is not setup. Right know I am not going to manage the merge of double sources (autodetection and configuration file). 2. At the moment only Docker Swarm will support this feature.
This commit is contained in:
parent
046d999a1b
commit
db7f674976
@ -25,7 +25,7 @@ func (c *DaemonCmd) Run(args []string) int {
|
|||||||
var debug bool
|
var debug bool
|
||||||
cmdFlags := flag.NewFlagSet("event", flag.ExitOnError)
|
cmdFlags := flag.NewFlagSet("event", flag.ExitOnError)
|
||||||
cmdFlags.StringVar(&port, "port", ":8000", "port")
|
cmdFlags.StringVar(&port, "port", ":8000", "port")
|
||||||
cmdFlags.StringVar(&configPath, "config", "/etc/deamon.yml", "config")
|
cmdFlags.StringVar(&configPath, "config", "", "config")
|
||||||
cmdFlags.BoolVar(&debug, "debug", false, "debug")
|
cmdFlags.BoolVar(&debug, "debug", false, "debug")
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
logrus.WithField("error", err).Warn("Problem to parse arguments.")
|
logrus.WithField("error", err).Warn("Problem to parse arguments.")
|
||||||
@ -35,16 +35,23 @@ func (c *DaemonCmd) Run(args []string) int {
|
|||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
logrus.Debug("Daemon started in debug mode")
|
logrus.Debug("Daemon started in debug mode")
|
||||||
}
|
}
|
||||||
|
var coreEngine core.Core
|
||||||
|
if configPath != "" {
|
||||||
config, err := readConfiguration(configPath)
|
config, err := readConfiguration(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("error", err).Warn("Configuration file malformed.")
|
logrus.WithField("error", err).Warn("Configuration file malformed.")
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
core, err := core.NewCore(config.AutoscalersConf)
|
logrus.Infof("Starting from configuration file located %s", configPath)
|
||||||
|
coreEngine, err = core.NewCoreByConfig(config.AutoscalersConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("error", err).Warn(err)
|
logrus.WithField("error", err).Warn(err)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logrus.Info("Starting in auto-detection mode.")
|
||||||
|
coreEngine, err = core.Autodetect()
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
sigchan := make(chan os.Signal, 10)
|
sigchan := make(chan os.Signal, 10)
|
||||||
signal.Notify(sigchan, os.Interrupt)
|
signal.Notify(sigchan, os.Interrupt)
|
||||||
@ -52,7 +59,7 @@ func (c *DaemonCmd) Run(args []string) int {
|
|||||||
logrus.Info("Stopping and cleaning. Bye!")
|
logrus.Info("Stopping and cleaning. Bye!")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
router := api.GetRouter(core, c.EventChannel)
|
router := api.GetRouter(coreEngine, c.EventChannel)
|
||||||
logrus.Infof("API Server run on port %s", port)
|
logrus.Infof("API Server run on port %s", port)
|
||||||
http.ListenAndServe(port, router)
|
http.ListenAndServe(port, router)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
21
core/autodetect.go
Normal file
21
core/autodetect.go
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import "github.com/gianarb/orbiter/autoscaler"
|
||||||
|
|
||||||
|
// This function use diferent strategies to get information from
|
||||||
|
// the system itself to configure the autoloader.
|
||||||
|
// They can be environment variables for example or other systems.
|
||||||
|
func Autodetect() (Core error) {
|
||||||
|
scalers := autoscaler.Autoscalers{}
|
||||||
|
var core Core
|
||||||
|
autoDetectSwarmMode(&scalers)
|
||||||
|
return core, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func autoDetectSwarmMode(a *autoscaler.Autoscalers) {
|
||||||
|
// Create Docker Client by EnvVar and check if it's working.
|
||||||
|
|
||||||
|
// Get List of Services
|
||||||
|
|
||||||
|
// Check which services has labels and register them to orbiter.
|
||||||
|
}
|
||||||
@ -11,7 +11,7 @@ type Core struct {
|
|||||||
Autoscalers autoscaler.Autoscalers
|
Autoscalers autoscaler.Autoscalers
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCore(c map[string]AutoscalerConf) (Core, error) {
|
func NewCoreByConfig(c map[string]AutoscalerConf) (Core, error) {
|
||||||
scalers := autoscaler.Autoscalers{}
|
scalers := autoscaler.Autoscalers{}
|
||||||
var core Core
|
var core Core
|
||||||
for scalerName, scaler := range c {
|
for scalerName, scaler := range c {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ func TestNewCore(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
core, err := NewCore(conf)
|
core, err := NewCoreByConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ func TestGetSingleAutoscaler(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
core, _ := NewCore(conf)
|
core, _ := NewCoreByConfig(conf)
|
||||||
_, ok := core.Autoscalers["second/micro"]
|
_, ok := core.Autoscalers["second/micro"]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
t.Fatal("micro exist")
|
t.Fatal("micro exist")
|
||||||
@ -89,7 +89,7 @@ func TestNewCoreWithUnsupportedProvider(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := NewCore(conf)
|
_, err := NewCoreByConfig(conf)
|
||||||
if err.Error() != "lalala not supported." {
|
if err.Error() != "lalala not supported." {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user