Skip to content

Commit fb15e40

Browse files
committed
minor changes before integration tests
Signed-off-by: wind57 <[email protected]>
1 parent 52108e5 commit fb15e40

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

docs/modules/ROOT/pages/leader-election.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ spring.cloud.kubernetes.leader.config-map-name=leader
2828

2929
'''
3030

31-
There is another way you can configure leader election, and it comes with native support in the fabric8 library. In the long run, this will be the default way to configure leader election, while the previous one will be dropped. You can treat this one much like the JDKs "preview" features.
31+
There is another way you can configure leader election, and it comes with native support in the fabric8 library (k8s native client support is not yet implemented). In the long run, this will be the default way to configure leader election, while the previous one will be dropped. You can treat this one much like the JDKs "preview" features.
3232

3333
To be able to use it, you need to set the property:
3434

@@ -72,7 +72,7 @@ Like with the old implementation, we will publish events by default, but this ca
7272
spring.cloud.kubernetes.leader.election.publishEvents=false
7373
----
7474

75-
There are a few parameters that control how the leader election process will happen. In order to explain them, we need to look at the high level implementation of this process. All the candidates (pods), try to become the leader, or they try to _acquire_ the lock. If the lock is already taken, they will continue to retry to acquire it every `spring.cloud.kubernetes.leader.election.retryPeriod` (value is specified as `java.time.Duration`, and by default it is 2 seconds).
75+
There are a few parameters that control how the leader election process will happen. To explain them, we need to look at the high-level implementation of this process. All the candidate pods try to become the leader, or they try to _acquire_ the lock. If the lock is already taken, they will continue to retry to acquire it every `spring.cloud.kubernetes.leader.election.retryPeriod` (value is specified as `java.time.Duration`, and by default it is 2 seconds).
7676

7777
If the lock is not taken, current pod becomes the leader. It does so by inserting a so-called "record" into the lock (`Lease` or `ConfigMap`). Among the things that the "record" contains, is the `leaseDuration` (that you can specify via `spring.cloud.kubernetes.leader.election.leaseDuration`; by default it is 15 seconds and is of type `java.time.Duration`). This acts like a TTL on the lock: no other candidate can acquire the lock, unless this period has expired (from the last renewal time).
7878

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
*/
3737
public final class LeaderUtils {
3838

39+
public static final String LEADER_ELECTION_PROPERTY_PREFIX = "spring.cloud.kubernetes.leader.election";
40+
41+
public static final String LEADER_ELECTION_ENABLED_PROPERTY = LEADER_ELECTION_PROPERTY_PREFIX + ".enabled";
42+
3943
private static final LogAccessor LOG = new LogAccessor(LeaderUtils.class);
4044

4145
// k8s environment variable responsible for host name

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/election/ConditionalOnLeaderElectionDisabled.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import static org.springframework.cloud.kubernetes.commons.leader.LeaderUtils.LEADER_ELECTION_ENABLED_PROPERTY;
27+
2628
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2729

2830
/**
@@ -35,8 +37,7 @@
3537
@Retention(RetentionPolicy.RUNTIME)
3638
@Documented
3739
@Inherited
38-
@ConditionalOnProperty(value = "spring.cloud.kubernetes.leader.election.enabled", matchIfMissing = true,
39-
havingValue = "false")
40+
@ConditionalOnProperty(value = LEADER_ELECTION_ENABLED_PROPERTY, matchIfMissing = true, havingValue = "false")
4041
public @interface ConditionalOnLeaderElectionDisabled {
4142

4243
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/election/ConditionalOnLeaderElectionEnabled.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.lang.annotation.RetentionPolicy;
2424
import java.lang.annotation.Target;
2525

26+
import static org.springframework.cloud.kubernetes.commons.leader.LeaderUtils.LEADER_ELECTION_ENABLED_PROPERTY;
27+
2628
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
2729

2830
/**
@@ -35,8 +37,7 @@
3537
@Retention(RetentionPolicy.RUNTIME)
3638
@Documented
3739
@Inherited
38-
@ConditionalOnProperty(value = "spring.cloud.kubernetes.leader.election.enabled", matchIfMissing = false,
39-
havingValue = "true")
40+
@ConditionalOnProperty(value = LEADER_ELECTION_ENABLED_PROPERTY, matchIfMissing = false, havingValue = "true")
4041
public @interface ConditionalOnLeaderElectionEnabled {
4142

4243
}

spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/election/LeaderElectionProperties.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import org.springframework.boot.context.properties.ConfigurationProperties;
2222
import org.springframework.boot.context.properties.bind.DefaultValue;
2323

24+
import static org.springframework.cloud.kubernetes.commons.leader.LeaderUtils.LEADER_ELECTION_PROPERTY_PREFIX;
25+
2426
/**
2527
* @author wind57
2628
*/
2729
// @formatter:off
28-
@ConfigurationProperties("spring.cloud.kubernetes.leader.election")
30+
@ConfigurationProperties(LEADER_ELECTION_PROPERTY_PREFIX)
2931
public record LeaderElectionProperties(
3032
@DefaultValue("true") boolean waitForPodReady,
3133
@DefaultValue("true") boolean publishEvents,

0 commit comments

Comments
 (0)