spring-cloud / spring-cloud-kubernetes

Kubernetes integration with Spring Cloud Discovery Client, Configuration, etc...
Apache License 2.0
3.46k stars 1.03k forks source link

Watch ConfigMaps and Secrets With Spring Cloud Kubernetes Config Watcher From Other Namespaces #814

Closed PetricHwang closed 2 years ago

PetricHwang commented 3 years ago

My Spring Cloud Kubernetes Configuration Watcher and configmap is different namespace, when I change configmap, then watcher can't listener this configmap change.

ryanjbaxter commented 3 years ago

Can you try setting spring.cloud.kubernetes.client.namespace to the namespace in which the configmap is in? You might also need to set spring.cloud.kubernetes.discovery.all-namespaces=true depending on which notification strategy you are using.

PetricHwang commented 3 years ago

Can you try setting spring.cloud.kubernetes.client.namespace to the namespace in which the configmap is in? You might also need to set spring.cloud.kubernetes.discovery.all-namespaces=true depending on which notification strategy you are using.

Thanks for your reply.

I try setting spring.cloud.kubernetes.client.namespace to the namespace in which the configmap is in and set spring.cloud.kubernetes.discovery.all-namespaces=true , then is ok. But I hope the watcher can listener multiple(one, two...) namespace configmap. Thank you.

ryanjbaxter commented 3 years ago

Yeah that is an enhancement. I will try and work on this, but if anyone else wants to help, you are more than welcome

kabennett commented 3 years ago

If I understand what this enhancement is requested to provide, it's the same thing as described here, correct? If so, is there any update regarding progress on this enhancement? I would love to contribute, but we are expressly forbidden to according to my organization's policy. Thank you.

ryanjbaxter commented 3 years ago

No updates on this yet, sorry.

walejandromt commented 2 years ago

sorry only i want confirm if this update work for Spring Gateway load Mapped multiple Routes with multiples namespaces of Kubernetes services for example spring.cloud.kubernetes.discovery.namespaces=namespaces-app, namespaces-core, namespaces-users

ryanjbaxter commented 2 years ago

@walejandromt that does not have to do with this issue

cz4rny commented 2 years ago

OK, any hints how to make that happen? @ryanjbaxter I could be your programming hands and make that happen. However, I'd appreciate some pointers in which direction. As maybe you know what blocks the multi-namespace usage and I could try to change the code and make a PR.

ryanjbaxter commented 2 years ago

@cz4rny the main change probably needs to be made here https://github.com/spring-cloud/spring-cloud-kubernetes/blob/main/spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/reload/EventBasedConfigMapChangeDetector.java#L80

In the case where we want to monitor Config Maps across all namespaces we would need to call this.kubernetesClient.configMaps().inAnyNamespace().watch(....

A similar change would need to be made for Secrets.

This should only be enabled when a property is set.

wind57 commented 2 years ago

@ryanjbaxter just a minor note, I don't think that EventBasedConfigMapChangeDetector (now it's called Fabric8EventBasedConfigMapChangeDetector in main branch) is the right place, users seem to want that ability via the config watcher.

ryanjbaxter commented 2 years ago

I'm not sure what you mean...

wind57 commented 2 years ago

I'll comment may be more when I get my hands on this one, and may be then it will make sense. I am still kind of far from that point, so I'll keep a longer comment for later.

webrod commented 1 year ago

so about this issue, is there a documentation about how 1 instance of the watcher controller can watch configmaps from many other namespaces? The documentation only mentions "spring.cloud.kubernetes.client.namespace", so 1 namespace. https://docs.spring.io/spring-cloud-kubernetes/docs/current/reference/html/index.html#spring-cloud-kubernetes-configuration-watcher

Based on this issue, I tried instead : name: spring.cloud.kubernetes.reload.namespaces value: "namespace1,namespace2"

The log says: o.s.c.k.c.c.KubernetesClientConfigUtils : informer namespaces : [namespace1, namespace2] tesClientEventBasedSecretsChangeDetector : added secret informer for namespace : namespace1 tesClientEventBasedSecretsChangeDetector : added secret informer for namespace : namespace2

but it only adds configmaps from the first namespace in that list, i.e. namespace1. configmaps from namespace2 are ignored

if I set like this: value: "namespace2,namespace1"

then it's the opposite, only configmap from namespace2 are added (and thus monitored).

how to watch configmaps from namespace1 AND namespace2?

thanks for the clarification! Note: I'm using springcloud/spring-cloud-kubernetes-configuration-watcher:3.0.1-SNAPSHOT

wind57 commented 1 year ago

if you look at the PR that closed this issue here, the very first file is a documentation change.

Also present here. If anything does not work the way you expect, we need a reproducible example.

webrod commented 1 year ago

I guess I'm confused because I thought property source reload was deprecated as said here: https://docs.spring.io/spring-cloud-kubernetes/docs/3.0.1-SNAPSHOT/reference/html/#propertysource-reload

which redirect to https://docs.spring.io/spring-cloud-kubernetes/docs/3.0.1-SNAPSHOT/reference/html/#spring-cloud-kubernetes-configuration-watcher which does not have any info about watching from many namespaces.

anyways, I understand now that even if deprecated we need to use a 'reload' property like I setup with my watcher controlelr deployment as environment variable; name: spring.cloud.kubernetes.reload.namespaces value: "namespace1,namespace2"

I will continue my investigation, if it still does not work (i.e. only monitoring confimaps from the first namespace in that list) then I will create a new issue

thanks

wind57 commented 1 year ago

totally understandable on the confusion part, if something is unclear you can ask here anytime. And while indeed that is deprecated functionality, it still works. I don't know of any plans to actually drop it (but I am not a Spring employee so that this with a grain of salt). As a matter of fact, it was improved in this release.

PetricHwang commented 1 year ago

Sorry, I need to know how to achieve this. Thanks!

wind57 commented 1 year ago

@PetricHwang did you read the documentation? https://docs.spring.io/spring-cloud-kubernetes/docs/3.0.1-SNAPSHOT/reference/html/#namespace-label-filtering