Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Nov 8, 2024
2 parents 9a32a97 + 19ee913 commit ac830a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,31 @@ 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()) {
LOG.debug(() -> "no existingSources found, reload will not happen");
return false;
}

List<? extends MapPropertySource> sourceFromK8s = locateMapPropertySources(locator, environment);

boolean changed = changed(sourceFromK8s, existingSources);
if (changed) {
LOG.info("Detected change in config maps/secrets");
Expand All @@ -67,7 +85,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)
public static <S extends PropertySource<?>> List<S> findPropertySources(Class<S> sourceClass,
ConfigurableEnvironment environment) {
List<S> managedSources = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
if (changedConfigMap) {
log.info("Detected change in config maps");
reloadProperties();
}
}

if (changedConfigMap) {
log.info("Detected change in config maps");
reloadProperties();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 secrets and fires a reload when something
* changes.
Expand Down Expand Up @@ -75,23 +70,13 @@ private void init() {
}

private void executeCycle() {

boolean changedSecrets = false;
if (monitorSecrets) {
log.debug("Polling for changes in secrets");
List<MapPropertySource> currentSecretSources = locateMapPropertySources(this.propertySourceLocator,
this.environment);
if (!currentSecretSources.isEmpty()) {
List<? extends MapPropertySource> propertySources = findPropertySources(propertySourceClass,
environment);
changedSecrets = changed(currentSecretSources, propertySources);
boolean changedSecrets = ConfigReloadUtil.reload(propertySourceLocator, environment, propertySourceClass);
if (changedSecrets) {
log.info("Detected change in secrets");
reloadProperties();
}
}

if (changedSecrets) {
log.info("Detected change in secrets");
reloadProperties();
}
}

}

0 comments on commit ac830a6

Please sign in to comment.