discovery/kubernetes: fix missing label sanitization (#5462)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2019-04-15 20:04:50 +02:00 committed by Brian Brazil
parent 8dfd829fef
commit 559237cc4f
6 changed files with 50 additions and 50 deletions

View File

@ -357,7 +357,7 @@ func TestEndpointsDiscoveryWithService(t *testing.T) {
Name: "testendpoints",
Namespace: "default",
Labels: map[string]string{
"app": "test",
"app/name": "test",
},
},
}
@ -387,11 +387,11 @@ func TestEndpointsDiscoveryWithService(t *testing.T) {
},
},
Labels: model.LabelSet{
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_endpoints_name": "testendpoints",
"__meta_kubernetes_service_label_app": "test",
"__meta_kubernetes_service_labelpresent_app": "true",
"__meta_kubernetes_service_name": "testendpoints",
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_endpoints_name": "testendpoints",
"__meta_kubernetes_service_label_app_name": "test",
"__meta_kubernetes_service_labelpresent_app_name": "true",
"__meta_kubernetes_service_name": "testendpoints",
},
Source: "endpoints/default/testendpoints",
},
@ -410,7 +410,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
Name: "testendpoints",
Namespace: "default",
Labels: map[string]string{
"app": "test",
"app/name": "test",
},
},
}
@ -422,7 +422,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
Name: "testendpoints",
Namespace: "default",
Labels: map[string]string{
"app": "svc",
"app/name": "svc",
"component": "testing",
},
},
@ -455,8 +455,8 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
Labels: model.LabelSet{
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_endpoints_name": "testendpoints",
"__meta_kubernetes_service_label_app": "svc",
"__meta_kubernetes_service_labelpresent_app": "true",
"__meta_kubernetes_service_label_app_name": "svc",
"__meta_kubernetes_service_labelpresent_app_name": "true",
"__meta_kubernetes_service_name": "testendpoints",
"__meta_kubernetes_service_label_component": "testing",
"__meta_kubernetes_service_labelpresent_component": "true",

View File

@ -36,8 +36,8 @@ func makeIngress(tls TLSMode) *v1beta1.Ingress {
ObjectMeta: metav1.ObjectMeta{
Name: "testingress",
Namespace: "default",
Labels: map[string]string{"testlabel": "testvalue"},
Annotations: map[string]string{"testannotation": "testannotationvalue"},
Labels: map[string]string{"test/label": "testvalue"},
Annotations: map[string]string{"test/annotation": "testannotationvalue"},
},
Spec: v1beta1.IngressSpec{
TLS: nil,
@ -118,12 +118,12 @@ func expectedTargetGroups(ns string, tls TLSMode) map[string]*targetgroup.Group
},
},
Labels: model.LabelSet{
"__meta_kubernetes_ingress_name": "testingress",
"__meta_kubernetes_namespace": lv(ns),
"__meta_kubernetes_ingress_label_testlabel": "testvalue",
"__meta_kubernetes_ingress_labelpresent_testlabel": "true",
"__meta_kubernetes_ingress_annotation_testannotation": "testannotationvalue",
"__meta_kubernetes_ingress_annotationpresent_testannotation": "true",
"__meta_kubernetes_ingress_name": "testingress",
"__meta_kubernetes_namespace": lv(ns),
"__meta_kubernetes_ingress_label_test_label": "testvalue",
"__meta_kubernetes_ingress_labelpresent_test_label": "true",
"__meta_kubernetes_ingress_annotation_test_annotation": "testannotationvalue",
"__meta_kubernetes_ingress_annotationpresent_test_annotation": "true",
},
Source: key,
},

View File

