Skip to content
Snippets Groups Projects
Commit 830a4874 authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

delete file / clean up

parent 69b28381
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!142Rewrite operator to use k8s states,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
package theodolite.execution.operator
import io.fabric8.kubernetes.client.DefaultKubernetesClient
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderCallbacks
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectionConfigBuilder
import io.fabric8.kubernetes.client.extended.leaderelection.resourcelock.LeaseLock
import mu.KotlinLogging
import java.time.Duration
import java.util.*
import kotlin.reflect.KFunction0
import kotlin.reflect.KFunction1
private val logger = KotlinLogging.logger {}
class LeaderElector(
val client: NamespacedKubernetesClient,
val name: String
) {
fun getLeadership(leader: KFunction1<NamespacedKubernetesClient, Unit>) {
val lockIdentity: String = UUID.randomUUID().toString()
DefaultKubernetesClient().use { kc ->
kc.leaderElector()
.withConfig(
LeaderElectionConfigBuilder()
.withName("Theodolite")
.withLeaseDuration(Duration.ofSeconds(15L))
.withLock(LeaseLock(client.namespace, name, lockIdentity))
.withRenewDeadline(Duration.ofSeconds(10L))
.withRetryPeriod(Duration.ofSeconds(2L))
.withLeaderCallbacks(LeaderCallbacks(
leader,
{ logger.info { "STOPPED LEADERSHIP " } }
) { newLeader: String? ->
logger.info { "New leader elected $newLeader" }
})
.build()
)
.build().run()
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment