Skip to content

Commit 3dca323

Browse files
author
Ryan Baxter
committed
Merge remote-tracking branch 'origin/1.0.x'
2 parents ccc8169 + f22175c commit 3dca323

File tree

29 files changed

+153
-106
lines changed

29 files changed

+153
-106
lines changed

spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/BootstrapConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ protected static class KubernetesPropertySourceConfiguration {
4949
private KubernetesClient client;
5050

5151
@Bean
52-
@ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled", matchIfMissing = true)
52+
@ConditionalOnProperty(name = "spring.cloud.kubernetes.config.enabled",
53+
matchIfMissing = true)
5354
public ConfigMapPropertySourceLocator configMapPropertySourceLocator(
5455
ConfigMapConfigProperties properties) {
5556
return new ConfigMapPropertySourceLocator(this.client, properties);
5657
}
5758

5859
@Bean
59-
@ConditionalOnProperty(name = "spring.cloud.kubernetes.secrets.enabled", matchIfMissing = true)
60+
@ConditionalOnProperty(name = "spring.cloud.kubernetes.secrets.enabled",
61+
matchIfMissing = true)
6062
public SecretsPropertySourceLocator secretsPropertySourceLocator(
6163
SecretsConfigProperties properties) {
6264
return new SecretsPropertySourceLocator(this.client, properties);

spring-cloud-kubernetes-config/src/main/java/org/springframework/cloud/kubernetes/config/reload/PollingConfigurationChangeDetector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public void init() {
6262
this.log.info("Kubernetes polling configuration change detector activated");
6363
}
6464

65-
@Scheduled(initialDelayString = "${spring.cloud.kubernetes.reload.period:15000}", fixedDelayString = "${spring.cloud.kubernetes.reload.period:15000}")
65+
@Scheduled(initialDelayString = "${spring.cloud.kubernetes.reload.period:15000}",
66+
fixedDelayString = "${spring.cloud.kubernetes.reload.period:15000}")
6667
public void executeCycle() {
6768

6869
boolean changedConfigMap = false;

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsFromFilePathsSpringBootTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@
3939
import static org.springframework.cloud.kubernetes.config.ConfigMapTestUtil.createFileWithContent;
4040

4141
@RunWith(SpringRunner.class)
42-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
43-
"spring.application.name=configmap-path-example",
44-
"spring.cloud.kubernetes.config.enableApi=false",
45-
"spring.cloud.kubernetes.config.paths="
46-
+ ConfigMapsFromFilePathsSpringBootTest.FIRST_FILE_NAME_FULL_PATH + ","
47-
+ ConfigMapsFromFilePathsSpringBootTest.SECOND_FILE_NAME_FULL_PATH })
42+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
43+
classes = App.class,
44+
properties = { "spring.application.name=configmap-path-example",
45+
"spring.cloud.kubernetes.config.enableApi=false",
46+
"spring.cloud.kubernetes.config.paths="
47+
+ ConfigMapsFromFilePathsSpringBootTest.FIRST_FILE_NAME_FULL_PATH
48+
+ ","
49+
+ ConfigMapsFromFilePathsSpringBootTest.SECOND_FILE_NAME_FULL_PATH })
4850
public class ConfigMapsFromFilePathsSpringBootTest {
4951

5052
protected static final String FILES_ROOT_PATH = "/tmp/scktests";

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsMixedSpringBootTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@
4141
import static org.springframework.cloud.kubernetes.config.ConfigMapTestUtil.readResourceFile;
4242

4343
@RunWith(SpringRunner.class)
44-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
45-
"spring.application.name=" + ConfigMapsMixedSpringBootTest.APPLICATION_NAME,
46-
"spring.cloud.kubernetes.config.enableApi=true",
47-
"spring.cloud.kubernetes.config.paths="
48-
+ ConfigMapsMixedSpringBootTest.FILE_NAME_FULL_PATH })
44+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
45+
classes = App.class,
46+
properties = {
47+
"spring.application.name="
48+
+ ConfigMapsMixedSpringBootTest.APPLICATION_NAME,
49+
"spring.cloud.kubernetes.config.enableApi=true",
50+
"spring.cloud.kubernetes.config.paths="
51+
+ ConfigMapsMixedSpringBootTest.FILE_NAME_FULL_PATH })
4952
public class ConfigMapsMixedSpringBootTest {
5053

5154
protected static final String FILES_ROOT_PATH = "/tmp/scktests";

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsSpringBootTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
* @author Charles Moulliard
4242
*/
4343
@RunWith(SpringRunner.class)
44-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
45-
"spring.application.name=configmap-example",
46-
"spring.cloud.kubernetes.reload.enabled=false" })
44+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
45+
classes = App.class, properties = { "spring.application.name=configmap-example",
46+
"spring.cloud.kubernetes.reload.enabled=false" })
4747
@AutoConfigureWebTestClient
4848
public class ConfigMapsSpringBootTest {
4949

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsWithProfileExpressionSpringBootTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
* Tests reading property from YAML document specified by profile expression.
4242
*/
4343
@RunWith(SpringRunner.class)
44-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
45-
"spring.application.name=configmap-with-profile-example",
46-
"spring.cloud.kubernetes.reload.enabled=false" })
44+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
45+
classes = App.class,
46+
properties = { "spring.application.name=configmap-with-profile-example",
47+
"spring.cloud.kubernetes.reload.enabled=false" })
4748
@ActiveProfiles({ "production", "us-east" })
4849
@AutoConfigureWebTestClient
4950
public class ConfigMapsWithProfileExpressionSpringBootTest {

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsWithProfilesNoActiveProfileSpringBootTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
* @author Charles Moulliard
4141
*/
4242
@RunWith(SpringRunner.class)
43-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
44-
"spring.application.name=configmap-with-profile-no-active-profiles-example",
45-
"spring.cloud.kubernetes.reload.enabled=false" })
43+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
44+
classes = App.class,
45+
properties = {
46+
"spring.application.name=configmap-with-profile-no-active-profiles-example",
47+
"spring.cloud.kubernetes.reload.enabled=false" })
4648
@AutoConfigureWebTestClient
4749
public class ConfigMapsWithProfilesNoActiveProfileSpringBootTest {
4850

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsWithProfilesSpringBootTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
* @author Charles Moulliard
4242
*/
4343
@RunWith(SpringRunner.class)
44-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
45-
"spring.application.name=configmap-with-profile-example",
46-
"spring.cloud.kubernetes.reload.enabled=false" })
44+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
45+
classes = App.class,
46+
properties = { "spring.application.name=configmap-with-profile-example",
47+
"spring.cloud.kubernetes.reload.enabled=false" })
4748
@ActiveProfiles("development")
4849
@AutoConfigureWebTestClient
4950
public class ConfigMapsWithProfilesSpringBootTest {

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/ConfigMapsWithoutProfilesSpringBootTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
import static org.springframework.cloud.kubernetes.config.ConfigMapTestUtil.readResourceFile;
3939

4040
@RunWith(SpringRunner.class)
41-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
42-
"spring.application.name=configmap-without-profile-example",
43-
"spring.cloud.kubernetes.reload.enabled=false" })
41+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
42+
classes = App.class,
43+
properties = { "spring.application.name=configmap-without-profile-example",
44+
"spring.cloud.kubernetes.reload.enabled=false" })
4445
@ActiveProfiles("development")
4546
@AutoConfigureWebTestClient
4647
public class ConfigMapsWithoutProfilesSpringBootTest {

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/CoreTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
import static org.assertj.core.api.Assertions.assertThat;
3737

3838
@RunWith(SpringRunner.class)
39-
@SpringBootTest(classes = TestApplication.class, properties = {
40-
"spring.application.name=testapp",
41-
"spring.cloud.kubernetes.client.namespace=testns",
42-
"spring.cloud.kubernetes.client.trustCerts=true",
43-
"spring.cloud.kubernetes.config.namespace=testns",
44-
"spring.cloud.kubernetes.secrets.enableApi=true" })
39+
@SpringBootTest(classes = TestApplication.class,
40+
properties = { "spring.application.name=testapp",
41+
"spring.cloud.kubernetes.client.namespace=testns",
42+
"spring.cloud.kubernetes.client.trustCerts=true",
43+
"spring.cloud.kubernetes.config.namespace=testns",
44+
"spring.cloud.kubernetes.secrets.enableApi=true" })
4545
public class CoreTest {
4646

4747
@ClassRule

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/HealthIndicatorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
import static org.hamcrest.Matchers.containsString;
3636

3737
@RunWith(SpringRunner.class)
38-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
39-
"management.endpoint.health.show-details=always" })
38+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
39+
classes = App.class,
40+
properties = { "management.endpoint.health.show-details=always" })
4041
public class HealthIndicatorTest {
4142

4243
@ClassRule

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/MultipleConfigMapsSpringBootTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
* @author Charles Moulliard
4040
*/
4141
@RunWith(SpringRunner.class)
42-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ExampleApp.class, properties = {
43-
"spring.cloud.bootstrap.name=multiplecms" })
42+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
43+
classes = ExampleApp.class,
44+
properties = { "spring.cloud.bootstrap.name=multiplecms" })
4445
@AutoConfigureWebTestClient
4546
public class MultipleConfigMapsSpringBootTest {
4647

spring-cloud-kubernetes-config/src/test/java/org/springframework/cloud/kubernetes/config/SecretsPropertySourceTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
import static org.assertj.core.api.Assertions.assertThat;
4040

4141
@RunWith(SpringRunner.class)
42-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
42+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
43+
classes = App.class)
4344
@TestPropertySource("classpath:/application-secrets.properties")
4445
public class SecretsPropertySourceTest {
4546

spring-cloud-kubernetes-core/src/test/java/org/springframework/cloud/kubernetes/HealthIndicatorTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535
import static org.hamcrest.Matchers.containsString;
3636

3737
@RunWith(SpringRunner.class)
38-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class, properties = {
39-
"management.endpoint.health.show-details=always" })
38+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
39+
classes = App.class,
40+
properties = { "management.endpoint.health.show-details=always" })
4041
public class HealthIndicatorTest {
4142

4243
@ClassRule

spring-cloud-kubernetes-core/src/test/java/org/springframework/cloud/kubernetes/InfoContributorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import static org.hamcrest.Matchers.containsString;
3636

3737
@RunWith(SpringRunner.class)
38-
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = App.class)
38+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
39+
classes = App.class)
3940
public class InfoContributorTest {
4041

4142
@ClassRule

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesCatalogWatch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
5858
this.publisher = publisher;
5959
}
6060

