Add support for spring.cloud.kubernetes.discovery.service-labels filter in Fabric8ServicesListSupplier
Description
The current implementation of Fabric8ServicesListSupplier does not take into account the service labels filter specified in the spring.cloud.kubernetes.discovery.service-labels property. This feature would enhance the service discovery mechanism by allowing users to filter services based on their labels.
Motivation
- Enhanced Filtering Capabilities: Allow users to selectively discover services based on specific labels, improving the flexibility of service discovery.
- Improved Configuration Management: Provide a more granular way to manage and discover services within a Kubernetes cluster.
- Better Integration: Align with existing Spring Cloud Kubernetes configuration properties for a consistent user experience.
Proposed Solution
Modify the Fabric8ServicesListSupplier to:
- Apply labels from property
spring.cloud.kubernetes.discovery.service-labelsas filters when querying services from Kubernetes.
Example Usage
Configuration in application.properties:
spring:
cloud:
kubernetes:
discovery:
service-labels:
environment: production
team: dev
I think that this makes sense. We currently do it based on the property called : loadbalancer.client.name; and we only search for services by name which match that.
In the discovery client, we do it either based on labels or SpEL expression. We could implement it in the load balancer to search by labels too, especially since spring.cloud.kubernetes.discovery.service-labels indeed already exists.
I like the idea, but let's see what @ryanjbaxter thinks about it.
We already have a similar request, but for configuration watcher : https://github.com/spring-cloud/spring-cloud-kubernetes/issues/1816
Sounds good to me