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{} labels := map[string]string{}
// prepend the podLabelPrefix to the labels' keys // prepend the podLabelPrefix to the labels' keys
for k, v := range podConfig.Labels { for k, v := range podConfig.Labels {
labels[podLabelPrefix+k] = v labels[labelPrefix+k] = v
} }
labels[agolaLabelKey] = agolaLabelValue labels[agolaLabelKey] = agolaLabelValue
labels[podIDKey] = podConfig.ID labels[podIDKey] = podConfig.ID
@ -211,7 +211,7 @@ func (d *DockerDriver) GetPodsByLabels(ctx context.Context, labels map[string]st
args := filters.NewArgs() args := filters.NewArgs()
// search label adding the podLabelPrefix // search label adding the podLabelPrefix
for k, v := range labels { 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, containers, err := d.client.ContainerList(ctx,
@ -269,8 +269,8 @@ func (d *DockerDriver) GetPodsByLabels(ctx context.Context, labels map[string]st
if cIndex == 0 { if cIndex == 0 {
podLabels := map[string]string{} podLabels := map[string]string{}
for labelName, labelValue := range container.Labels { for labelName, labelValue := range container.Labels {
if strings.HasPrefix(labelName, podLabelPrefix) { if strings.HasPrefix(labelName, labelPrefix) {
podLabels[strings.TrimPrefix(labelName, podLabelPrefix)] = labelValue podLabels[strings.TrimPrefix(labelName, labelPrefix)] = labelValue
} }
} }
pod.labels = podLabels 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 { func podLabelsFromContainer(containerLabels map[string]string) map[string]string {
labels := map[string]string{} labels := map[string]string{}
for k, v := range containerLabels { for k, v := range containerLabels {
if strings.HasPrefix(k, podLabelPrefix) { if strings.HasPrefix(k, labelPrefix) {
labels[strings.TrimPrefix(k, podLabelPrefix)] = v labels[strings.TrimPrefix(k, labelPrefix)] = v
} }
} }
return labels return labels

View File

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