Segments Labels: Mesos
This commit is contained in:
parent
a5beeb4f04
commit
599b699ac9
6 changed files with 883 additions and 70 deletions
|
@ -1,8 +1,10 @@
|
|||
package mesos
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/provider/label"
|
||||
"github.com/mesosphere/mesos-dns/records/state"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
@ -48,12 +50,29 @@ func TestBuilder(t *testing.T) {
|
|||
assert.Equal(t, expected, result)
|
||||
}
|
||||
|
||||
func aTaskData(id string, ops ...func(*state.Task)) taskData {
|
||||
func aTaskData(id, segment string, ops ...func(*state.Task)) taskData {
|
||||
ts := &state.Task{ID: id}
|
||||
for _, op := range ops {
|
||||
op(ts)
|
||||
}
|
||||
return taskData{Task: *ts, TraefikLabels: extractLabels(*ts)}
|
||||
lbls := label.ExtractTraefikLabels(extractLabels(*ts))
|
||||
if len(lbls[segment]) > 0 {
|
||||
return taskData{Task: *ts, TraefikLabels: lbls[segment], SegmentName: segment}
|
||||
}
|
||||
return taskData{Task: *ts, TraefikLabels: lbls[""], SegmentName: segment}
|
||||
}
|
||||
|
||||
func segmentedTaskData(segments []string, ts state.Task) []taskData {
|
||||
td := []taskData{}
|
||||
lbls := label.ExtractTraefikLabels(extractLabels(ts))
|
||||
for _, s := range segments {
|
||||
if l, ok := lbls[s]; !ok {
|
||||
td = append(td, taskData{Task: ts, TraefikLabels: lbls[""], SegmentName: s})
|
||||
} else {
|
||||
td = append(td, taskData{Task: ts, TraefikLabels: l, SegmentName: s})
|
||||
}
|
||||
}
|
||||
return td
|
||||
}
|
||||
|
||||
func aTask(id string, ops ...func(*state.Task)) state.Task {
|
||||
|
@ -148,6 +167,18 @@ func withLabel(key, value string) func(*state.Task) {
|
|||
}
|
||||
}
|
||||
|
||||
func withSegmentLabel(key, value, segmentName string) func(*state.Task) {
|
||||
if len(segmentName) == 0 {
|
||||
panic("segmentName can not be empty")
|
||||
}
|
||||
|
||||
property := strings.TrimPrefix(key, label.Prefix)
|
||||
return func(task *state.Task) {
|
||||
lbl := state.Label{Key: label.Prefix + segmentName + "." + property, Value: value}
|
||||
task.Labels = append(task.Labels, lbl)
|
||||
}
|
||||
}
|
||||
|
||||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue