mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Send update when pod's IP address is empty
When the pod gets evicted, its IP address becomes empty and it needs to be removed from the targets.
This commit is contained in:
parent
d127a21071
commit
2072bbc824
|
@ -170,14 +170,14 @@ func podLabels(pod *apiv1.Pod) model.LabelSet {
|
|||
}
|
||||
|
||||
func (p *Pod) buildPod(pod *apiv1.Pod) *targetgroup.Group {
|
||||
// During startup the pod may not have an IP yet. This does not even allow
|
||||
// for an up metric, so we skip the target.
|
||||
if len(pod.Status.PodIP) == 0 {
|
||||
return nil
|
||||
}
|
||||
tg := &targetgroup.Group{
|
||||
Source: podSource(pod),
|
||||
}
|
||||
// PodIP can be empty when a pod is starting or has been evicted.
|
||||
if len(pod.Status.PodIP) == 0 {
|
||||
return tg
|
||||
}
|
||||
|
||||
tg.Labels = podLabels(pod)
|
||||
tg.Labels[namespaceLabel] = lv(pod.Namespace)
|
||||
|
||||
|
|
|
@ -350,3 +350,46 @@ func TestPodDiscoveryUpdate(t *testing.T) {
|
|||
},
|
||||
}.Run(t)
|
||||
}
|
||||
|
||||
func TestPodDiscoveryUpdateEmptyPodIP(t *testing.T) {
|
||||
n, i := makeTestPodDiscovery()
|
||||
initialPod := makePod()
|
||||
|
||||
updatedPod := makePod()
|
||||
updatedPod.Status.PodIP = ""
|
||||
|
||||
i.GetStore().Add(initialPod)
|
||||
|
||||
k8sDiscoveryTest{
|
||||
discovery: n,
|
||||
afterStart: func() { go func() { i.Update(updatedPod) }() },
|
||||
expectedInitial: []*targetgroup.Group{
|
||||
{
|
||||
Targets: []model.LabelSet{
|
||||
{
|
||||
"__address__": "1.2.3.4:9000",
|
||||
"__meta_kubernetes_pod_container_name": "testcontainer",
|
||||
"__meta_kubernetes_pod_container_port_name": "testport",
|
||||
"__meta_kubernetes_pod_container_port_number": "9000",
|
||||
"__meta_kubernetes_pod_container_port_protocol": "TCP",
|
||||
},
|
||||
},
|
||||
Labels: model.LabelSet{
|
||||
"__meta_kubernetes_pod_name": "testpod",
|
||||
"__meta_kubernetes_namespace": "default",
|
||||
"__meta_kubernetes_pod_node_name": "testnode",
|
||||
"__meta_kubernetes_pod_ip": "1.2.3.4",
|
||||
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
|
||||
"__meta_kubernetes_pod_ready": "true",
|
||||
"__meta_kubernetes_pod_uid": "abc123",
|
||||
},
|
||||
Source: "pod/default/testpod",
|
||||
},
|
||||
},
|
||||
expectedRes: []*targetgroup.Group{
|
||||
{
|
||||
Source: "pod/default/testpod",
|
||||
},
|
||||
},
|
||||
}.Run(t)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue