Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wind57 committed May 1, 2024
2 parents 2ddaca9 + 353dfe7 commit 8ee9390
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected Leader extractLeader(Map<String, String> data) {

String leaderKey = getLeaderKey();
String leaderId = data.get(leaderKey);
LOGGER.debug(() -> "retrieved leaderId: " + leaderId + " from leaderKey : " + leaderId);
if (!StringUtils.hasText(leaderId)) {
return null;
}
Expand Down Expand Up @@ -112,7 +113,7 @@ else if (newLeader != null && newLeader.isCandidate(candidate)) {
}

protected void notifyOnGranted() {
LOGGER.debug(() -> "Leadership has been granted for :" + candidate);
LOGGER.debug(() -> "Leadership has been granted to : " + candidate);

Context context = new LeaderContext(candidate, this);
leaderEventPublisher.publishOnGranted(this, context, candidate.getRole());
Expand All @@ -126,7 +127,7 @@ protected void notifyOnGranted() {
}

protected void notifyOnRevoked() {
LOGGER.debug(() -> "Leadership has been revoked for :" + candidate);
LOGGER.debug(() -> "Leadership has been revoked from :" + candidate);

Context context = new LeaderContext(candidate, this);
leaderEventPublisher.publishOnRevoked(this, context, candidate.getRole());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void start() {
public void stop() {
if (configMapWatch != null) {
guarded(lock, () -> {
if (this.configMapWatch != null) {
if (configMapWatch != null) {
LOGGER.debug(() -> "Stopping leader record watcher");
configMapWatch.close();
configMapWatch = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void revoke() {
}

private void revoke(ConfigMap configMap) {
LOGGER.debug(() -> "Trying to revoke leadership for :" + candidate);
LOGGER.debug(() -> "Trying to revoke leadership from :" + candidate);

try {
String leaderKey = getLeaderKey();
Expand All @@ -105,7 +105,7 @@ private void revoke(ConfigMap configMap) {
}

private void acquire(ConfigMap configMap) {
LOGGER.debug(() -> "Trying to acquire leadership for :" + this.candidate);
LOGGER.debug(() -> "Trying to acquire leadership for :" + candidate);

if (!isPodReady(candidate.getId())) {
LOGGER.debug("Pod : " + candidate + "is not ready at the moment, cannot acquire leadership");
Expand Down Expand Up @@ -133,7 +133,7 @@ private void acquire(ConfigMap configMap) {

@Override
protected PodReadinessWatcher createPodReadinessWatcher(String localLeaderId) {
return new Fabric8PodReadinessWatcher(localLeaderId, this.kubernetesClient, this);
return new Fabric8PodReadinessWatcher(localLeaderId, kubernetesClient, this);
}

private Leader extractLeader(ConfigMap configMap) {
Expand Down Expand Up @@ -176,8 +176,9 @@ private void removeConfigMapEntry(ConfigMap configMap, String key) {
}

private void updateConfigMap(ConfigMap oldConfigMap, ConfigMap newConfigMap) {
String oldResourceVersion = oldConfigMap.getMetadata().getResourceVersion();
kubernetesClient.configMaps().inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace()))
.resource(newConfigMap).lockResourceVersion(oldConfigMap.getMetadata().getResourceVersion()).update();
.resource(newConfigMap).lockResourceVersion(oldResourceVersion).update();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void whenNonExistentConfigmapAndCreationNotAllowedStopLeadershipAcquire(Captured
fabric8LeadershipController.update();

// then
assertThat(output).contains("ConfigMap 'test-configmap' does not exist and leaderProperties.isCreateConfigMap() is false, cannot acquire leadership");
assertThat(output).contains(
"ConfigMap 'test-configmap' does not exist and leaderProperties.isCreateConfigMap() is false, cannot acquire leadership");
verify(mockLeaderEventPublisher).publishOnFailedToAcquire(any(), any(), any());

verify(mockKubernetesClient, never()).pods();
Expand Down

0 comments on commit 8ee9390

Please sign in to comment.