24
24
import org .springframework .boot .actuate .autoconfigure .endpoint .EndpointAutoConfiguration ;
25
25
import org .springframework .boot .actuate .autoconfigure .info .InfoEndpointAutoConfiguration ;
26
26
import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
27
- import org .springframework .boot .autoconfigure .condition .AnyNestedCondition ;
28
27
import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
29
28
import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
30
29
import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingBean ;
36
35
import org .springframework .cloud .context .restart .RestartEndpoint ;
37
36
import org .springframework .cloud .kubernetes .config .ConfigMapPropertySourceLocator ;
38
37
import org .springframework .cloud .kubernetes .config .SecretsPropertySourceLocator ;
38
+ import org .springframework .cloud .kubernetes .config .reload .condition .EventReloadDetectionMode ;
39
+ import org .springframework .cloud .kubernetes .config .reload .condition .PollingReloadDetectionMode ;
39
40
import org .springframework .context .ConfigurableApplicationContext ;
40
41
import org .springframework .context .annotation .Bean ;
41
42
import org .springframework .context .annotation .Conditional ;
49
50
* Definition of beans needed for the automatic reload of configuration.
50
51
*
51
52
* @author Nicolla Ferraro
53
+ * @author Kris Iyer
52
54
*/
53
55
@ Configuration (proxyBeanMethods = false )
54
56
@ ConditionalOnProperty (value = "spring.cloud.kubernetes.enabled" , matchIfMissing = true )
55
57
@ ConditionalOnClass (EndpointAutoConfiguration .class )
56
58
@ AutoConfigureAfter ({ InfoEndpointAutoConfiguration .class , RefreshEndpointAutoConfiguration .class ,
57
59
RefreshAutoConfiguration .class })
58
60
@ EnableConfigurationProperties (ConfigReloadProperties .class )
59
-
60
61
public class ConfigReloadAutoConfiguration {
61
62
62
63
/**
@@ -75,25 +76,71 @@ protected static class ConfigReloadAutoConfigurationBeans {
75
76
private KubernetesClient kubernetesClient ;
76
77
77
78
/**
79
+ * Polling configMap ConfigurationChangeDetector.
78
80
* @param properties config reload properties
79
81
* @param strategy configuration update strategy
82
+ * @param configMapPropertySourceLocator configMap property source locator
80
83
* @return a bean that listen to configuration changes and fire a reload.
81
84
*/
82
85
@ Bean
83
- @ Conditional (OnConfigEnabledOrSecretsEnabled .class )
84
- public ConfigurationChangeDetector propertyChangeWatcher (ConfigReloadProperties properties ,
85
- ConfigurationUpdateStrategy strategy ,
86
- @ Autowired (required = false ) ConfigMapPropertySourceLocator configMapPropertySourceLocator ,
87
- @ Autowired (required = false ) SecretsPropertySourceLocator secretsPropertySourceLocator ) {
88
- switch (properties .getMode ()) {
89
- case POLLING :
90
- return new PollingConfigurationChangeDetector (this .environment , properties , this .kubernetesClient ,
91
- strategy , configMapPropertySourceLocator , secretsPropertySourceLocator );
92
- case EVENT :
93
- return new EventBasedConfigurationChangeDetector (this .environment , properties , this .kubernetesClient ,
94
- strategy , configMapPropertySourceLocator , secretsPropertySourceLocator );
95
- }
96
- throw new IllegalStateException ("Unsupported configuration reload mode: " + properties .getMode ());
86
+ @ ConditionalOnBean (ConfigMapPropertySourceLocator .class )
87
+ @ Conditional (PollingReloadDetectionMode .class )
88
+ public ConfigurationChangeDetector configMapPropertyChangePollingWatcher (ConfigReloadProperties properties ,
89
+ ConfigurationUpdateStrategy strategy , ConfigMapPropertySourceLocator configMapPropertySourceLocator ) {
90
+
91
+ return new PollingConfigMapChangeDetector (this .environment , properties , this .kubernetesClient , strategy ,
92
+ configMapPropertySourceLocator );
93
+ }
94
+
95
+ /**
96
+ * Polling secrets ConfigurationChangeDetector.
97
+ * @param properties config reload properties
98
+ * @param strategy configuration update strategy
99
+ * @param secretsPropertySourceLocator secrets property source locator
100
+ * @return a bean that listen to configuration changes and fire a reload.
101
+ */
102
+ @ Bean
103
+ @ ConditionalOnBean (SecretsPropertySourceLocator .class )
104
+ @ Conditional (PollingReloadDetectionMode .class )
105
+ public ConfigurationChangeDetector secretsPropertyChangePollingWatcher (ConfigReloadProperties properties ,
106
+ ConfigurationUpdateStrategy strategy , SecretsPropertySourceLocator secretsPropertySourceLocator ) {
107
+
108
+ return new PollingSecretsChangeDetector (this .environment , properties , this .kubernetesClient , strategy ,
109
+ secretsPropertySourceLocator );
110
+ }
111
+
112
+ /**
113
+ * Event Based configMap ConfigurationChangeDetector.
114
+ * @param properties config reload properties
115
+ * @param strategy configuration update strategy
116
+ * @param configMapPropertySourceLocator configMap property source locator
117
+ * @return a bean that listen to configMap change events and fire a reload.
118
+ */
119
+ @ Bean
120
+ @ ConditionalOnBean (ConfigMapPropertySourceLocator .class )
121
+ @ Conditional (EventReloadDetectionMode .class )
122
+ public ConfigurationChangeDetector configMapPropertyChangeEventWatcher (ConfigReloadProperties properties ,
123
+ ConfigurationUpdateStrategy strategy , ConfigMapPropertySourceLocator configMapPropertySourceLocator ) {
124
+
125
+ return new EventBasedConfigMapChangeDetector (this .environment , properties , this .kubernetesClient , strategy ,
126
+ configMapPropertySourceLocator );
127
+ }
128
+
129
+ /**
130
+ * Event Based secrets ConfigurationChangeDetector.
131
+ * @param properties config reload properties
132
+ * @param strategy configuration update strategy
133
+ * @param secretsPropertySourceLocator secrets property source locator
134
+ * @return a bean that listen to secrets change events and fire a reload.
135
+ */
136
+ @ Bean
137
+ @ ConditionalOnBean (SecretsPropertySourceLocator .class )
138
+ @ Conditional (EventReloadDetectionMode .class )
139
+ public ConfigurationChangeDetector secretsPropertyChangeEventWatcher (ConfigReloadProperties properties ,
140
+ ConfigurationUpdateStrategy strategy , SecretsPropertySourceLocator secretsPropertySourceLocator ) {
141
+
142
+ return new EventBasedSecretsChangeDetector (this .environment , properties , this .kubernetesClient , strategy ,
143
+ secretsPropertySourceLocator );
97
144
}
98
145
99
146
/**
@@ -135,24 +182,6 @@ private static void wait(ConfigReloadProperties properties) {
135
182
}
136
183
}
137
184
138
- private static class OnConfigEnabledOrSecretsEnabled extends AnyNestedCondition {
139
-
140
- OnConfigEnabledOrSecretsEnabled () {
141
- super (ConfigurationPhase .REGISTER_BEAN );
142
- }
143
-
144
- @ ConditionalOnBean (ConfigMapPropertySourceLocator .class )
145
- static class configEnabled {
146
-
147
- }
148
-
149
- @ ConditionalOnBean (SecretsPropertySourceLocator .class )
150
- static class secretsEnabled {
151
-
152
- }
153
-
154
- }
155
-
156
185
}
157
186
158
187
}
0 commit comments