Browse Source

feat(discovery/kubernetes): container_is_init label

Adds a label that shows whether the container is an init container or not

Signed-off-by: sh0rez <me@shorez.de>
pull/5598/head
sh0rez 6 years ago
parent
commit
cfa253ae06
No known key found for this signature in database
GPG Key ID: 87C71DF9F8181FF1
  1. 7
      discovery/kubernetes/pod.go

7
discovery/kubernetes/pod.go

@ -141,6 +141,7 @@ const (
podContainerPortNameLabel = metaLabelPrefix + "pod_container_port_name"
podContainerPortNumberLabel = metaLabelPrefix + "pod_container_port_number"
podContainerPortProtocolLabel = metaLabelPrefix + "pod_container_port_protocol"
podContainerIsInit = metaLabelPrefix + "pod_container_is_init"
podReadyLabel = metaLabelPrefix + "pod_ready"
podPhaseLabel = metaLabelPrefix + "pod_phase"
podLabelPrefix = metaLabelPrefix + "pod_label_"
@ -214,7 +215,9 @@ func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
tg.Labels[namespaceLabel] = lv(pod.Namespace)
containers := append(pod.Spec.Containers, pod.Spec.InitContainers...)
for _, c := range containers {
for i, c := range containers {
is_init := i >= len(pod.Spec.Containers)
// If no ports are defined for the container, create an anonymous
// target per container.
if len(c.Ports) == 0 {
@ -223,6 +226,7 @@ func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: lv(pod.Status.PodIP),
podContainerNameLabel: lv(c.Name),
podContainerIsInit: lv(strconv.FormatBool(is_init)),
})
continue
}
@ -237,6 +241,7 @@ func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
podContainerPortNumberLabel: lv(ports),
podContainerPortNameLabel: lv(port.Name),
podContainerPortProtocolLabel: lv(string(port.Protocol)),
podContainerIsInit: lv(strconv.FormatBool(is_init)),
})
}
}

Loading…
Cancel
Save