Skip to content

Commit a7e1184

Browse files
committed
review comments
Signed-off-by: wind57 <[email protected]>
1 parent fada846 commit a7e1184

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ management.info.leader.enabled=false
5353
5454
'''
5555
56-
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.
56+
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 JDK's "preview" features.
5757
5858
To be able to use it, you need to set the property:
5959
@@ -103,7 +103,7 @@ If the lock is not taken, current pod becomes the leader. It does so by insertin
103103
104104
Once a certain pod establishes itself as the leader (by acquiring the lock), it will continuously (every `spring.cloud.kubernetes.leader.election.retryPeriod`) try to renew its lease, or in other words: it will try to extend its leadership. When a renewal happens, the "record" that is stored inside the lock, is updated. For example, `renewTime` is updated inside the record, to denote when the last renewal happened. (You can always peek inside these fields by using `kubectl describe lease...` for example).
105105
106-
Renewal must happen within a certain interval, specified by `spring.cloud.kubernetes.leader.election.renewDeadline`. By default, it is equal to 10 seconds, and it means that the leader pod has a maximum of 10 seconds to renew its leadership. If that does not happen, this pod loses its leadership and leader election starts again. Because other pods try to become leaders every 2 seconds (by default), it could mean that the pod that just lost leadership, will become leader again. If you want other pods to have a higher chance of becoming leaders, you can set the property (specified in seconds, by default it is 0) :
106+
Renewal must happen within a certain interval, specified by `spring.cloud.kubernetes.leader.election.renewDeadline`. By default, it is equal to 10 seconds, and it means that the leader pod has a maximum of 10 seconds to renew its leadership. If that does not happen, this pod loses its leadership and leader election starts again. Because other pods try to become leaders every 2 seconds (by default), it could mean that the pod that just lost leadership, will become leader again. If you want other pods to have a higher chance of becoming leaders, you can set the property (specified in seconds, by default it is 3) :
107107
108108
[source]
109109
----
@@ -132,6 +132,11 @@ You might have to give proper RBAC to be able to use this functionality, for exa
132132
[source]
133133
----
134134
- apiGroups: [ "coordination.k8s.io" ]
135-
resources: [ "leases", "configmaps" ]
136-
verbs: [ "get", "update", "create", "patch"]
135+
resources: [ "leases" ]
136+
resourceNames: [ "spring-k8s-leader-election-lock" ]
137+
verbs: [ "get", "update", "create" ]
138+
- apiGroups: [ "" ]
139+
resources: [ "configmaps" ]
140+
resourceNames: [ "spring-k8s-leader-election-lock" ]
141+
verbs: [ "get", "update", "create" ]
137142
----

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21-
import java.io.UncheckedIOException;
2221
import java.net.InetAddress;
2322
import java.net.UnknownHostException;
2423
import java.nio.file.Files;
@@ -74,7 +73,7 @@ private LeaderUtils() {
7473
}
7574

7675
/**
77-
* ideally, should always be present. If not, downward api must enable this one.
76+
* Ideally, should always be present. If not, downward API must enable this one.
7877
*/
7978
public static Optional<String> podNamespace() {
8079
Path serviceAccountPath = new File(SERVICE_ACCOUNT_NAMESPACE_PATH).toPath();
@@ -87,7 +86,8 @@ public static Optional<String> podNamespace() {
8786
return Optional.of(namespace);
8887
}
8988
catch (IOException e) {
90-
throw new UncheckedIOException(e);
89+
LOG.error(e,
90+
() -> "error reading service account, will default to reading env variable : " + POD_NAMESPACE);
9191
}
9292

9393
}

0 commit comments

Comments
 (0)