Skip to content

Commit b9f6bf7

Browse files
committed
merge main
Signed-off-by: wind57 <[email protected]>
2 parents dd48b37 + ef3e9c7 commit b9f6bf7

File tree

5 files changed

+60
-27
lines changed

5 files changed

+60
-27
lines changed

spring-cloud-kubernetes-fabric8-leader/pom.xml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@
2222
<artifactId>spring-boot-starter-actuator</artifactId>
2323
<optional>true</optional>
2424
</dependency>
25-
<dependency>
26-
<groupId>org.springframework.boot</groupId>
27-
<artifactId>spring-boot-configuration-processor</artifactId>
28-
<optional>true</optional>
29-
</dependency>
30-
<dependency>
31-
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-web</artifactId>
33-
<scope>test</scope>
34-
</dependency>
35-
<dependency>
36-
<groupId>org.springframework.boot</groupId>
37-
<artifactId>spring-boot-starter-webflux</artifactId>
38-
<scope>test</scope>
39-
</dependency>
40-
<dependency>
41-
<groupId>org.springframework.boot</groupId>
42-
<artifactId>spring-boot-starter-test</artifactId>
43-
<scope>test</scope>
44-
</dependency>
4525
<dependency>
4626
<groupId>org.springframework.cloud</groupId>
4727
<artifactId>spring-cloud-kubernetes-test-support</artifactId>

spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.Lock;
3131
import io.fabric8.kubernetes.client.readiness.Readiness;
3232

33+
import org.springframework.boot.actuate.autoconfigure.info.ConditionalOnEnabledInfoContributor;
3334
import org.springframework.boot.actuate.info.InfoContributor;
3435
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
3536
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -38,7 +39,6 @@
3839
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3940
import org.springframework.boot.cloud.CloudPlatform;
4041
import org.springframework.boot.context.properties.EnableConfigurationProperties;
41-
import org.springframework.boot.health.autoconfigure.contributor.ConditionalOnEnabledHealthIndicator;
4242
import org.springframework.cloud.kubernetes.commons.leader.election.ConditionalOnLeaderElectionEnabled;
4343
import org.springframework.cloud.kubernetes.commons.leader.election.LeaderElectionProperties;
4444
import org.springframework.context.annotation.Bean;
@@ -66,7 +66,7 @@ class Fabric8LeaderElectionAutoConfiguration {
6666

6767
@Bean
6868
@ConditionalOnClass(InfoContributor.class)
69-
@ConditionalOnEnabledHealthIndicator("leader.election")
69+
@ConditionalOnEnabledInfoContributor("leader.election")
7070
Fabric8LeaderElectionInfoContributor leaderElectionInfoContributor(String candidateIdentity,
7171
LeaderElectionConfig leaderElectionConfig, KubernetesClient fabric8KubernetesClient) {
7272
return new Fabric8LeaderElectionInfoContributor(candidateIdentity, leaderElectionConfig,

spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/FabricLeaderApp.java renamed to spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import org.springframework.boot.autoconfigure.SpringBootApplication;
2121

2222
@SpringBootApplication
23-
public class FabricLeaderApp {
23+
public class Fabric8LeaderApp {
2424

2525
public static void main(String[] args) {
26-
SpringApplication.run(FabricLeaderApp.class, args);
26+
SpringApplication.run(Fabric8LeaderApp.class, args);
2727
}
2828

2929
}

spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderAutoConfigurationTests.java

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.assertj.core.api.Assertions;
2222
import org.junit.jupiter.api.Test;
2323

24+
import org.springframework.boot.autoconfigure.AutoConfigurations;
2425
import org.springframework.boot.test.context.TestConfiguration;
2526
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
2627
import org.springframework.context.annotation.Bean;
@@ -87,8 +88,8 @@ void leaderElectionAnnotationPresentEqualToFalse() {
8788
*
8889
* As such:
8990
*
90-
* - Fabric8LeaderAutoConfiguration must not be picked up
91-
* - Fabric8LeaderElectionAutoConfiguration must be picked up
91+
* - Fabric8LeaderElectionAutoConfiguration is present
92+
* - Fabric8LeaderElectionCallbacksAutoConfiguration is present
9293
* </pre>
9394
*/
9495
@Test
@@ -105,6 +106,58 @@ void leaderElectionAnnotationPresentEqualToTrue() {
105106
});
106107
}
107108

109+
/**
110+
* <pre>
111+
* - spring.cloud.kubernetes.leader.election = true
112+
* - management.info.leader.election.enabled = true
113+
*
114+
* As such:
115+
*
116+
* - Fabric8LeaderElectionAutoConfiguration must be picked up
117+
* - Fabric8LeaderElectionInfoContributor must be picked up
118+
* </pre>
119+
*/
120+
@Test
121+
void leaderInfoContributorPresent() {
122+
new ApplicationContextRunner().withUserConfiguration(Fabric8LeaderApp.class)
123+
.withConfiguration(AutoConfigurations.of(Fabric8LeaderElectionAutoConfiguration.class,
124+
Fabric8LeaderElectionCallbacksAutoConfiguration.class))
125+
.withPropertyValues("spring.main.cloud-platform=kubernetes", "management.info.leader.election.enabled=true",
126+
"spring.cloud.kubernetes.leader.election.enabled=true")
127+
.withAllowBeanDefinitionOverriding(true)
128+
.run(context -> {
129+
Assertions.assertThat(context).hasSingleBean(Fabric8LeaderElectionAutoConfiguration.class);
130+
Assertions.assertThat(context).hasSingleBean(Fabric8LeaderElectionInfoContributor.class);
131+
});
132+
}
133+
134+
/**
135+
* <pre>
136+
* - spring.cloud.kubernetes.leader.election = true
137+
* - management.info.leader.election.enabled = false
138+
*
139+
* As such:
140+
*
141+
* - Fabric8LeaderAutoConfiguration must not be picked up
142+
* - Fabric8LeaderElectionAutoConfiguration must be picked up
143+
* - Fabric8LeaderElectionInfoContributor must not be picked up
144+
* </pre>
145+
*/
146+
@Test
147+
void leaderInfoContributorMissing() {
148+
new ApplicationContextRunner().withUserConfiguration(Fabric8LeaderApp.class)
149+
.withConfiguration(AutoConfigurations.of(Fabric8LeaderElectionAutoConfiguration.class,
150+
Fabric8LeaderElectionCallbacksAutoConfiguration.class))
151+
.withPropertyValues("spring.main.cloud-platform=kubernetes",
152+
"management.info.leader.election.enabled=false",
153+
"spring.cloud.kubernetes.leader.election.enabled=true")
154+
.withAllowBeanDefinitionOverriding(true)
155+
.run(context -> {
156+
Assertions.assertThat(context).hasSingleBean(Fabric8LeaderElectionAutoConfiguration.class);
157+
Assertions.assertThat(context).doesNotHaveBean(Fabric8LeaderElectionInfoContributor.class);
158+
});
159+
}
160+
108161
@TestConfiguration
109162
static class TestConfig {
110163

spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/election/Fabric8LeaderElectionInfoContributorIsNotLeaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
*/
5353
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
5454
properties = { "spring.main.cloud-platform=KUBERNETES", "management.endpoints.web.exposure.include=info",
55-
"management.endpoint.info.show-details=always", "management.info.kubernetes.enabled=true",
55+
"management.endpoint.info.show-details=always",
5656
"spring.cloud.kubernetes.leader.election.enabled=true" })
5757
@AutoConfigureWebTestClient
5858
class Fabric8LeaderElectionInfoContributorIsNotLeaderTest {

0 commit comments

Comments
 (0)