Skip to content

Commit

Permalink
fix config missing when using both configmap and secret
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLiu1123 committed Feb 3, 2023
1 parent 03a30bb commit 9706561
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ public String toString() {

@Override
public void afterPropertiesSet() {
this.merge();
}

/**
* Merge the default properties value to the ConfigMaps and Secrets.
*/
public void merge() {
mergeConfigmaps();
mergeSecrets();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.cloud.endpoint.event.RefreshEvent;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
Expand Down Expand Up @@ -82,23 +81,10 @@ public void postProcessEnvironment(ConfigurableEnvironment environment,
KubernetesConfigProperties properties = getKubernetesConfigProperties(
environment);

if (isRefreshing()) {
RefreshEvent event = RefreshContext.get().refreshEvent();
Object resource = event.getSource();
if (resource instanceof ConfigMap) {
pullConfigMaps(properties, environment);
}
else if (resource instanceof Secret) {
pullSecrets(properties, environment);
}
else {
log.warn("Refreshed a unknown resource type: " + resource.getClass());
}
}
else {
pullConfigMaps(properties, environment);
pullSecrets(properties, environment);
}
// NOTE: current environment is brand new, we can't just refresh a single
// resource, all resources must be re-pulled!
pullConfigMaps(properties, environment);
pullSecrets(properties, environment);
}

private static KubernetesConfigProperties getKubernetesConfigProperties(
Expand All @@ -111,7 +97,7 @@ private static KubernetesConfigProperties getKubernetesConfigProperties(
.bind(KubernetesConfigProperties.PREFIX,
KubernetesConfigProperties.class)
.orElseGet(KubernetesConfigProperties::new);
prop.afterPropertiesSet();
prop.merge();
return prop;
});
}
Expand Down Expand Up @@ -192,7 +178,7 @@ private EnumerablePropertySource<?> propertySourceForConfigMap(

private static AbstractKubernetesConfigException kubernetesConfigException(
Class<?> type, String name, String namespace, KubernetesClientException e) {
// Usually the Service Account or user does not have enough privileges.
// Usually the ServiceAccount or user does not have enough privileges.
if (e.getCode() == HttpURLConnection.HTTP_FORBIDDEN) {
return new KubernetesForbiddenException(type, name, namespace, e);
}
Expand Down

0 comments on commit 9706561

Please sign in to comment.