From 4da4f48f9881da0219f83969ec3702ce7ab10e20 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Mon, 22 Apr 2019 18:19:43 +0200 Subject: [PATCH] runservice executor: rename pod labels * Use a command namespaced prefix * Add executor id label for future usage --- .../services/runservice/executor/driver/docker.go | 12 ++++++------ .../services/runservice/executor/driver/driver.go | 12 +++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/services/runservice/executor/driver/docker.go b/internal/services/runservice/executor/driver/docker.go index bf382c3..9797646 100644 --- a/internal/services/runservice/executor/driver/docker.go +++ b/internal/services/runservice/executor/driver/docker.go @@ -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 diff --git a/internal/services/runservice/executor/driver/driver.go b/internal/services/runservice/executor/driver/driver.go index 9550e05..a74326c 100644 --- a/internal/services/runservice/executor/driver/driver.go +++ b/internal/services/runservice/executor/driver/driver.go @@ -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"