Merge pull request #3842 from simonpasquier/delete-evicted-pods
Send update when pod's IP address is empty
This commit is contained in:
commit
2124a436ff
|
@ -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 New Issue