Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • she/theodolite
1 result
Show changes
Commits on Source (7)
......@@ -68,6 +68,18 @@ class TheodoliteExecutor(
afterTeardownDelay = config.execution.afterTeardownDelay
)
if (config.load.loadValues != config.load.loadValues.sorted()) {
config.load.loadValues = config.load.loadValues.sorted()
logger.info { "Load values are not sorted correctly, Theodolite sorts them in ascending order." +
"New order is: ${config.load.loadValues}" }
}
if (config.resources.resourceValues != config.resources.resourceValues.sorted()) {
config.resources.resourceValues = config.resources.resourceValues.sorted()
logger.info { "Load values are not sorted correctly, Theodolite sorts them in ascending order." +
"New order is: ${config.resources.resourceValues}" }
}
return Config(
loads = config.load.loadValues.map { load -> LoadDimension(load, loadDimensionPatcherDefinition) },
resources = config.resources.resourceValues.map { resource ->
......
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
private val logger = KotlinLogging.logger {}
class LeaderElector(
val client: NamespacedKubernetesClient,
val name: String
) {
fun getLeadership(leader: KFunction0<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(
{ Thread{leader()}.start() },
{ logger.info { "STOPPED LEADERSHIP" } }
) { newLeader: String? ->
logger.info { "New leader elected $newLeader" }
})
.build()
)
.build().run()
}
}
}
\ No newline at end of file
package theodolite.execution.operator
import io.fabric8.kubernetes.client.DefaultKubernetesClient
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.dsl.MixedOperation
import io.fabric8.kubernetes.client.dsl.Resource
import io.fabric8.kubernetes.internal.KubernetesDeserializer
......@@ -27,14 +28,22 @@ private val logger = KotlinLogging.logger {}
*/
class TheodoliteOperator {
private val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
val client: NamespacedKubernetesClient = DefaultKubernetesClient().inNamespace(namespace)
fun start() {
LeaderElector(
client = client,
name = "theodolite-operator"
)
.getLeadership(::startOperator)
}
/**
* Start the operator.
*/
fun start() {
// FIXME("Remove all benchmark state handling")
private fun startOperator() {
logger.info { "Using $namespace as namespace." }
val client = DefaultKubernetesClient().inNamespace(namespace)
client.use {
KubernetesDeserializer.registerCustomKind(
"$GROUP/$API_VERSION",
......
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
import theodolite.util.DeploymentFailedException
import theodolite.util.PatcherDefinition
/**
......@@ -27,7 +28,9 @@ class PatcherFactory {
k8sResources: List<Pair<String, KubernetesResource>>
): Patcher {
val resource =
k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }[0]
k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }.firstOrNull()
?: throw DeploymentFailedException("Could not find resource ${patcherDefinition.resource}")
return when (patcherDefinition.type) {
"ReplicaPatcher" -> ReplicaPatcher(resource)
"NumNestedGroupsLoadGeneratorReplicaPatcher" -> NumNestedGroupsLoadGeneratorReplicaPatcher(resource)
......
package theodolite.util
class DeploymentFailedException(message:String): Exception(message) {
}
\ No newline at end of file