-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reload functionality clean-up part 4 #1036
Merged
ryanjbaxter
merged 36 commits into
spring-cloud:main
from
wind57:reload-simplify-configs-part-4
Jul 7, 2022
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
bf7b971
first
wind57 cf4fca4
more changes
wind57 0ace7cd
fix test
wind57 923895f
fix test
wind57 6379ed9
make both final
wind57 ad85d11
first
wind57 c99f760
more clean-up
wind57 36e1bae
some simplifications
wind57 e3725f5
same logging
wind57 9face5a
Merge branch 'reload-conditionals-nitpick' into reload-conditionals-n…
wind57 1eefcb9
more clean-up, still I am in the blur a little
wind57 f60830a
clean-up
wind57 9f953ab
clean-up part 4
wind57 d148d2f
configmap polling test added
wind57 2a5da4c
informers + tests
wind57 940efcc
k8s native changes + tests
wind57 eba2c9f
fix tests
wind57 af8dc00
fix tests take 2
wind57 d7164dc
fix tests take 3
wind57 66b1e6a
fix tests take 4
wind57 4f08bed
merge previous
wind57 db6043c
fix test
wind57 623bac6
merge main
wind57 587a2cc
Merge branch 'reload-conditionals-nitpick-2' into reload-simplify-con…
wind57 f5487ae
merge previous
wind57 c648adf
dirty
wind57 63d34d9
started merging
wind57 69af4b1
fabric8 polish
wind57 83a60be
license
wind57 8410306
log added
wind57 8f919c9
inform
wind57 61507aa
informers commented
wind57 4a47895
k8s native
wind57 7886338
more
wind57 eaf5938
2 minutes
wind57 0ffbb3d
give more time
wind57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,9 @@ | |
import io.kubernetes.client.util.CallGeneratorParams; | ||
import jakarta.annotation.PostConstruct; | ||
import jakarta.annotation.PreDestroy; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource; | ||
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySourceLocator; | ||
import org.springframework.cloud.kubernetes.commons.KubernetesClientProperties; | ||
import org.springframework.cloud.kubernetes.commons.KubernetesNamespaceProvider; | ||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadProperties; | ||
import org.springframework.cloud.kubernetes.commons.config.reload.ConfigurationChangeDetector; | ||
|
@@ -44,17 +41,15 @@ | |
*/ | ||
public class KubernetesClientEventBasedConfigMapChangeDetector extends ConfigurationChangeDetector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some minor cleanups in this class |
||
|
||
private static final Log LOG = LogFactory.getLog(KubernetesClientEventBasedConfigMapChangeDetector.class); | ||
|
||
private CoreV1Api coreV1Api = null; | ||
private final CoreV1Api coreV1Api; | ||
|
||
private final KubernetesClientConfigMapPropertySourceLocator propertySourceLocator; | ||
|
||
private final SharedInformerFactory factory; | ||
|
||
private KubernetesClientProperties kubernetesClientProperties; | ||
private final String namespace; | ||
|
||
private KubernetesNamespaceProvider kubernetesNamespaceProvider; | ||
private final boolean monitorConfigMaps; | ||
|
||
public KubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api, ConfigurableEnvironment environment, | ||
ConfigReloadProperties properties, ConfigurationUpdateStrategy strategy, | ||
|
@@ -71,38 +66,33 @@ public KubernetesClientEventBasedConfigMapChangeDetector(CoreV1Api coreV1Api, Co | |
// certificate authorities for the cluster. This results in SSL errors. | ||
// See https://github.com/spring-cloud/spring-cloud-kubernetes/issues/885 | ||
this.factory = new SharedInformerFactory(createApiClientForInformerClient()); | ||
this.kubernetesNamespaceProvider = kubernetesNamespaceProvider; | ||
} | ||
|
||
private String getNamespace() { | ||
return kubernetesNamespaceProvider != null ? kubernetesNamespaceProvider.getNamespace() | ||
: kubernetesClientProperties.getNamespace(); | ||
this.namespace = kubernetesNamespaceProvider.getNamespace(); | ||
this.monitorConfigMaps = properties.isMonitoringConfigMaps(); | ||
} | ||
|
||
@PostConstruct | ||
public void watch() { | ||
if (coreV1Api != null && this.properties.isMonitoringConfigMaps()) { | ||
if (coreV1Api != null && monitorConfigMaps) { | ||
SharedIndexInformer<V1ConfigMap> configMapInformer = factory.sharedIndexInformerFor( | ||
(CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(getNamespace(), null, null, | ||
null, null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, | ||
null), | ||
(CallGeneratorParams params) -> coreV1Api.listNamespacedConfigMapCall(namespace, null, null, null, | ||
null, null, null, params.resourceVersion, null, params.timeoutSeconds, params.watch, null), | ||
V1ConfigMap.class, V1ConfigMapList.class); | ||
configMapInformer.addEventHandler(new ResourceEventHandler<V1ConfigMap>() { | ||
configMapInformer.addEventHandler(new ResourceEventHandler<>() { | ||
@Override | ||
public void onAdd(V1ConfigMap obj) { | ||
LOG.info("CongifMap " + obj.getMetadata().getName() + " was added."); | ||
log.info("ConfigMap " + obj.getMetadata().getName() + " was added."); | ||
onEvent(obj); | ||
} | ||
|
||
@Override | ||
public void onUpdate(V1ConfigMap oldObj, V1ConfigMap newObj) { | ||
LOG.info("ConfigMap " + newObj.getMetadata().getName() + " was added."); | ||
log.info("ConfigMap " + newObj.getMetadata().getName() + " was added."); | ||
onEvent(newObj); | ||
} | ||
|
||
@Override | ||
public void onDelete(V1ConfigMap obj, boolean deletedFinalStateUnknown) { | ||
LOG.info("ConfigMap " + obj.getMetadata() + " was deleted."); | ||
log.info("ConfigMap " + obj.getMetadata() + " was deleted."); | ||
onEvent(obj); | ||
} | ||
}); | ||
|
@@ -116,15 +106,15 @@ public void unwatch() { | |
} | ||
|
||
private void onEvent(V1ConfigMap configMap) { | ||
this.log.debug(String.format("onEvent configMap: %s", configMap.toString())); | ||
log.debug("onEvent configMap: " + configMap.toString()); | ||
boolean changed = changed(locateMapPropertySources(this.propertySourceLocator, this.environment), | ||
findPropertySources(KubernetesClientConfigMapPropertySource.class)); | ||
if (changed) { | ||
LOG.info("Configuration change detected, reloading properties."); | ||
log.info("Configuration change detected, reloading properties."); | ||
reloadProperties(); | ||
} | ||
else { | ||
LOG.warn("Configuration change was not detected."); | ||
log.warn("Configuration change was not detected."); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same simplification has been done in fabric8 - drop the inner class, move annotations