From 275821c1916493419af79a8160726855bd7a674b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Henning?= <soeren.henning@email.uni-kiel.de> Date: Tue, 15 Mar 2022 16:05:29 +0100 Subject: [PATCH] Minor code quality improvements --- .../theodolite/execution/operator/LeaderElector.kt | 12 ++++++------ .../execution/operator/TheodoliteOperator.kt | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/LeaderElector.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/LeaderElector.kt index 1ce94c2fd..558d06ce0 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/LeaderElector.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/LeaderElector.kt @@ -18,22 +18,22 @@ class LeaderElector( ) { // TODO(what is the name of the lock? .withName() or LeaseLock(..,name..) ?) - fun getLeadership(leader: KFunction0<Unit>) { + fun getLeadership(leader: () -> Unit) { val lockIdentity: String = UUID.randomUUID().toString() DefaultKubernetesClient().use { kc -> kc.leaderElector() .withConfig( LeaderElectionConfigBuilder() .withName("Theodolite") - .withLeaseDuration(Duration.ofSeconds(15L)) + .withLeaseDuration(Duration.ofSeconds(15)) .withLock(LeaseLock(client.namespace, name, lockIdentity)) - .withRenewDeadline(Duration.ofSeconds(10L)) - .withRetryPeriod(Duration.ofSeconds(2L)) + .withRenewDeadline(Duration.ofSeconds(10)) + .withRetryPeriod(Duration.ofSeconds(2)) .withLeaderCallbacks(LeaderCallbacks( { Thread { leader() }.start() }, - { logger.info { "STOPPED LEADERSHIP" } } + { logger.info { "Stop being the leading operator." } } ) { newLeader: String? -> - logger.info { "New leader elected $newLeader" } + logger.info { "New leader elected: $newLeader" } }) .build() ) diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt index 071bd0607..ada30ec94 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt @@ -41,15 +41,14 @@ class TheodoliteOperator { LeaderElector( client = client, name = Configuration.COMPONENT_NAME - ) - .getLeadership(::startOperator) + ).getLeadership(::startOperator) } /** * Start the operator. */ private fun startOperator() { - logger.info { "Using $namespace as namespace." } + logger.info { "Becoming the leading operator. Use namespace '$namespace'." } client.use { KubernetesDeserializer.registerCustomKind( "$GROUP/$API_VERSION", -- GitLab