Skip to content

Commit 870360a

Browse files
committed
Merge branch '3.1.x' into 3.2.x
2 parents e308273 + 2b9709b commit 870360a

12 files changed

+710
-6
lines changed

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesConfigServerAutoConfiguration.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323

2424
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2525
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2627
import org.springframework.boot.autoconfigure.condition.ConditionalOnCloudPlatform;
28+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2729
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2830
import org.springframework.boot.cloud.CloudPlatform;
2931
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3032
import org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration;
31-
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
3233
import org.springframework.cloud.kubernetes.client.KubernetesClientAutoConfiguration;
3334
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigContext;
3435
import org.springframework.cloud.kubernetes.client.config.KubernetesClientConfigMapPropertySource;
@@ -59,11 +60,21 @@ public class KubernetesConfigServerAutoConfiguration {
5960

6061
@Bean
6162
@Profile("kubernetes")
62-
public EnvironmentRepository kubernetesEnvironmentRepository(CoreV1Api coreV1Api,
63+
@ConditionalOnMissingBean
64+
public KubernetesEnvironmentRepository kubernetesEnvironmentRepository(CoreV1Api coreV1Api,
6365
List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers,
64-
KubernetesNamespaceProvider kubernetesNamespaceProvider) {
66+
KubernetesNamespaceProvider kubernetesNamespaceProvider,
67+
KubernetesConfigServerProperties kubernetesConfigServerProperties) {
6568
return new KubernetesEnvironmentRepository(coreV1Api, kubernetesPropertySourceSuppliers,
66-
kubernetesNamespaceProvider.getNamespace());
69+
kubernetesNamespaceProvider.getNamespace(), kubernetesConfigServerProperties);
70+
}
71+
72+
@Bean
73+
@ConditionalOnBean(KubernetesEnvironmentRepository.class)
74+
@ConditionalOnMissingBean
75+
public KubernetesEnvironmentRepositoryFactory kubernetesEnvironmentRepositoryFactory(
76+
KubernetesEnvironmentRepository kubernetesEnvironmentRepository) {
77+
return new KubernetesEnvironmentRepositoryFactory(kubernetesEnvironmentRepository);
6778
}
6879

6980
@Bean

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesConfigServerProperties.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717
package org.springframework.cloud.kubernetes.configserver;
1818

1919
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.cloud.config.server.support.EnvironmentRepositoryProperties;
2021

2122
/**
2223
* @author Ryan Baxter
2324
*/
2425

2526
@ConfigurationProperties("spring.cloud.kubernetes.configserver")
26-
public class KubernetesConfigServerProperties {
27+
public class KubernetesConfigServerProperties implements EnvironmentRepositoryProperties {
28+
29+
private int order = DEFAULT_ORDER;
2730

2831
private String configMapNamespaces = "";
2932

@@ -45,4 +48,12 @@ public void setSecretsNamespaces(String secretsNamespaces) {
4548
this.secretsNamespaces = secretsNamespaces;
4649
}
4750

51+
public int getOrder() {
52+
return this.order;
53+
}
54+
55+
public void setOrder(int order) {
56+
this.order = order;
57+
}
58+
4859
}

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/main/java/org/springframework/cloud/kubernetes/configserver/KubernetesEnvironmentRepository.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.cloud.config.environment.Environment;
2929
import org.springframework.cloud.config.environment.PropertySource;
3030
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
31+
import org.springframework.core.Ordered;
3132
import org.springframework.core.env.MapPropertySource;
3233
import org.springframework.core.env.MutablePropertySources;
3334
import org.springframework.core.env.StandardEnvironment;
@@ -36,7 +37,7 @@
3637
/**
3738
* @author Ryan Baxter
3839
*/
39-
public class KubernetesEnvironmentRepository implements EnvironmentRepository {
40+
public class KubernetesEnvironmentRepository implements EnvironmentRepository, Ordered {
4041

4142
private static final Log LOG = LogFactory.getLog(KubernetesEnvironmentRepository.class);
4243

@@ -46,13 +47,25 @@ public class KubernetesEnvironmentRepository implements EnvironmentRepository {
4647

4748
private final String namespace;
4849

50+
private int order = KubernetesConfigServerProperties.DEFAULT_ORDER;
51+
52+
@Deprecated
4953
public KubernetesEnvironmentRepository(CoreV1Api coreApi,
5054
List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers, String namespace) {
5155
this.coreApi = coreApi;
5256
this.kubernetesPropertySourceSuppliers = kubernetesPropertySourceSuppliers;
5357
this.namespace = namespace;
5458
}
5559

60+
public KubernetesEnvironmentRepository(CoreV1Api coreApi,
61+
List<KubernetesPropertySourceSupplier> kubernetesPropertySourceSuppliers, String namespace,
62+
KubernetesConfigServerProperties properties) {
63+
this.coreApi = coreApi;
64+
this.kubernetesPropertySourceSuppliers = kubernetesPropertySourceSuppliers;
65+
this.namespace = namespace;
66+
this.order = properties.getOrder();
67+
}
68+
5669
@Override
5770
public Environment findOne(String application, String profile, String label) {
5871
return findOne(application, profile, label, true);
@@ -118,4 +131,13 @@ private void addApplicationConfiguration(Environment environment, StandardEnviro
118131
});
119132
}
120133

134+
@Override
135+
public int getOrder() {
136+
return this.order;
137+
}
138+
139+
public void setOrder(int order) {
140+
this.order = order;
141+
}
142+
121143
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2013-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.configserver;
18+
19+
import org.springframework.cloud.config.server.environment.EnvironmentRepositoryFactory;
20+
21+
/**
22+
* Factory class for creating instances of {@link KubernetesEnvironmentRepository}.
23+
*
24+
* @author Arjav Dongaonkar
25+
*/
26+
public class KubernetesEnvironmentRepositoryFactory
27+
implements EnvironmentRepositoryFactory<KubernetesEnvironmentRepository, KubernetesConfigServerProperties> {
28+
29+
private final KubernetesEnvironmentRepository kubernetesEnvironmentRepository;
30+
31+
public KubernetesEnvironmentRepositoryFactory(KubernetesEnvironmentRepository kubernetesEnvironmentRepository) {
32+
this.kubernetesEnvironmentRepository = kubernetesEnvironmentRepository;
33+
}
34+
35+
@Override
36+
public KubernetesEnvironmentRepository build(KubernetesConfigServerProperties environmentProperties) {
37+
return kubernetesEnvironmentRepository;
38+
}
39+
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.configserver;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.cloud.config.server.environment.JGitEnvironmentRepository;
24+
import org.springframework.context.ConfigurableApplicationContext;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
/**
29+
* @author Arjav Dongaonkar
30+
*/
31+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
32+
classes = { KubernetesConfigServerApplication.class },
33+
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes",
34+
"spring.cloud.kubernetes.client.namespace=default", "spring.profiles.active=composite",
35+
"spring.cloud.config.server.composite[0].type=git",
36+
"spring.cloud.config.server.composite[0].uri=https://github.com/spring-cloud-samples/config-repo",
37+
"spring.cloud.config.server.composite[1].type=kubernetes",
38+
"spring.cloud.config.server.composite[1].config-map-namespace=default",
39+
"spring.cloud.config.server.composite[1].secrets-namespace=default" })
40+
class CompositeProfileWithGitAndKubernetesConfigSourcesTests {
41+
42+
@Autowired
43+
private ConfigurableApplicationContext context;
44+
45+
@Test
46+
void runTest() {
47+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepository.class)).hasSize(2);
48+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepositoryFactory.class)).hasSize(1);
49+
assertThat(context.getBeanNamesForType(KubernetesPropertySourceSupplier.class)).isNotEmpty();
50+
assertThat(context.getBeanNamesForType(JGitEnvironmentRepository.class)).hasSize(1);
51+
}
52+
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.configserver;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.context.ConfigurableApplicationContext;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* @author Arjav Dongaonkar
29+
*/
30+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
31+
classes = { KubernetesConfigServerApplication.class },
32+
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes",
33+
"spring.cloud.kubernetes.client.namespace=default", "spring.profiles.active=composite",
34+
"spring.cloud.config.server.composite[0].type=kubernetes",
35+
"spring.cloud.config.server.composite[0].config-map-namespace=default",
36+
"spring.cloud.config.server.composite[0].secrets-namespace=default",
37+
"spring.cloud.config.server.composite[1].type=kubernetes",
38+
"spring.cloud.config.server.composite[1].config-map-namespace=another-namespace",
39+
"spring.cloud.config.server.composite[1].secrets-namespace=another-namespace" })
40+
class CompositeProfileWithMultipleKubernetesConfigSourcesTests {
41+
42+
@Autowired
43+
private ConfigurableApplicationContext context;
44+
45+
@Test
46+
void runTest() {
47+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepository.class)).hasSize(3);
48+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepositoryFactory.class)).hasSize(1);
49+
assertThat(context.getBeanNamesForType(KubernetesPropertySourceSupplier.class)).isNotEmpty();
50+
}
51+
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2013-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.kubernetes.configserver;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.boot.test.context.SpringBootTest;
23+
import org.springframework.context.ConfigurableApplicationContext;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* @author Arjav Dongaonkar
29+
*/
30+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
31+
classes = { KubernetesConfigServerApplication.class },
32+
properties = { "spring.main.cloud-platform=KUBERNETES", "spring.profiles.include=kubernetes",
33+
"spring.cloud.kubernetes.client.namespace=default", "spring.profiles.active=composite",
34+
"spring.cloud.config.server.composite[0].type=kubernetes",
35+
"spring.cloud.config.server.composite[0].config-map-namespace=default",
36+
"spring.cloud.config.server.composite[0].secrets-namespace=default" })
37+
class CompositeProfileWithOnlyKubernetesConfigSourceTests {
38+
39+
@Autowired
40+
private ConfigurableApplicationContext context;
41+
42+
@Test
43+
void runTest() {
44+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepository.class)).hasSize(2);
45+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepositoryFactory.class)).hasSize(1);
46+
assertThat(context.getBeanNamesForType(KubernetesPropertySourceSupplier.class)).isNotEmpty();
47+
}
48+
49+
}

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/test/java/org/springframework/cloud/kubernetes/configserver/ConfigServerAutoConfigurationKubernetesDisabledTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ConfigServerAutoConfigurationKubernetesDisabledTests {
3838
@Test
3939
void runTest() {
4040
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepository.class)).hasSize(0);
41+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepositoryFactory.class)).hasSize(0);
4142
}
4243

4344
}

spring-cloud-kubernetes-controllers/spring-cloud-kubernetes-configserver/src/test/java/org/springframework/cloud/kubernetes/configserver/ConfigServerAutoConfigurationKubernetesEnabledProfileIncludedConfigApiDisabledTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ConfigServerAutoConfigurationKubernetesEnabledProfileIncludedConfigApiDisa
4040
void runTest() {
4141
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepository.class)).hasSize(1);
4242
assertThat(context.getBeanNamesForType(KubernetesPropertySourceSupplier.class)).hasSize(0);
43+
assertThat(context.getBeanNamesForType(KubernetesEnvironmentRepositoryFactory.class)).hasSize(1);
4344
}
4445

4546
}

0 commit comments

Comments
 (0)