Reload namespace and label filtering

By default, a namespace chosen using the steps outlined in Namespace resolution will be used to listen to changes in configmaps and secrets. i.e.: if you do not tell reload what namespaces and configmaps/secrets to watch for, it will watch all configmaps/secrets from the namespace that will be computed using the above algorithm.spring-doc.cn

On the other hand, you can define a more fine-grained approach. For example, you can specify the namespaces where changes will be monitored:spring-doc.cn

spring:
  application:
    name: event-reload
  cloud:
    kubernetes:
      reload:
        enabled: true
        strategy: shutdown
        mode: event
        namespaces:
          - my-namespace

Such a configuration will make the app watch changes only in the my-namespace namespace. Mind that this will watch all configmaps/secrets (depending on which one you enable). If you want an even more fine-grained approach, you can enable "label-filtering". First we need to enable such support via : enable-reload-filtering: truespring-doc.cn

spring:
  application:
    name: event-reload
  cloud:
    kubernetes:
      reload:
        enabled: true
        strategy: shutdown
        mode: event
        namespaces:
          - my-namespaces
        monitoring-config-maps: true
        enable-reload-filtering: true

What this will do, is watch configmaps/secrets that only have the spring.cloud.kubernetes.config.informer.enabled: true label.spring-doc.cn

Table 1. Properties:
Name Type Default Description

spring.cloud.kubernetes.reload.enabledspring-doc.cn

Booleanspring-doc.cn

falsespring-doc.cn

Enables monitoring of property sources and configuration reloadspring-doc.cn

spring.cloud.kubernetes.reload.monitoring-config-mapsspring-doc.cn

Booleanspring-doc.cn

truespring-doc.cn

Allow monitoring changes in config mapsspring-doc.cn

spring.cloud.kubernetes.reload.monitoring-secretsspring-doc.cn

Booleanspring-doc.cn

falsespring-doc.cn

Allow monitoring changes in secretsspring-doc.cn

spring.cloud.kubernetes.reload.strategyspring-doc.cn

Enumspring-doc.cn

refreshspring-doc.cn

The strategy to use when firing a reload (refresh, restart_context, or shutdown)spring-doc.cn

spring.cloud.kubernetes.reload.modespring-doc.cn

Enumspring-doc.cn

eventspring-doc.cn

Specifies how to listen for changes in property sources (event or polling)spring-doc.cn

spring.cloud.kubernetes.reload.periodspring-doc.cn

Durationspring-doc.cn

15sspring-doc.cn

The period for verifying changes when using the polling strategyspring-doc.cn

spring.cloud.kubernetes.reload.namespacesspring-doc.cn

String[]spring-doc.cn

namespaces where we should watch for changesspring-doc.cn

spring.cloud.kubernetes.reload.enable-reload-filteringspring-doc.cn

Stringspring-doc.cn

enabled labeled filtering for reload functionalityspring-doc.cn

  • You should not use properties under spring.cloud.kubernetes.reload in config maps or secrets. Changing such properties at runtime may lead to unexpected results.spring-doc.cn

  • Deleting a property or the whole config map does not restore the original state of the beans when you use the refresh level.spring-doc.cn