-
Notifications
You must be signed in to change notification settings - Fork 20
/
labels.go
40 lines (31 loc) · 965 Bytes
/
labels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package mapping
import (
"fmt"
"github.com/ernoaapa/eliot/pkg/model"
)
var (
labelPrefix = "io.eliot"
podNameLabel = "pod.name"
containerNameLabel = "container.name"
)
// ContainerLabels is helper type for managing container labels
type ContainerLabels map[string]string
func (l ContainerLabels) getPodName() string {
return l.getValue(podNameLabel)
}
func (l ContainerLabels) getContainerName() string {
return l.getValue(containerNameLabel)
}
func (l ContainerLabels) getValue(key string) string {
return l[buildLabelKeyFor(key)]
}
func buildLabelKeyFor(name string) string {
return fmt.Sprintf("%s.%s", labelPrefix, name)
}
// NewLabels constructs new labels map for new container
func NewLabels(pod model.Pod, container model.Container) ContainerLabels {
labels := make(map[string]string)
labels[buildLabelKeyFor(podNameLabel)] = pod.Metadata.Name
labels[buildLabelKeyFor(containerNameLabel)] = container.Name
return labels
}