Skip to content

Commit 858c815

Browse files
committed
fix
Signed-off-by: wind57 <eugen.rabii@gmail.com>
1 parent 76723d3 commit 858c815

File tree

5 files changed

+63
-48
lines changed

5 files changed

+63
-48
lines changed

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedConfigMapChangeDetector.java

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class KubernetesClientEventBasedConfigMapChangeDetector extends Configura
6969

7070
private final boolean enableReloadFiltering;
7171

72+
private final boolean monitoringConfigMaps;
73+
7274
private final ResourceEventHandler<V1ConfigMap> handler = new ResourceEventHandler<>() {
7375

7476
@Override
@@ -107,33 +109,40 @@ public KubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api, Co
107109
this.coreV1Api = coreV1Api;
108110
this.apiClient = createApiClientForInformerClient();
109111
this.enableReloadFiltering = properties.enableReloadFiltering();
112+
this.monitoringConfigMaps = properties.monitoringConfigMaps();
110113
namespaces = namespaces(kubernetesNamespaceProvider, properties, "configmap");
111114
}
112115

113116
@PostConstruct
114117
void inform() {
115-
LOG.info(() -> "Kubernetes event-based configMap change detector activated");
116-
117-
namespaces.forEach(namespace -> {
118-
SharedIndexInformer<V1ConfigMap> informer;
119-
String[] filter = new String[1];
120118

121-
if (enableReloadFiltering) {
122-
filter[0] = ConfigReloadProperties.RELOAD_LABEL_FILTER + "=true";
123-
}
124-
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
125-
factories.add(factory);
126-
informer = factory
127-
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace,
128-
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
129-
params.timeoutSeconds, params.watch, null), V1ConfigMap.class, V1ConfigMapList.class);
130-
131-
LOG.debug(() -> "added configmap informer for namespace : " + namespace + " with filter : " + filter[0]);
132-
133-
informer.addEventHandler(handler);
134-
informers.add(informer);
135-
factory.startAllRegisteredInformers();
136-
});
119+
if (monitoringConfigMaps) {
120+
LOG.info(() -> "Kubernetes event-based configMap change detector activated");
121+
122+
namespaces.forEach(namespace -> {
123+
SharedIndexInformer<V1ConfigMap> informer;
124+
String[] filter = new String[1];
125+
126+
if (enableReloadFiltering) {
127+
filter[0] = ConfigReloadProperties.RELOAD_LABEL_FILTER + "=true";
128+
}
129+
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
130+
factories.add(factory);
131+
informer = factory
132+
.sharedIndexInformerFor(
133+
(CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace, null, null,
134+
null, null, filter[0], null, params.resourceVersion, null, null,
135+
params.timeoutSeconds, params.watch, null),
136+
V1ConfigMap.class, V1ConfigMapList.class);
137+
138+
LOG.debug(
139+
() -> "added configmap informer for namespace : " + namespace + " with filter : " + filter[0]);
140+
141+
informer.addEventHandler(handler);
142+
informers.add(informer);
143+
factory.startAllRegisteredInformers();
144+
});
145+
}
137146

138147
}
139148

spring-cloud-kubernetes-client-config/src/main/java/org/springframework/cloud/kubernetes/client/config/reload/KubernetesClientEventBasedSecretsChangeDetector.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public class KubernetesClientEventBasedSecretsChangeDetector extends Configurati
7171

7272
private final boolean enableReloadFiltering;
7373

