diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetector.java index daa2f839..b80f8e73 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetector.java @@ -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; - } - } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetector.java index 11e1718a..e4d9a3f8 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetector.java @@ -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; - } - } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java index 6316b671..2e089b4f 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigMapWatcherChangeDetector.java @@ -84,7 +84,9 @@ public abstract class ConfigMapWatcherChangeDetector extends KubernetesClientEve } } - protected boolean isSpringCloudKubernetesConfig(V1ConfigMap configMap) { + protected abstract Mono 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 triggerRefresh(V1ConfigMap configMap); - } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigurationWatcherAutoConfiguration.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigurationWatcherAutoConfiguration.java index b3970303..a1d73cdf 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigurationWatcherAutoConfiguration.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/ConfigurationWatcherAutoConfiguration.java @@ -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); } } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java index e72042a3..5b9c0ccb 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/main/java/org/springframework/cloud/kubernetes/configuration/watcher/SecretsWatcherChangeDetector.java @@ -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 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 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")); + } + } diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetectorTests.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetectorTests.java index c8fac120..d1916ee7 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetectorTests.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedConfigMapWatcherChangeDetectorTests.java @@ -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 diff --git a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetectorTests.java b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetectorTests.java index 1b84909e..28fd3210 100644 --- a/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetectorTests.java +++ b/spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configuration-watcher/src/test/java/org/springframework/cloud/kubernetes/configuration/watcher/BusEventBasedSecretsWatcherChangeDetectorTests.java @@ -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