61-
@Scheduled(fixedDelayString = "${spring.cloud.kubernetes.discovery.catalogServicesWatchDelay:30000}")
61+
@Scheduled(
62+
fixedDelayString = "${spring.cloud.kubernetes.discovery.catalogServicesWatchDelay:30000}")
6263
public void catalogServicesWatch() {
6364
try {
6465
List<String> previousState = this.catalogEndpointsState.get();

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClientAutoConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public KubernetesClientServicesFunction servicesFunction(
5858

5959
@Bean
6060
@ConditionalOnMissingBean
61-
@ConditionalOnProperty(name = "spring.cloud.kubernetes.discovery.enabled", matchIfMissing = true)
61+
@ConditionalOnProperty(name = "spring.cloud.kubernetes.discovery.enabled",
62+
matchIfMissing = true)
6263
public KubernetesDiscoveryClient kubernetesDiscoveryClient(KubernetesClient client,
6364
KubernetesDiscoveryProperties properties,
6465
KubernetesClientServicesFunction kubernetesClientServicesFunction,
@@ -85,7 +86,9 @@ public KubernetesDiscoveryProperties getKubernetesDiscoveryProperties() {
8586

8687
@Bean
8788
@ConditionalOnMissingBean
88-
@ConditionalOnProperty(name = "spring.cloud.kubernetes.discovery.catalog-services-watch.enabled", matchIfMissing = true)
89+
@ConditionalOnProperty(
90+
name = "spring.cloud.kubernetes.discovery.catalog-services-watch.enabled",
91+
matchIfMissing = true)
8992
public KubernetesCatalogWatch kubernetesCatalogWatch(KubernetesClient client) {
9093
return new KubernetesCatalogWatch(client);
9194
}

spring-cloud-kubernetes-examples/kubernetes-leader-election-example/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ And finally, if the leadership is yielded or revoked for some reason, the old le
2727

2828
## Example application usage
2929

30-
To begin with, build and deploy the application:
30+
Leader election mechanism uses Kubernetes ConfigMap feature to coordinate leadership information.
31+
To access ConfigMap user needs correct role and role binding.
32+
Create them using the following commands:
33+
```
34+
kubectl apply -f leader-role.yml
35+
kubectl apply -f leader-rolebinding.yml
36+
```
37+
38+
Now build and deploy the application:
3139
```
32-
mvn clean package fabric8:deploy -Pkubernetes
40+
mvn clean fabric8:deploy -Pkubernetes
3341
```
3442

3543
This will deploy a single application instance to the cluster and that instance will automatically become a leader.
@@ -76,8 +84,4 @@ Thus, when trying to yield the leadership, request might go to a non-leader node
7684

7785
> Note: instances periodically try to acquire leadership and Spring Cloud Kubernetes doesn't decide which one of them is more worth to become one.
7886
Thus, it is possible that the instance which just yielded the leadership, made another leadership take over request faster than another instances and became a leader again.
79-
80-
## Access control notice
81-
82-
Leader election mechanism uses Kubernetes ConfigMap feature to coordinate leadership information.
83-
In order to access it, [Role](./src/main/fabric8/role.yaml) and [RoleBinding](./src/main/fabric8/rb.yaml) objects are defined.
87+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: leader
5+
labels:
6+
app: kubernetes-leader-election-example
7+
group: org.springframework.cloud
8+
rules:
9+
- apiGroups:
10+
- ""
11+
resources:
12+
- pods
13+
- configmaps
14+
verbs:
15+
- '*'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
labels:
5+
app: kubernetes-leader-election-example
6+
group: org.springframework.cloud
7+
name: leader
8+
roleRef:
9+
apiGroup: ""
10+
kind: Role
11+
name: leader
12+
subjects:
13+
- kind: ServiceAccount
14+
name: default
15+
apiGroup: ""

spring-cloud-kubernetes-examples/kubernetes-leader-election-example/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<groupId>org.springframework.boot</groupId>
3737
<artifactId>spring-boot-starter-web</artifactId>
3838
</dependency>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-actuator</artifactId>
42+
</dependency>
3943
<dependency>
4044
<groupId>org.springframework.cloud</groupId>
4145
<artifactId>spring-cloud-kubernetes-leader</artifactId>

spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/fabric8/rb.yaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

spring-cloud-kubernetes-examples/kubernetes-leader-election-example/src/main/fabric8/role.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

spring-cloud-kubernetes-leader/src/main/java/org/springframework/cloud/kubernetes/leader/LeaderAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
@Configuration
4242
@EnableConfigurationProperties(LeaderProperties.class)
4343
@ConditionalOnBean(KubernetesClient.class)
44-
@ConditionalOnProperty(value = "spring.cloud.kubernetes.leader.enabled", matchIfMissing = true)
44+
@ConditionalOnProperty(value = "spring.cloud.kubernetes.leader.enabled",
45+
matchIfMissing = true)
4546
public class LeaderAutoConfiguration {
4647

4748
@Bean

0 commit comments

Comments
 (0)