@ -59,8 +59,8 @@ func TestNodeDiscoveryBeforeStart(t *testing.T) {
obj := makeNode(
"test",
"1.2.3.4",
map[string]string{"testlabel": "testvalue"},
map[string]string{"testannotation": "testannotationvalue"},
map[string]string{"test-label": "testvalue"},
map[string]string{"test-annotation": "testannotationvalue"},
)
c.CoreV1().Nodes().Create(obj)
},
@ -75,11 +75,11 @@ func TestNodeDiscoveryBeforeStart(t *testing.T) {
},
},
Labels: model.LabelSet{
"__meta_kubernetes_node_name": "test",
"__meta_kubernetes_node_label_testlabel": "testvalue",
"__meta_kubernetes_node_labelpresent_testlabel": "true",
"__meta_kubernetes_node_annotation_testannotation": "testannotationvalue",
"__meta_kubernetes_node_annotationpresent_testannotation": "true",
"__meta_kubernetes_node_name": "test",
"__meta_kubernetes_node_label_test_label": "testvalue",
"__meta_kubernetes_node_labelpresent_test_label": "true",
"__meta_kubernetes_node_annotation_test_annotation": "testannotationvalue",
"__meta_kubernetes_node_annotationpresent_test_annotation": "true",
},
Source: "node/test",
},

View File

@ -188,7 +188,7 @@ func podLabels(pod *apiv1.Pod) model.LabelSet {
for k, v := range pod.Labels {
ln := strutil.SanitizeLabelName(k)
ls[model.LabelName(podLabelPrefix+k)] = lv(v)
ls[model.LabelName(podLabelPrefix+ln)] = lv(v)
ls[model.LabelName(podLabelPresentPrefix+ln)] = presentValue
}

View File

@ -33,8 +33,8 @@ func makeMultiPortPods() *v1.Pod {
ObjectMeta: metav1.ObjectMeta{
Name: "testpod",
Namespace: "default",
Labels: map[string]string{"testlabel": "testvalue"},
Annotations: map[string]string{"testannotation": "testannotationvalue"},
Labels: map[string]string{"test/label": "testvalue"},
Annotations: map[string]string{"test/annotation": "testannotationvalue"},
UID: types.UID("abc123"),
OwnerReferences: []metav1.OwnerReference{
{
@ -178,20 +178,20 @@ func TestPodDiscoveryBeforeRun(t *testing.T) {
},
},
Labels: model.LabelSet{
"__meta_kubernetes_pod_name": "testpod",
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_pod_label_testlabel": "testvalue",
"__meta_kubernetes_pod_labelpresent_testlabel": "true",
"__meta_kubernetes_pod_annotation_testannotation": "testannotationvalue",
"__meta_kubernetes_pod_annotationpresent_testannotation": "true",
"__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_phase": "Running",
"__meta_kubernetes_pod_uid": "abc123",
"__meta_kubernetes_pod_controller_kind": "testcontrollerkind",
"__meta_kubernetes_pod_controller_name": "testcontrollername",
"__meta_kubernetes_pod_name": "testpod",
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_pod_label_test_label": "testvalue",
"__meta_kubernetes_pod_labelpresent_test_label": "true",
"__meta_kubernetes_pod_annotation_test_annotation": "testannotationvalue",
"__meta_kubernetes_pod_annotationpresent_test_annotation": "true",
"__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_phase": "Running",
"__meta_kubernetes_pod_uid": "abc123",
"__meta_kubernetes_pod_controller_kind": "testcontrollerkind",
"__meta_kubernetes_pod_controller_name": "testcontrollername",
},
Source: "pod/default/testpod",
},

View File

@ -28,8 +28,8 @@ func makeMultiPortService() *v1.Service {
ObjectMeta: metav1.ObjectMeta{
Name: "testservice",
Namespace: "default",
Labels: map[string]string{"testlabel": "testvalue"},
Annotations: map[string]string{"testannotation": "testannotationvalue"},
Labels: map[string]string{"test-label": "testvalue"},
Annotations: map[string]string{"test-annotation": "testannotationvalue"},
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
@ -186,12 +186,12 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
},
},
Labels: model.LabelSet{
"__meta_kubernetes_service_name": "testservice",
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_service_label_testlabel": "testvalue",
"__meta_kubernetes_service_labelpresent_testlabel": "true",
"__meta_kubernetes_service_annotation_testannotation": "testannotationvalue",
"__meta_kubernetes_service_annotationpresent_testannotation": "true",
"__meta_kubernetes_service_name": "testservice",
"__meta_kubernetes_namespace": "default",
"__meta_kubernetes_service_label_test_label": "testvalue",
"__meta_kubernetes_service_labelpresent_test_label": "true",
"__meta_kubernetes_service_annotation_test_annotation": "testannotationvalue",
"__meta_kubernetes_service_annotationpresent_test_annotation": "true",
},
Source: "svc/default/testservice",
},