Signed-off-by: wind57 <eugen.rabii@gmail.com>
This commit is contained in:
wind57
2025-03-26 18:33:29 +02:00
parent 1e70cab4e3
commit 074404cd60
8 changed files with 17 additions and 10 deletions

View File

@@ -21,13 +21,14 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiConsumer;
@@ -103,6 +104,7 @@ public abstract class SecretsPropertySourceLocator implements PropertySourceLoca
}
cache.discardAll();
System.out.println("composite : " + Arrays.toString(composite.getPropertyNames()));
return composite;
}
return null;
@@ -141,7 +143,8 @@ public abstract class SecretsPropertySourceLocator implements PropertySourceLoca
LOG.warn("Error walking properties files", e);
return null;
}
}).filter(Objects::nonNull)
})
.filter(Objects::nonNull)
.filter(Files::isRegularFile)
.collect(new SecretsPropertySourceCollector())
.forEach(composite::addPropertySource);
@@ -192,8 +195,9 @@ public abstract class SecretsPropertySourceLocator implements PropertySourceLoca
try {
String content = new String(Files.readAllBytes(filePath)).trim();
System.out.println("content is : " + content);
String sourceName = fileName.toLowerCase(Locale.ROOT);
SourceData sourceData = new SourceData(sourceName, Collections.singletonMap(fileName, content));
SourceData sourceData = new SourceData(sourceName, Map.of(fileName, content));
return new SecretsPropertySource(sourceData);
}
catch (IOException e) {

View File

@@ -25,7 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
*/
@SpringBootApplication
@EnableConfigurationProperties({ LeftProperties.class, RightProperties.class, RightWithLabelsProperties.class,
ConfigMapProperties.class, SecretsProperties.class })
ConfigMapProperties.class, SecretProperties.class })
public class App {
public static void main(String[] args) {

View File

@@ -27,9 +27,9 @@ public class Controller {
private final ConfigMapProperties configMapProperties;
private final SecretsProperties secretsProperties;
private final SecretProperties secretsProperties;
public Controller(ConfigMapProperties configMapProperties, SecretsProperties secretsProperties) {
public Controller(ConfigMapProperties configMapProperties, SecretProperties secretsProperties) {
this.configMapProperties = configMapProperties;
this.secretsProperties = secretsProperties;
}

View File

@@ -22,7 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author wind57
*/
@ConfigurationProperties("from.properties.secret")
public class SecretsProperties {
public class SecretProperties {
private String key;

View File

@@ -9,4 +9,3 @@ spring:
mode: polling
period: 5000
monitoring-secrets: true

View File

@@ -4,3 +4,7 @@ spring:
secrets:
paths:
- /tmp/application.properties
enabled: true
config:
enabled: false

View File

@@ -116,9 +116,9 @@ abstract class K8sClientReloadBase {
protected static void manifestsSecret(Phase phase, Util util, String namespace, String imageName) {
V1Secret secret = (V1Secret) util.yaml("mount/secret.yaml");
V1Deployment deployment = (V1Deployment) util.yaml("mount/deployment-with-secret.yaml");
V1Service service = (V1Service) util.yaml("mount/service-with-secret.yaml");
V1Secret secret = (V1Secret) util.yaml("mount/secret.yaml");
if (phase.equals(Phase.CREATE)) {
util.createAndWait(namespace, null, secret);

View File

@@ -14,7 +14,7 @@ spec:
serviceAccountName: spring-cloud-kubernetes-serviceaccount
containers:
- name: spring-cloud-kubernetes-k8s-client-reload
image: docker.io/springcloud/spring-cloud-kubernetes-k8s-client-reload:1
image: docker.io/springcloud/spring-cloud-kubernetes-k8s-client-reload
imagePullPolicy: IfNotPresent
readinessProbe:
httpGet: