Use containers labels instead of task labels from Docker Swarm SD (#9187) (#10311)

* Remove task labels from Docker Swarm SD (#9187)

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>

Add container labels to Docker Swarm SD (#9187)

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>

* Reorder labels in configuration doc

Signed-off-by: Ujjwal Goyal <importujjwal@gmail.com>
This commit is contained in:
Ujjwal Goyal 2022-03-08 19:19:20 +05:30 committed by GitHub
parent 097b359b41
commit 9e7ae4d963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 719 additions and 690 deletions

View File

@ -28,14 +28,14 @@ import (
)
const (
swarmLabelTaskPrefix = swarmLabel + "task_"
swarmLabelTaskID = swarmLabelTaskPrefix + "id"
swarmLabelTaskLabelPrefix = swarmLabelTaskPrefix + "label_"
swarmLabelTaskDesiredState = swarmLabelTaskPrefix + "desired_state"
swarmLabelTaskStatus = swarmLabelTaskPrefix + "state"
swarmLabelTaskContainerID = swarmLabelTaskPrefix + "container_id"
swarmLabelTaskSlot = swarmLabelTaskPrefix + "slot"
swarmLabelTaskPortMode = swarmLabelTaskPrefix + "port_publish_mode"
swarmLabelTaskPrefix = swarmLabel + "task_"
swarmLabelTaskID = swarmLabelTaskPrefix + "id"
swarmLabelTaskDesiredState = swarmLabelTaskPrefix + "desired_state"
swarmLabelTaskStatus = swarmLabelTaskPrefix + "state"
swarmLabelTaskContainerID = swarmLabelTaskPrefix + "container_id"
swarmLabelTaskSlot = swarmLabelTaskPrefix + "slot"
swarmLabelTaskPortMode = swarmLabelTaskPrefix + "port_publish_mode"
swarmLabelContainerLabelPrefix = swarmLabel + "container_label_"
)
func (d *Discovery) refreshTasks(ctx context.Context) ([]*targetgroup.Group, error) {
@ -75,9 +75,11 @@ func (d *Discovery) refreshTasks(ctx context.Context) ([]*targetgroup.Group, err
commonLabels[swarmLabelTaskContainerID] = s.Status.ContainerStatus.ContainerID
}
for k, v := range s.Labels {
ln := strutil.SanitizeLabelName(k)
commonLabels[swarmLabelTaskLabelPrefix+ln] = v
if s.Spec.ContainerSpec != nil {
for k, v := range s.Spec.ContainerSpec.Labels {
ln := strutil.SanitizeLabelName(k)
commonLabels[swarmLabelContainerLabelPrefix+ln] = v
}
}
for k, v := range serviceLabels[s.ServiceID] {

File diff suppressed because it is too large Load Diff

View File

@ -792,10 +792,10 @@ created using the `port` parameter defined in the SD configuration.
Available meta labels:
* `__meta_dockerswarm_container_label_<labelname>`: each label of the container
* `__meta_dockerswarm_task_id`: the id of the task
* `__meta_dockerswarm_task_container_id`: the container id of the task
* `__meta_dockerswarm_task_desired_state`: the desired state of the task
* `__meta_dockerswarm_task_label_<labelname>`: each label of the task
* `__meta_dockerswarm_task_slot`: the slot of the task
* `__meta_dockerswarm_task_state`: the state of the task
* `__meta_dockerswarm_task_port_publish_mode`: the publish mode of the task port