Browse Source

add __meta_kubernetes_service_port_number (#10945)

Signed-off-by: yngwiewang <yngwiewang@163.com>
pull/11002/head
yngwiewang 2 years ago
parent
commit
1abbf5a5c5
  1. 2
      discovery/kubernetes/service.go
  2. 9
      discovery/kubernetes/service_test.go

2
discovery/kubernetes/service.go

@ -150,6 +150,7 @@ const (
serviceAnnotationPrefix = metaLabelPrefix + "service_annotation_"
serviceAnnotationPresentPrefix = metaLabelPrefix + "service_annotationpresent_"
servicePortNameLabel = metaLabelPrefix + "service_port_name"
servicePortNumberLabel = metaLabelPrefix + "service_port_number"
servicePortProtocolLabel = metaLabelPrefix + "service_port_protocol"
serviceClusterIPLabel = metaLabelPrefix + "service_cluster_ip"
serviceExternalNameLabel = metaLabelPrefix + "service_external_name"
@ -189,6 +190,7 @@ func (s *Service) buildService(svc *apiv1.Service) *targetgroup.Group {
labelSet := model.LabelSet{
model.AddressLabel: lv(addr),
servicePortNameLabel: lv(port.Name),
servicePortNumberLabel: lv(strconv.FormatInt(int64(port.Port), 10)),
servicePortProtocolLabel: lv(string(port.Protocol)),
serviceType: lv(string(svc.Spec.Type)),
}

9
discovery/kubernetes/service_test.go

@ -117,6 +117,7 @@ func TestServiceDiscoveryAdd(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{
@ -132,6 +133,7 @@ func TestServiceDiscoveryAdd(t *testing.T) {
"__address__": "testservice-external.default.svc:31900",
"__meta_kubernetes_service_type": "ExternalName",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "31900",
"__meta_kubernetes_service_external_name": "FooExternalName",
},
},
@ -182,6 +184,7 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport0",
"__meta_kubernetes_service_port_number": "30900",
},
{
"__meta_kubernetes_service_port_protocol": "UDP",
@ -189,6 +192,7 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport1",
"__meta_kubernetes_service_port_number": "30901",
},
},
Labels: model.LabelSet{
@ -227,6 +231,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{
@ -243,6 +248,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{
@ -277,6 +283,7 @@ func TestServiceDiscoveryOwnNamespace(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{
@ -311,6 +318,7 @@ func TestServiceDiscoveryAllNamespaces(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{
@ -327,6 +335,7 @@ func TestServiceDiscoveryAllNamespaces(t *testing.T) {
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_port_number": "30900",
},
},
Labels: model.LabelSet{

Loading…
Cancel
Save