-
Notifications
You must be signed in to change notification settings - Fork 1k
Add namespace information to service instance metadata #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add namespace information to service instance metadata #503
Conversation
@m-kay - I wonder why to consider a namespace as long as it's still one service doing the same thing, but happens to be across different namespaces? why not to discover and balance across regardless of the namespace as long as endpoints are reachable using registered IP/port? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to rely on @Haybu and @ryanjbaxter for implementation checks
.../src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClient.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClient.java
Outdated
Show resolved
Hide resolved
I agree with @Haybu, I don't think the service id should be different. Maybe we should add namespace information to the metadata? |
Correct me if I'm wrong, but I think it's not possible to access the service by only its service id from outside its own namespace. See: https://kubernetes.io/docs/concepts/services-networking/service/#dns |
@m-kay - that is true when a service name/id is used directly and you depend on k8s platform to resolve. But the idea here is that the discovery client uses a service id to interrogate the platform server for the service endpoints, hence providing a list of pods ip:port to pick from and hit. |
But how can you be sure that two services are really the same? It's totally valid to have two different services with the same name in different namespaces. In my case I have different applications which are structured the same way in different namespaces. Each application has the same service for example "gateway". However each gateway does something different because it's specific for the application in that namespace. |
We'll need to have a discussion. What you've described and what Haytham and Ryan have said are both valid, but at odds with each other. We'll need to see if we can reconcile the two. I don't know if it's in discovery client or in loadbalancer or both. |
Hi am looking for a similar solution where services can be deployed on multiple namespaces (1 namespace eq customer instance). I still have a multitenant application using the kuberentesDiscoveryClient and I would need to route the request to multiple namespaces. I was wondering why not add the namespace to kubernetesServiceInstance instead of in the serviceId? |
After discussing this with the team today we think the best solution at this time is to only take the portion of this PR which puts the namespace in the service metadata From there clients should be able to determine which instance of the service they want to target. @m-kay if you are interested in modifying the PR to just include those changes please let me know |
If the service instance would contain the namespace as a field, Spring cloud gateway could for instance forward to the correct namespace when using kubernetes services dns. example config:
|
@ryanjbaxter yes I would like to change the pull requests. However the code you mentioned in the diff does not include the namespace in the service metadata but was to filter service instances in the k8s client. As I understood the idea is to include the namespace information in the ServiceInstance, right? @GianniGiglio I could include a getter method in the KubernetesServiceInstance which returns the information from the metadata, that should also do the trick. However you will still have the problem that the service which is used can be from any namespace because the discovery client will return an unfiltered list of all instances of the service from all namespaces. |
c036db5
to
a422611
Compare
… all-namspaces=true Fixes spring-cloudgh-503
That depends on how the Kubernetes client is configured I think. At least your proposed solution is how I worked around it by over-writing the kubernetesServiceInstance and populate the namespace based on the metadata. this.kubernetesClient.endpoints().inNamespace("default") --> will only return the endpoints for the default namespace endpoints.getMetadata().getNamespace() should give you the namespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one small tweak
.../src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesServiceInstance.java
Outdated
Show resolved
Hide resolved
Can we get this in the next 1.1.x release by any chance or will it only make it in the next major release? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you retarget to 1.1.x branch?
/** | ||
* Key of the namespace metadata. | ||
*/ | ||
public static final String NAMESPACE_METADAT_KEY = "namespace"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAMESPACE_METADAT_KEY
-> NAMESPACE_METADATA_KEY
(metadata is missspelled).
… all-namspaces=true Fixes spring-cloudgh-503
2e955ab
to
6f7c1be
Compare
6f7c1be
to
3d42f97
Compare
As mentioned in issue #473 the namespace should be reflected in the serviceId when using discovery with all-namespaces set to true.