74+
private final boolean monitoringSecrets;
75+
7476
private final ResourceEventHandler<V1Secret> handler = new ResourceEventHandler<>() {
7577

7678
@Override
@@ -110,34 +112,37 @@ public KubernetesClientEventBasedSecretsChangeDetector(CoreV1Api coreV1Api, Conf
110112
this.coreV1Api = coreV1Api;
111113
this.apiClient = createApiClientForInformerClient();
112114
this.enableReloadFiltering = properties.enableReloadFiltering();
115+
this.monitoringSecrets = properties.monitoringSecrets();
113116
namespaces = namespaces(kubernetesNamespaceProvider, properties, "secret");
114117
}
115118

116119
@PostConstruct
117120
void inform() {
118121
LOG.info(() -> "Kubernetes event-based secrets change detector activated");
119122

120-
namespaces.forEach(namespace -> {
121-
SharedIndexInformer<V1Secret> informer;
122-
String[] filter = new String[1];
123-
124-
if (enableReloadFiltering) {
125-
filter[0] = ConfigReloadProperties.RELOAD_LABEL_FILTER + "=true";
126-
}
127-
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
128-
factories.add(factory);
129-
informer = factory
130-
.sharedIndexInformerFor((CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(namespace,
131-
null, null, null, null, filter[0], null, params.resourceVersion, null, null,
132-
params.timeoutSeconds, params.watch, null), V1Secret.class, V1SecretList.class);
133-
134-
LOG.debug(() -> "added secret informer for namespace : " + namespace + " with filter : " + filter[0]);
135-
136-
informer.addEventHandler(handler);
137-
informers.add(informer);
138-
factory.startAllRegisteredInformers();
139-
});
140-
123+
if (monitoringSecrets) {
124+
namespaces.forEach(namespace -> {
125+
SharedIndexInformer<V1Secret> informer;
126+
String[] filter = new String[1];
127+
128+
if (enableReloadFiltering) {
129+
filter[0] = ConfigReloadProperties.RELOAD_LABEL_FILTER + "=true";
130+
}
131+
SharedInformerFactory factory = new SharedInformerFactory(apiClient);
132+
factories.add(factory);
133+
informer = factory.sharedIndexInformerFor(
134+
(CallGeneratorParams params) -> coreV1Api.listNamespacedSecretCall(namespace, null, null, null,
135+
null, filter[0], null, params.resourceVersion, null, null, params.timeoutSeconds,
136+
params.watch, null),
137+
V1Secret.class, V1SecretList.class);
138+
139+
LOG.debug(() -> "added secret informer for namespace : " + namespace + " with filter : " + filter[0]);
140+
141+
informer.addEventHandler(handler);
142+
informers.add(informer);
143+
factory.startAllRegisteredInformers();
144+
});
145+
}
141146
}
142147

143148
@PreDestroy

spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/reload/Fabric8EventBasedConfigMapChangeDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private void shutdown() {
119119

120120
private void onEvent(ConfigMap configMap) {
121121
boolean reload = ConfigReloadUtil.reload("config-map", configMap.toString(),
122-
fabric8ConfigMapPropertySourceLocator, environment, Fabric8ConfigMapPropertySource.class);
122+
fabric8ConfigMapPropertySourceLocator, environment, Fabric8ConfigMapPropertySource.class);
123123
if (reload) {
124124
reloadProperties();
125125
}

spring-cloud-kubernetes-fabric8-config/src/main/java/org/springframework/cloud/kubernetes/fabric8/config/reload/Fabric8EventBasedSecretsChangeDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private void inform() {
118118

119119
private void onEvent(Secret secret) {
120120
boolean reload = ConfigReloadUtil.reload("secrets", secret.toString(), fabric8SecretsPropertySourceLocator,
121-
environment, Fabric8SecretsPropertySource.class);
121+
environment, Fabric8SecretsPropertySource.class);
122122
if (reload) {
123123
reloadProperties();
124124
}

spring-cloud-kubernetes-fabric8-config/src/test/java/org/springframework/cloud/kubernetes/fabric8/config/reload_it/EventReloadSecretTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
*/
6262
@SpringBootTest(
6363
properties = { "spring.main.allow-bean-definition-overriding=true",
64-
"logging.level.org.springframework.cloud.kubernetes.commons.config=debug" },
64+
"logging.level.org.springframework.cloud.kubernetes.commons.config=debug" },
6565
classes = { EventReloadSecretTest.TestConfig.class })
6666
@EnableKubernetesMockClient(crud = true)
6767
@ExtendWith(OutputCaptureExtension.class)
@@ -98,7 +98,8 @@ void test(CapturedOutput output) {
9898
.inNamespace(NAMESPACE);
9999

100100
// makes sure that when 'onEvent' is triggered (because we added a config map)
101-
// the call to /api/v1/namespaces/spring-k8s/secrets will not fail with an Exception
101+
// the call to /api/v1/namespaces/spring-k8s/secrets will not fail with an
102+
// Exception
102103
MixedOperation<Secret, SecretList, Resource<Secret>> mixedOperation = Mockito.mock(MixedOperation.class);
103104
NonNamespaceOperation<Secret, SecretList, Resource<Secret>> mockedOperation = Mockito
104105
.mock(NonNamespaceOperation.class);
@@ -189,8 +190,8 @@ ConfigReloadProperties configReloadProperties() {
189190
@Bean
190191
@Primary
191192
SecretsConfigProperties secretsConfigProperties() {
192-
return new SecretsConfigProperties(true, Map.of(), List.of(), List.of(), true, SECRET_NAME, NAMESPACE,
193-
true, true, FAIL_FAST, RetryProperties.DEFAULT);
193+
return new SecretsConfigProperties(true, Map.of(), List.of(), List.of(), true, SECRET_NAME, NAMESPACE, true,
194+
true, FAIL_FAST, RetryProperties.DEFAULT);
194195
}
195196

196197
@Bean

0 commit comments

Comments
 (0)