|  | 
| 1 | 1 | /* | 
| 2 |  | - * Copyright 2013-2020 the original author or authors. | 
|  | 2 | + * Copyright 2013-2024 the original author or authors. | 
| 3 | 3 |  * | 
| 4 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
| 5 | 5 |  * you may not use this file except in compliance with the License. | 
|  | 
| 18 | 18 | 
 | 
| 19 | 19 | import io.kubernetes.client.openapi.apis.CoreV1Api; | 
| 20 | 20 | 
 | 
| 21 |  | -import org.springframework.boot.actuate.autoconfigure.amqp.RabbitHealthContributorAutoConfiguration; | 
| 22 |  | -import org.springframework.boot.autoconfigure.AutoConfiguration; | 
|  | 21 | +import org.springframework.boot.autoconfigure.AutoConfigureAfter; | 
|  | 22 | +import org.springframework.boot.autoconfigure.AutoConfigureBefore; | 
| 23 | 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | 
|  | 24 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform; | 
| 24 | 25 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | 
|  | 26 | +import org.springframework.boot.cloud.CloudPlatform; | 
| 25 | 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; | 
| 26 |  | -import org.springframework.cloud.bus.BusProperties; | 
| 27 |  | -import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration; | 
|  | 28 | +import org.springframework.cloud.bus.BusStreamAutoConfiguration; | 
| 28 | 29 | import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySourceLocator; | 
| 29 | 30 | import org.springframework.cloud.kubernetes.client.config.KubernetesClientSecretsPropertySourceLocator; | 
| 30 |  | -import org.springframework.cloud.kubernetes.client.discovery.reactive.KubernetesInformerReactiveDiscoveryClient; | 
| 31 | 31 | import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; | 
| 32 | 32 | import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties; | 
| 33 | 33 | import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationUpdateStrategy; | 
| 34 |  | -import org.springframework.context.ApplicationEventPublisher; | 
| 35 | 34 | import org.springframework.context.annotation.Bean; | 
| 36 | 35 | import org.springframework.context.annotation.Configuration; | 
| 37 |  | -import org.springframework.context.annotation.Import; | 
| 38 |  | -import org.springframework.context.annotation.Profile; | 
| 39 | 36 | import org.springframework.core.env.AbstractEnvironment; | 
| 40 | 37 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | 
| 41 | 38 | import org.springframework.web.reactive.function.client.WebClient; | 
|  | 
| 45 | 42 |  * @author Kris Iyer | 
| 46 | 43 |  */ | 
| 47 | 44 | @Configuration(proxyBeanMethods = false) | 
|  | 45 | +@ConditionalOnCloudPlatform(CloudPlatform.KUBERNETES) | 
| 48 | 46 | @EnableConfigurationProperties({ ConfigurationWatcherConfigurationProperties.class }) | 
| 49 |  | -@Import({ ConfigurationWatcherAutoConfiguration.RefreshTriggerConfiguration.class }) | 
|  | 47 | +@AutoConfigureAfter({ RefreshTriggerAutoConfiguration.class, BusRabbitAutoConfiguration.class, | 
|  | 48 | +		BusKafkaAutoConfiguration.class }) | 
|  | 49 | +@AutoConfigureBefore(BusStreamAutoConfiguration.class) | 
| 50 | 50 | public class ConfigurationWatcherAutoConfiguration { | 
| 51 | 51 | 
 | 
| 52 |  | -	private static final String AMQP = "bus-amqp"; | 
| 53 |  | - | 
| 54 |  | -	private static final String KAFKA = "bus-kafka"; | 
| 55 |  | - | 
| 56 | 52 | 	@Bean | 
| 57 | 53 | 	@ConditionalOnMissingBean | 
| 58 | 54 | 	public WebClient webClient(WebClient.Builder webClientBuilder) { | 
| @@ -87,95 +83,4 @@ public SecretsWatcherChangeDetector httpBasedSecretsWatchChangeDetector(Abstract | 
| 87 | 83 | 				httpRefreshTrigger); | 
| 88 | 84 | 	} | 
| 89 | 85 | 
 | 
| 90 |  | -	@Configuration | 
| 91 |  | -	@Profile(AMQP) | 
| 92 |  | -	@Import({ ContextFunctionCatalogAutoConfiguration.class, RabbitHealthContributorAutoConfiguration.class, | 
| 93 |  | -			RefreshTriggerConfiguration.class }) | 
| 94 |  | -	static class BusRabbitConfiguration { | 
| 95 |  | - | 
| 96 |  | -		@Bean | 
| 97 |  | -		@ConditionalOnMissingBean(ConfigMapWatcherChangeDetector.class) | 
| 98 |  | -		@ConditionalOnBean(KubernetesClientConfigMapPropertySourceLocator.class) | 
| 99 |  | -		public ConfigMapWatcherChangeDetector busConfigMapChangeWatcher(AbstractEnvironment environment, | 
| 100 |  | -				CoreV1Api coreV1Api, KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator, | 
| 101 |  | -				KubernetesNamespaceProvider kubernetesNamespaceProvider, ConfigReloadProperties properties, | 
| 102 |  | -				ConfigurationUpdateStrategy strategy, | 
| 103 |  | -				ConfigurationWatcherConfigurationProperties k8SConfigurationProperties, | 
| 104 |  | -				ThreadPoolTaskExecutor threadFactory, BusRefreshTrigger busRefreshTrigger) { | 
| 105 |  | -			return new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, environment, properties, strategy, | 
| 106 |  | -					configMapPropertySourceLocator, kubernetesNamespaceProvider, k8SConfigurationProperties, | 
| 107 |  | -					threadFactory, busRefreshTrigger); | 
| 108 |  | -		} | 
| 109 |  | - | 
| 110 |  | -		@Bean | 
| 111 |  | -		@ConditionalOnMissingBean(SecretsWatcherChangeDetector.class) | 
| 112 |  | -		@ConditionalOnBean(KubernetesClientSecretsPropertySourceLocator.class) | 
| 113 |  | -		public SecretsWatcherChangeDetector busSecretsChangeWatcher(AbstractEnvironment environment, | 
| 114 |  | -				CoreV1Api coreV1Api, KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator, | 
| 115 |  | -				ConfigReloadProperties properties, KubernetesNamespaceProvider kubernetesNamespaceProvider, | 
| 116 |  | -				ConfigurationUpdateStrategy strategy, | 
| 117 |  | -				ConfigurationWatcherConfigurationProperties k8SConfigurationProperties, | 
| 118 |  | -				ThreadPoolTaskExecutor threadFactory, BusRefreshTrigger busRefreshTrigger) { | 
| 119 |  | -			return new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, environment, properties, strategy, | 
| 120 |  | -					secretsPropertySourceLocator, kubernetesNamespaceProvider, k8SConfigurationProperties, | 
| 121 |  | -					threadFactory, busRefreshTrigger); | 
| 122 |  | -		} | 
| 123 |  | - | 
| 124 |  | -	} | 
| 125 |  | - | 
| 126 |  | -	@Configuration | 
| 127 |  | -	@Profile(KAFKA) | 
| 128 |  | -	@Import({ ContextFunctionCatalogAutoConfiguration.class, RefreshTriggerConfiguration.class }) | 
| 129 |  | -	static class BusKafkaConfiguration { | 
| 130 |  | - | 
| 131 |  | -		@Bean | 
| 132 |  | -		@ConditionalOnMissingBean(ConfigMapWatcherChangeDetector.class) | 
| 133 |  | -		@ConditionalOnBean(KubernetesClientConfigMapPropertySourceLocator.class) | 
| 134 |  | -		public ConfigMapWatcherChangeDetector busConfigMapChangeWatcher(AbstractEnvironment environment, | 
| 135 |  | -				CoreV1Api coreV1Api, KubernetesClientConfigMapPropertySourceLocator configMapPropertySourceLocator, | 
| 136 |  | -				ConfigReloadProperties properties, KubernetesNamespaceProvider namespaceProvider, | 
| 137 |  | -				ConfigurationUpdateStrategy strategy, | 
| 138 |  | -				ConfigurationWatcherConfigurationProperties k8SConfigurationProperties, | 
| 139 |  | -				ThreadPoolTaskExecutor threadFactory, BusRefreshTrigger busRefreshTrigger) { | 
| 140 |  | -			return new BusEventBasedConfigMapWatcherChangeDetector(coreV1Api, environment, properties, strategy, | 
| 141 |  | -					configMapPropertySourceLocator, namespaceProvider, k8SConfigurationProperties, threadFactory, | 
| 142 |  | -					busRefreshTrigger); | 
| 143 |  | -		} | 
| 144 |  | - | 
| 145 |  | -		@Bean | 
| 146 |  | -		@ConditionalOnMissingBean(SecretsWatcherChangeDetector.class) | 
| 147 |  | -		@ConditionalOnBean(KubernetesClientSecretsPropertySourceLocator.class) | 
| 148 |  | -		public SecretsWatcherChangeDetector busSecretsChangeWatcher(AbstractEnvironment environment, | 
| 149 |  | -				CoreV1Api coreV1Api, KubernetesClientSecretsPropertySourceLocator secretsPropertySourceLocator, | 
| 150 |  | -				ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy, | 
| 151 |  | -				ConfigurationWatcherConfigurationProperties k8SConfigurationProperties, | 
| 152 |  | -				ThreadPoolTaskExecutor threadFactory, KubernetesNamespaceProvider namespaceProvider, | 
| 153 |  | -				BusRefreshTrigger busRefreshTrigger) { | 
| 154 |  | -			return new BusEventBasedSecretsWatcherChangeDetector(coreV1Api, environment, properties, strategy, | 
| 155 |  | -					secretsPropertySourceLocator, namespaceProvider, k8SConfigurationProperties, threadFactory, | 
| 156 |  | -					busRefreshTrigger); | 
| 157 |  | -		} | 
| 158 |  | - | 
| 159 |  | -	} | 
| 160 |  | - | 
| 161 |  | -	@AutoConfiguration | 
| 162 |  | -	static class RefreshTriggerConfiguration { | 
| 163 |  | - | 
| 164 |  | -		@Bean | 
| 165 |  | -		@ConditionalOnMissingBean | 
| 166 |  | -		@Profile({ AMQP, KAFKA }) | 
| 167 |  | -		public BusRefreshTrigger busRefreshTrigger(ApplicationEventPublisher applicationEventPublisher, | 
| 168 |  | -				BusProperties busProperties) { | 
| 169 |  | -			return new BusRefreshTrigger(applicationEventPublisher, busProperties.getId()); | 
| 170 |  | -		} | 
| 171 |  | - | 
| 172 |  | -		@Bean | 
| 173 |  | -		@ConditionalOnMissingBean | 
| 174 |  | -		public HttpRefreshTrigger httpRefreshTrigger(KubernetesInformerReactiveDiscoveryClient client, | 
| 175 |  | -				ConfigurationWatcherConfigurationProperties properties, WebClient webClient) { | 
| 176 |  | -			return new HttpRefreshTrigger(client, properties, webClient); | 
| 177 |  | -		} | 
| 178 |  | - | 
| 179 |  | -	} | 
| 180 |  | - | 
| 181 | 86 | } | 
0 commit comments