Merge pull request #3495 from tomwilkie/pod-uid-discovery-master

Include Pod UID in the discovery metadata.
This commit is contained in:
Tom Wilkie 2017-11-24 15:37:57 +00:00 committed by GitHub
commit 9d4e332137
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/cache"
)
@ -126,6 +127,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
Namespace: "default",
UID: types.UID("deadbeef"),
},
Spec: v1.PodSpec{
NodeName: "testnode",
@ -210,6 +212,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
"__meta_kubernetes_pod_container_port_name": "mainport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
"__meta_kubernetes_pod_uid": "deadbeef",
},
{
"__address__": "1.2.3.4:9001",
@ -222,6 +225,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
"__meta_kubernetes_pod_container_port_name": "sideport",
"__meta_kubernetes_pod_container_port_number": "9001",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
"__meta_kubernetes_pod_uid": "deadbeef",
},
},
Labels: model.LabelSet{

View File

@ -140,6 +140,7 @@ const (
podAnnotationPrefix = metaLabelPrefix + "pod_annotation_"
podNodeNameLabel = metaLabelPrefix + "pod_node_name"
podHostIPLabel = metaLabelPrefix + "pod_host_ip"
podUID = metaLabelPrefix + "pod_uid"
)
func podLabels(pod *apiv1.Pod) model.LabelSet {
@ -149,6 +150,7 @@ func podLabels(pod *apiv1.Pod) model.LabelSet {
podReadyLabel: podReady(pod),
podNodeNameLabel: lv(pod.Spec.NodeName),
podHostIPLabel: lv(pod.Status.HostIP),
podUID: lv(string(pod.ObjectMeta.UID)),
}
for k, v := range pod.Labels {

View File

@ -19,6 +19,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/tools/cache"
)
@ -43,6 +44,7 @@ func makeMultiPortPod() *v1.Pod {
Namespace: "default",
Labels: map[string]string{"testlabel": "testvalue"},
Annotations: map[string]string{"testannotation": "testannotationvalue"},
UID: types.UID("abc123"),
},
Spec: v1.PodSpec{
NodeName: "testnode",
@ -85,6 +87,7 @@ func makePod() *v1.Pod {
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
Namespace: "default",
UID: types.UID("abc123"),
},
Spec: v1.PodSpec{
NodeName: "testnode",
@ -151,6 +154,7 @@ func TestPodDiscoveryInitial(t *testing.T) {
"__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",
},
@ -182,6 +186,7 @@ func TestPodDiscoveryAdd(t *testing.T) {
"__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",
},
@ -214,6 +219,7 @@ func TestPodDiscoveryDelete(t *testing.T) {
"__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",
},
@ -251,6 +257,7 @@ func TestPodDiscoveryDeleteUnknownCacheState(t *testing.T) {
"__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",
},
@ -269,6 +276,7 @@ func TestPodDiscoveryUpdate(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
Namespace: "default",
UID: "xyz321",
},
Spec: v1.PodSpec{
NodeName: "testnode",
@ -312,6 +320,7 @@ func TestPodDiscoveryUpdate(t *testing.T) {
"__meta_kubernetes_pod_ip": "1.2.3.4",
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
"__meta_kubernetes_pod_ready": "unknown",
"__meta_kubernetes_pod_uid": "xyz321",
},
Source: "pod/default/testpod",
},
@ -334,6 +343,7 @@ func TestPodDiscoveryUpdate(t *testing.T) {
"__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",
},

View File

@ -643,6 +643,7 @@ Available meta labels:
* `__meta_kubernetes_pod_ready`: Set to `true` or `false` for the pod's ready state.
* `__meta_kubernetes_pod_node_name`: The name of the node the pod is scheduled onto.
* `__meta_kubernetes_pod_host_ip`: The current host IP of the pod object.
* `__meta_kubernetes_pod_uid`: The UID of the pod object.
#### `endpoints`