Bugfix autodetection labels

This commit is contained in:
Gianluca Arbezzano 2017-03-26 23:07:02 +01:00
parent 3cea6bb8ba
commit b6f6cb3784
2 changed files with 25 additions and 2 deletions

View File

@ -52,7 +52,6 @@ func autoDetectSwarmMode(c *Core) {
if err != nil { if err != nil {
continue continue
} }
logrus.Debugf("autodetect_swarm/%s added to orbiter.", service.Spec.Annotations.Name)
c.Autoscalers[fmt.Sprintf("autodetect_swarm/%s", service.Spec.Annotations.Name)] = s c.Autoscalers[fmt.Sprintf("autodetect_swarm/%s", service.Spec.Annotations.Name)] = s
} }
} }
@ -65,12 +64,13 @@ func getAutoscalerByService(p autoscaler.Provider, an swarm.Annotations) (autosc
up := convertStringLabelToInt("orbiter.up", an.Labels) up := convertStringLabelToInt("orbiter.up", an.Labels)
down := convertStringLabelToInt("orbiter.down", an.Labels) down := convertStringLabelToInt("orbiter.down", an.Labels)
as := autoscaler.NewAutoscaler(p, an.Name, up, down) as := autoscaler.NewAutoscaler(p, an.Name, up, down)
logrus.Debugf("autodetect_swarm/%s added to orbiter. UP %d, DOWN %d", an.Name, up, down)
return as, nil return as, nil
} }
func convertStringLabelToInt(labelName string, labels map[string]string) int { func convertStringLabelToInt(labelName string, labels map[string]string) int {
row, e := labels[labelName] row, e := labels[labelName]
if e == false { if e == true {
i, err := strconv.ParseInt(row, 10, 64) i, err := strconv.ParseInt(row, 10, 64)
if err != nil { if err != nil {
return 1 return 1

23
core/autodetect_test.go Normal file
View File

@ -0,0 +1,23 @@
package core
import "testing"
func TestGetRightOrbiterUp(t *testing.T) {
r := convertStringLabelToInt("orbiter.up", map[string]string{
"orbiter.up": "3",
"orbiter.down": "3",
})
if r != 3 {
t.Fatalf("%d != 3", r)
}
}
func TestGetRightOrbiterDown(t *testing.T) {
r := convertStringLabelToInt("orbiter.down", map[string]string{
"orbiter.up": "3",
"orbiter.down": "2",
})
if r != 2 {
t.Fatalf("%d != 2", r)
}
}