mirror of
https://github.com/spaytac/orbiter.git
synced 2026-01-21 23:04:45 +00:00
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.
31 lines
684 B
Go
31 lines
684 B
Go
package core
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gianarb/orbiter/autoscaler"
|
|
"github.com/gianarb/orbiter/provider"
|
|
)
|
|
|
|
type Core struct {
|
|
Autoscalers autoscaler.Autoscalers
|
|
}
|
|
|
|
func NewCoreByConfig(c map[string]AutoscalerConf) (Core, error) {
|
|
scalers := autoscaler.Autoscalers{}
|
|
var core Core
|
|
for scalerName, scaler := range c {
|
|
p, err := provider.NewProvider(scaler.Provider, scaler.Parameters)
|
|
if err != nil {
|
|
return core, err
|
|
}
|
|
for serviceName, policy := range scaler.Policies {
|
|
scalers[fmt.Sprintf("%s/%s", scalerName, serviceName)] = autoscaler.NewAutoscaler(p, serviceName, policy.Up, policy.Down)
|
|
}
|
|
}
|
|
core = Core{
|
|
Autoscalers: scalers,
|
|
}
|
|
return core, nil
|
|
}
|