-
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
Refactor reload (2) #1790
Refactor reload (2) #1790
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,13 +44,30 @@ private ConfigReloadUtil() { | |
|
||
private static final LogAccessor LOG = new LogAccessor(LogFactory.getLog(ConfigReloadUtil.class)); | ||
|
||
public static boolean reload(String target, String eventSourceType, PropertySourceLocator locator, | ||
/** | ||
* used for the event based reloading. | ||
*/ | ||
public static boolean reload(String target, String sourceAsString, PropertySourceLocator locator, | ||
ConfigurableEnvironment environment, Class<? extends MapPropertySource> existingSourcesType) { | ||
LOG.debug(() -> "onEvent " + target + ": " + eventSourceType); | ||
LOG.debug(() -> "onEvent " + target + ": " + sourceAsString); | ||
|
||
return reload(locator, environment, existingSourcesType); | ||
} | ||
|
||
/** | ||
* used for the poll based reloading. | ||
*/ | ||
public static boolean reload(PropertySourceLocator locator, ConfigurableEnvironment environment, | ||
Class<? extends MapPropertySource> existingSourcesType) { | ||
|
||
List<? extends MapPropertySource> sourceFromK8s = locateMapPropertySources(locator, environment); | ||
List<? extends MapPropertySource> existingSources = findPropertySources(existingSourcesType, environment); | ||
|
||
if (existingSources.isEmpty()) { | ||
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. I am adding this code:
This was actually already part of the polling code, but not from the event based one. So this aligns them. 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. this PR can only be created once you are OK with this one and it ends up in |
||
LOG.debug(() -> "no existingSources found, reload will not happen"); | ||
} | ||
|
||
List<? extends MapPropertySource> sourceFromK8s = locateMapPropertySources(locator, environment); | ||
|
||
boolean changed = changed(sourceFromK8s, existingSources); | ||
if (changed) { | ||
LOG.info("Detected change in config maps/secrets"); | ||
|
@@ -67,7 +84,9 @@ public static boolean reload(String target, String eventSourceType, PropertySour | |
* @param <S> property source type | ||
* @param sourceClass class for which property sources will be found | ||
* @return finds all registered property sources of the given type | ||
* @deprecated this method will not be public in the next major release. | ||
*/ | ||
@Deprecated(forRemoval = false) | ||
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. since this is public already, I can't make it package private, but I will create a PR that will make it such for the next major release |
||
public static <S extends PropertySource<?>> List<S> findPropertySources(Class<S> sourceClass, | ||
ConfigurableEnvironment environment) { | ||
List<S> managedSources = new ArrayList<>(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
package org.springframework.cloud.kubernetes.commons.config.reload; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import org.apache.commons.logging.Log; | ||
|
@@ -29,10 +28,6 @@ | |
import org.springframework.scheduling.TaskScheduler; | ||
import org.springframework.scheduling.support.PeriodicTrigger; | ||
|
||
import static org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadUtil.changed; | ||
import static org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadUtil.findPropertySources; | ||
import static org.springframework.cloud.kubernetes.commons.config.reload.ConfigReloadUtil.locateMapPropertySources; | ||
|
||
/** | ||
* A change detector that periodically retrieves configmaps and fire a reload when | ||
* something changes. | ||
|
@@ -75,23 +70,13 @@ private void init() { | |
} | ||
|
||
private void executeCycle() { | ||
|
||
boolean changedConfigMap = false; | ||
if (monitorConfigMaps) { | ||
log.debug("Polling for changes in config maps"); | ||
List<? extends MapPropertySource> currentConfigMapSources = findPropertySources(propertySourceClass, | ||
environment); | ||
|
||
if (!currentConfigMapSources.isEmpty()) { | ||
changedConfigMap = changed(locateMapPropertySources(this.propertySourceLocator, this.environment), | ||
currentConfigMapSources); | ||
boolean changedConfigMap = ConfigReloadUtil.reload(propertySourceLocator, environment, propertySourceClass); | ||
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. instead of calling : |
||
if (changedConfigMap) { | ||
log.info("Detected change in config maps"); | ||
reloadProperties(); | ||
} | ||
} | ||
|
||
if (changedConfigMap) { | ||
log.info("Detected change in config maps"); | ||
reloadProperties(); | ||
} | ||
} | ||
|
||
} |
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.
I want to achieve a very simple thing here : only two single "entry points" into this class. Only two public methods that both polling and event based reload should call, nothing else should be public. And they do exactly the same thing