Fabric leader clean up 9 (#1651)

This commit is contained in:
erabii
2024-05-01 15:36:46 +03:00
committed by GitHub
parent 65f5109864
commit 353dfe7eb4
4 changed files with 11 additions and 8 deletions

View File

@@ -83,6 +83,7 @@ public abstract class LeadershipController {
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 @@ public abstract class LeadershipController {
}
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 @@ public abstract class LeadershipController {
}
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());

View File

@@ -70,7 +70,7 @@ public class Fabric8LeaderRecordWatcher implements LeaderRecordWatcher, Watcher<
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;

View File

@@ -92,7 +92,7 @@ public class Fabric8LeadershipController extends LeadershipController {
}
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 @@ public class Fabric8LeadershipController extends LeadershipController {
}
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 @@ public class Fabric8LeadershipController extends LeadershipController {
@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 @@ public class Fabric8LeadershipController extends LeadershipController {
}
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();
}
}

View File

@@ -94,7 +94,8 @@ public class Fabric8LeadershipControllerTest {
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();