runservice executor: rename pod labels

* Use a command namespaced prefix
* Add executor id label for future usage
This commit is contained in:
Simone Gotti 2019-04-22 18:19:43 +02:00
parent abf908bcad
commit 4da4f48f98
2 changed files with 13 additions and 11 deletions

View File

@ -151,7 +151,7 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
labels := map[string]string{}
// prepend the podLabelPrefix to the labels' keys
for k, v := range podConfig.Labels {
labels[podLabelPrefix+k] = v
labels[labelPrefix+k] = v
}
labels[agolaLabelKey] = agolaLabelValue
labels[podIDKey] = podConfig.ID
@ -211,7 +211,7 @@ func (d *DockerDriver) GetPodsByLabels(ctx context.Context, labels map[string]st
args := filters.NewArgs()
// search label adding the podLabelPrefix
for k, v := range labels {
args.Add("label", fmt.Sprintf("%s%s=%s", podLabelPrefix, k, v))
args.Add("label", fmt.Sprintf("%s%s=%s", labelPrefix, k, v))
}
containers, err := d.client.ContainerList(ctx,
@ -269,8 +269,8 @@ func (d *DockerDriver) GetPodsByLabels(ctx context.Context, labels map[string]st
if cIndex == 0 {
podLabels := map[string]string{}
for labelName, labelValue := range container.Labels {
if strings.HasPrefix(labelName, podLabelPrefix) {
podLabels[strings.TrimPrefix(labelName, podLabelPrefix)] = labelValue
if strings.HasPrefix(labelName, labelPrefix) {
podLabels[strings.TrimPrefix(labelName, labelPrefix)] = labelValue
}
}
pod.labels = podLabels
@ -287,8 +287,8 @@ func (d *DockerDriver) GetPodsByLabels(ctx context.Context, labels map[string]st
func podLabelsFromContainer(containerLabels map[string]string) map[string]string {
labels := map[string]string{}
for k, v := range containerLabels {
if strings.HasPrefix(k, podLabelPrefix) {
labels[strings.TrimPrefix(k, podLabelPrefix)] = v
if strings.HasPrefix(k, labelPrefix) {
labels[strings.TrimPrefix(k, labelPrefix)] = v
}
}
return labels

View File

@ -22,14 +22,16 @@ import (
)
const (
agolaLabelKey = "agola"
labelPrefix = "agola.io/"
agolaLabelKey = labelPrefix + "agola"
agolaLabelValue = "true"
podIDKey = "podID"
containerIndexKey = "index"
taskKey = "task"
executorIDKey = labelPrefix + "executorid"
podIDKey = labelPrefix + "podid"
taskIDKey = labelPrefix + "taskid"
podLabelPrefix = "podlabel_"
containerIndexKey = labelPrefix + "containerindex"
)
// Driver is a generic interface around the pod concept (a group of "containers"