diff --git a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java index b7f30b6aea..ced9e3ad2c 100644 --- a/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java +++ b/spring-cloud-kubernetes-commons/src/main/java/org/springframework/cloud/kubernetes/commons/leader/LeadershipController.java @@ -83,6 +83,7 @@ protected Leader extractLeader(Map data) { String leaderKey = getLeaderKey(); String leaderId = data.get(leaderKey); + LOGGER.debug(() -> "retrieved leaderId: " + leaderId + " from leaderKey : " + leaderId); if (!StringUtils.hasText(leaderId)) { return null; } @@ -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()); @@ -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()); diff --git a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeaderRecordWatcher.java b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeaderRecordWatcher.java index 0900c6253e..c65fea0608 100644 --- a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeaderRecordWatcher.java +++ b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeaderRecordWatcher.java @@ -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; diff --git a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java index 8ae555218f..f6aadc4706 100644 --- a/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java +++ b/spring-cloud-kubernetes-fabric8-leader/src/main/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipController.java @@ -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(); @@ -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"); @@ -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) { @@ -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(); } } diff --git a/spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipControllerTest.java b/spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipControllerTest.java index 5347f71eec..424e789a12 100644 --- a/spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipControllerTest.java +++ b/spring-cloud-kubernetes-fabric8-leader/src/test/java/org/springframework/cloud/kubernetes/fabric8/leader/Fabric8LeadershipControllerTest.java @@ -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();