Add possibility to define the label for watcher 2 (#1062)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2020 the original author or authors.
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,6 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@@ -36,10 +35,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
* @author Ryan Baxter
|
||||
* @author Kris Iyer
|
||||
*/
|
||||
public class BusEventBasedConfigMapWatcherChangeDetector extends ConfigMapWatcherChangeDetector
|
||||
implements ApplicationEventPublisherAware {
|
||||
public class BusEventBasedConfigMapWatcherChangeDetector extends ConfigMapWatcherChangeDetector {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
private final ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
private final BusProperties busProperties;
|
||||
|
||||
@@ -48,10 +46,11 @@ public class BusEventBasedConfigMapWatcherChangeDetector extends ConfigMapWatche
|
||||
KubernetesClientConfigMapPropertySourceLocator propertySourceLocator,
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider, BusProperties busProperties,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor) {
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor, ApplicationEventPublisher applicationEventPublisher) {
|
||||
super(coreV1Api, environment, properties, strategy, propertySourceLocator, kubernetesNamespaceProvider,
|
||||
k8SConfigurationProperties, threadPoolTaskExecutor);
|
||||
this.busProperties = busProperties;
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,9 +60,4 @@ public class BusEventBasedConfigMapWatcherChangeDetector extends ConfigMapWatche
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2020 the original author or authors.
|
||||
* Copyright 2013-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,7 +28,6 @@ import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@@ -36,10 +35,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
* @author Ryan Baxter
|
||||
* @author Kris Iyer
|
||||
*/
|
||||
public class BusEventBasedSecretsWatcherChangeDetector extends SecretsWatcherChangeDetector
|
||||
implements ApplicationEventPublisherAware {
|
||||
public class BusEventBasedSecretsWatcherChangeDetector extends SecretsWatcherChangeDetector {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
private final ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
private final BusProperties busProperties;
|
||||
|
||||
@@ -48,10 +46,11 @@ public class BusEventBasedSecretsWatcherChangeDetector extends SecretsWatcherCha
|
||||
KubernetesClientSecretsPropertySourceLocator propertySourceLocator,
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider, BusProperties busProperties,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor) {
|
||||
ThreadPoolTaskExecutor threadPoolTaskExecutor, ApplicationEventPublisher applicationEventPublisher) {
|
||||
super(coreV1Api, environment, properties, strategy, propertySourceLocator, kubernetesNamespaceProvider,
|
||||
k8SConfigurationProperties, threadPoolTaskExecutor);
|
||||
this.busProperties = busProperties;
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,9 +60,4 @@ public class BusEventBasedSecretsWatcherChangeDetector extends SecretsWatcherCha
|
||||
return Mono.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
||||
this.applicationEventPublisher = applicationEventPublisher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,7 +84,9 @@ public abstract class ConfigMapWatcherChangeDetector extends KubernetesClientEve
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isSpringCloudKubernetesConfig(V1ConfigMap configMap) {
|
||||
protected abstract Mono<Void> triggerRefresh(V1ConfigMap configMap);
|
||||
|
||||
private boolean isSpringCloudKubernetesConfig(V1ConfigMap configMap) {
|
||||
if (configMap.getMetadata() == null || configMap.getMetadata().getLabels() == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -92,6 +94,4 @@ public abstract class ConfigMapWatcherChangeDetector extends KubernetesClientEve
|
||||
.getOrDefault(ConfigurationWatcherConfigurationProperties.CONFIG_LABEL, "false"));
|
||||
}
|
||||
|
||||
protected abstract Mono<Void> triggerRefresh(V1ConfigMap configMap);
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.cloud.kubernetes.client.discovery.reactive.Kubernetes
|
||||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties;
|
||||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -95,10 +96,10 @@ public class ConfigurationWatcherAutoConfiguration {
|
||||
KubernetesNamespaceProvider kubernetesNamespaceProvider, ConfigReloadProperties properties,
|
||||
ConfigurationUpdateStrategy strategy,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadFactory) {
|
||||
ThreadPoolTaskExecutor threadFactory, ApplicationEventPublisher applicationEventPublisher) {
|
||||
return new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, environment, properties, strategy,
|
||||
configMapPropertySourceLocator, kubernetesNamespaceProvider, busProperties,
|
||||
k8SConfigurationProperties, threadFactory);
|
||||
k8SConfigurationProperties, threadFactory, applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -110,10 +111,10 @@ public class ConfigurationWatcherAutoConfiguration {
|
||||
ConfigReloadProperties properties, KubernetesNamespaceProvider kubernetesNamespaceProvider,
|
||||
ConfigurationUpdateStrategy strategy,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadFactory) {
|
||||
ThreadPoolTaskExecutor threadFactory, ApplicationEventPublisher applicationEventPublisher) {
|
||||
return new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, environment, properties, strategy,
|
||||
secretsPropertySourceLocator, kubernetesNamespaceProvider, busProperties,
|
||||
k8SConfigurationProperties, threadFactory);
|
||||
k8SConfigurationProperties, threadFactory, applicationEventPublisher);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,10 +133,10 @@ public class ConfigurationWatcherAutoConfiguration {
|
||||
ConfigReloadProperties properties, KubernetesNamespaceProvider namespaceProvider,
|
||||
ConfigurationUpdateStrategy strategy,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadFactory) {
|
||||
ThreadPoolTaskExecutor threadFactory, ApplicationEventPublisher applicationEventPublisher) {
|
||||
return new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, environment, properties, strategy,
|
||||
configMapPropertySourceLocator, namespaceProvider, busProperties, k8SConfigurationProperties,
|
||||
threadFactory);
|
||||
threadFactory, applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -146,10 +147,11 @@ public class ConfigurationWatcherAutoConfiguration {
|
||||
KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator,
|
||||
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy,
|
||||
ConfigurationWatcherConfigurationProperties k8SConfigurationProperties,
|
||||
ThreadPoolTaskExecutor threadFactory, KubernetesNamespaceProvider namespaceProvider) {
|
||||
ThreadPoolTaskExecutor threadFactory, KubernetesNamespaceProvider namespaceProvider,
|
||||
ApplicationEventPublisher applicationEventPublisher) {
|
||||
return new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, environment, properties, strategy,
|
||||
secretsPropertySourceLocator, namespaceProvider, busProperties, k8SConfigurationProperties,
|
||||
threadFactory);
|
||||
threadFactory, applicationEventPublisher);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,16 +58,6 @@ public abstract class SecretsWatcherChangeDetector extends KubernetesClientEvent
|
||||
this.k8SConfigurationProperties = k8SConfigurationProperties;
|
||||
}
|
||||
|
||||
protected boolean isSpringCloudKubernetesSecret(V1Secret secret) {
|
||||
if (secret.getMetadata() == null || secret.getMetadata().getLabels() == null) {
|
||||
return false;
|
||||
}
|
||||
return Boolean.parseBoolean(secret.getMetadata().getLabels()
|
||||
.getOrDefault(ConfigurationWatcherConfigurationProperties.SECRET_LABEL, "false"));
|
||||
}
|
||||
|
||||
protected abstract Mono<Void> triggerRefresh(V1Secret secret);
|
||||
|
||||
@Override
|
||||
protected void onEvent(V1Secret secret) {
|
||||
if (isSpringCloudKubernetesSecret(secret)) {
|
||||
@@ -93,4 +83,14 @@ public abstract class SecretsWatcherChangeDetector extends KubernetesClientEvent
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Mono<Void> triggerRefresh(V1Secret secret);
|
||||
|
||||
private boolean isSpringCloudKubernetesSecret(V1Secret secret) {
|
||||
if (secret.getMetadata() == null || secret.getMetadata().getLabels() == null) {
|
||||
return false;
|
||||
}
|
||||
return Boolean.parseBoolean(secret.getMetadata().getLabels()
|
||||
.getOrDefault(ConfigurationWatcherConfigurationProperties.SECRET_LABEL, "false"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,8 +81,7 @@ class BusEventBasedConfigMapWatcherChangeDetectorTests {
|
||||
changeDetector = new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, mockEnvironment,
|
||||
configReloadProperties, UPDATE_STRATEGY, configMapPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), busProperties,
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor);
|
||||
changeDetector.setApplicationEventPublisher(applicationEventPublisher);
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor, applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -81,8 +81,7 @@ class BusEventBasedSecretsWatcherChangeDetectorTests {
|
||||
changeDetector = new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, mockEnvironment,
|
||||
configReloadProperties, UPDATE_STRATEGY, secretsPropertySourceLocator,
|
||||
new KubernetesNamespaceProvider(mockEnvironment), busProperties,
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor);
|
||||
changeDetector.setApplicationEventPublisher(applicationEventPublisher);
|
||||
configurationWatcherConfigurationProperties, threadPoolTaskExecutor, applicationEventPublisher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user