add service type metadata to kubernetes_sd_config service role #6496 (#6684)

* [service discovery] add service type metadata to kubernetes_sd_config service role

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>

* [fix] ServiceType -> string

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>

* [fix] fix testcase

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>

* [style]

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>

* [doc] add service type

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>

* [doc] sort

Signed-off-by: fuling <fuling.lgz@alibaba-inc.com>
This commit is contained in:
李国忠 2020-02-25 16:22:14 +08:00 committed by GitHub
parent 46129fdebb
commit 029b45aa30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View file

@ -152,6 +152,7 @@ const (
servicePortProtocolLabel = metaLabelPrefix + "service_port_protocol"
serviceClusterIPLabel = metaLabelPrefix + "service_cluster_ip"
serviceExternalNameLabel = metaLabelPrefix + "service_external_name"
serviceType = metaLabelPrefix + "service_type"
)
func serviceLabels(svc *apiv1.Service) model.LabelSet {
@ -188,6 +189,7 @@ func (s *Service) buildService(svc *apiv1.Service) *targetgroup.Group {
model.AddressLabel: lv(addr),
servicePortNameLabel: lv(port.Name),
servicePortProtocolLabel: lv(string(port.Protocol)),
serviceType: lv(string(svc.Spec.Type)),
}
if svc.Spec.Type == apiv1.ServiceTypeExternalName {

View file

@ -112,6 +112,7 @@ func TestServiceDiscoveryAdd(t *testing.T) {
{
"__meta_kubernetes_service_port_protocol": "TCP",
"__address__": "testservice.default.svc:30900",
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
},
@ -127,6 +128,7 @@ func TestServiceDiscoveryAdd(t *testing.T) {
{
"__meta_kubernetes_service_port_protocol": "TCP",
"__address__": "testservice-external.default.svc:31900",
"__meta_kubernetes_service_type": "ExternalName",
"__meta_kubernetes_service_port_name": "testport",
"__meta_kubernetes_service_external_name": "FooExternalName",
},
@ -175,12 +177,14 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
{
"__meta_kubernetes_service_port_protocol": "TCP",
"__address__": "testservice.default.svc:30900",
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport0",
},
{
"__meta_kubernetes_service_port_protocol": "UDP",
"__address__": "testservice.default.svc:30901",
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport1",
},
@ -218,6 +222,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
{
"__meta_kubernetes_service_port_protocol": "TCP",
"__address__": "testservice.ns1.svc:30900",
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
},
@ -233,6 +238,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
{
"__meta_kubernetes_service_port_protocol": "TCP",
"__address__": "testservice.ns2.svc:30900",
"__meta_kubernetes_service_type": "ClusterIP",
"__meta_kubernetes_service_cluster_ip": "10.0.0.1",
"__meta_kubernetes_service_port_name": "testport",
},

View file

@ -743,6 +743,7 @@ Available meta labels:
* `__meta_kubernetes_service_name`: The name of the service object.
* `__meta_kubernetes_service_port_name`: Name of the service port for the target.
* `__meta_kubernetes_service_port_protocol`: Protocol of the service port for the target.
* `__meta_kubernetes_service_type`: The type of the service.
#### `pod`