Skip to content

Wrong delimiter '&' in "labelSelector" of KubernetesCatalogWatchContext (spring-cloud-kubernetes-client-discovery) #1899

@cmaune

Description

@cmaune

We use the lasted version of org.springframework.cloud:spring-cloud-starter-kubernetes-client in combination with the latest spring boot admin release.

We configured two labels for discovery:

spring:
    cloud:
      kubernetes:
        discovery:
            serviceLabels:
                key1: value1
                key2: label2
            namespaces:
                - test

This leads to repeatly can not list endpoints in namespace warn log messages from KubernetesEndpointsCatalogWatch

The APIException thrown in the used io.kubernetes:client-java did not have any (message/stacktrace) helpfull information.

After turning on some http traffic logging we saw this request:

api/v1/namespaces/test/endpoints?labelSelector=key1%3Dvalue1%26key2%3Dvalue2

resulting in

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"unable to parse requirement: values[0][key1]: Invalid Value \"value1\u0026key2\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')","reason":"BadRequest","code":400}.

Leading to the hint that the delimiter & used here KubernetesCatalogWatchContext::labelSelector is wrong and should be ,

With spring-cloud-starter-kubernetes-fabric8 we had no problems, but there the filtering is done otherwise. Neverless the EndpointsTest from io.fabric8:kubernetes-client shows that the key value pairs should be seperated with ,

Using (same as KubernetesEndpointsCatalogWatch::namespacedEndpoints)

CoreV1Api.listNamespacedEndpoints(namespace, null, null, null, null, labelSelector(labels), null, null, null,	null, null, null)

from io.kubernetes:client-java with a labelSelector() returning a String with , separated Key=Value entries works for multiple labels.

I am unaware of this could be different for varying kubernetes versions.

Sample
Any app that uses org.springframework.cloud:spring-cloud-starter-kubernetes-client and has multiple serviceLables configured in application.yaml for discorvery should reproduce this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions