mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-28 14:12:10 -08:00
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>
This commit is contained in:
parent
bea07fe866
commit
cfa253ae06
|
@ -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…
Reference in a new issue