diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index 25535e1a64db9641cd47747cf8676b3994964690..7510fd82127edfe1925d51dee756d6112d045946 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -1,9 +1,12 @@ package theodolite.benchmark +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import io.fabric8.kubernetes.api.model.KubernetesResource +import io.fabric8.kubernetes.client.CustomResource import theodolite.util.ConfigurationOverride import kotlin.properties.Delegates -class BenchmarkExecution { +class BenchmarkExecution : CustomResource(){ lateinit var name: String lateinit var benchmark: String lateinit var load: LoadDefinition @@ -12,14 +15,16 @@ class BenchmarkExecution { lateinit var execution: Execution lateinit var configOverrides: List<ConfigurationOverride> - class Execution { + @JsonDeserialize + class Execution : KubernetesResource { lateinit var strategy: String var duration by Delegates.notNull<Long>() var repetitions by Delegates.notNull<Int>() lateinit var restrictions: List<String> } - class Slo { + @JsonDeserialize + class Slo : KubernetesResource{ lateinit var sloType: String var threshold by Delegates.notNull<Int>() lateinit var prometheusUrl: String @@ -28,12 +33,14 @@ class BenchmarkExecution { var warmup by Delegates.notNull<Int>() } - class LoadDefinition { + @JsonDeserialize + class LoadDefinition : KubernetesResource{ lateinit var loadType: String lateinit var loadValues: List<Int> } - class ResourceDefinition { + @JsonDeserialize + class ResourceDefinition : KubernetesResource{ lateinit var resourceType: String lateinit var resourceValues: List<Int> } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecutionList.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecutionList.kt new file mode 100644 index 0000000000000000000000000000000000000000..74ba733d703b2242e16b22aab7d4537a6f5bd88e --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecutionList.kt @@ -0,0 +1,6 @@ +package theodolite.benchmark + +import io.fabric8.kubernetes.client.CustomResourceList + +class BenchmarkExecutionList : CustomResourceList<BenchmarkExecution>() { +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/DonableTestResource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/DonableTestResource.kt new file mode 100644 index 0000000000000000000000000000000000000000..3c399a76b9deecd6b3a4aef7e04b02214321b3bf --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/DonableTestResource.kt @@ -0,0 +1,8 @@ +package theodolite.benchmark + + +import io.fabric8.kubernetes.client.CustomResourceDoneable +import io.fabric8.kubernetes.api.builder.Function + +class DonableTestResource(resource: TestResource, function: Function<TestResource,TestResource>) : + CustomResourceDoneable<TestResource>(resource, function) \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResource.kt new file mode 100644 index 0000000000000000000000000000000000000000..d28ac72592d2f3f1288dfbb04d1db8cd4823c479 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResource.kt @@ -0,0 +1,9 @@ +package theodolite.benchmark + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize +import io.fabric8.kubernetes.client.CustomResource + +@JsonDeserialize +data class TestResource(var name:String): CustomResource() { + +} \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResourceList.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResourceList.kt new file mode 100644 index 0000000000000000000000000000000000000000..043c2fcf9021d819220deb62c0a0fb9e9a6a49c7 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TestResourceList.kt @@ -0,0 +1,5 @@ +package theodolite.benchmark + +import io.fabric8.kubernetes.client.CustomResourceList + +class TestResourceList : CustomResourceList<TestResource> () \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteCRDExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteCRDExecutor.kt index 55b9765c51dd49772f8ad28a45213c7747a96994..5f79f65213e5f76920abc1e9f1c3ac0aebcefb6f 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteCRDExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteCRDExecutor.kt @@ -1,8 +1,13 @@ package theodolite.execution +import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder import io.fabric8.kubernetes.client.DefaultKubernetesClient +import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext +import io.fabric8.kubernetes.client.informers.ResourceEventHandler import io.quarkus.runtime.annotations.QuarkusMain import mu.KotlinLogging +import theodolite.benchmark.* +import theodolite.util.YamlParser import kotlin.system.exitProcess private var DEFAULT_NAMESPACE = "default" @@ -13,13 +18,57 @@ object TheodoliteCRDExecutor { @JvmStatic fun main(args: Array<String>) { - val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE - logger.info { "Using $namespace as namespace." } +// val namespace = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE +// logger.info { "Using $namespace as namespace." } - val client = DefaultKubernetesClient().inNamespace(namespace) + val client = DefaultKubernetesClient().inNamespace("default") - println("hello there") - exitProcess(0) +// val customResourceDefinition = CustomResourceDefinitionBuilder() +// .withNewMetadata().withName("benchmarkExecutions.demo.k8s.io").endMetadata() +// .withNewSpec() +// .withGroup("demo.k8s.io") +// .withVersion("v1alpha1") +// .withNewNames().withKind("BenchmarkExecution").withPlural("benchmarkExecutions").endNames() +// .withScope("Namespaced") +// .endSpec() +// .build() + + val context = CustomResourceDefinitionContext.Builder() + .withVersion("v1alpha1") + .withScope("Namespaced") + .withGroup("demo.k8s.io") + .withPlural("benchmarkexecutions") + .build() + + val informerFactory = client.informers() + + + val x = informerFactory.sharedIndexInformerForCustomResource(context, TestResource::class.java, + TestResourceList::class.java,10 * 60 * 1000.toLong()) + + + x.addEventHandler(object : ResourceEventHandler<TestResource> { + override fun onAdd(webServer: TestResource) { + println("hello there") + } + + override fun onUpdate(webServer: TestResource, newWebServer: TestResource) { + println("hello there") + } + + override fun onDelete(webServer: TestResource, b: Boolean) { + println("delted") + } + }) + + informerFactory.startAllRegisteredInformers() + + + + + //println(client.apiextensions().v1beta1().customResourceDefinitions().list()) + + //exitProcess(0) } } diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml index a91d123628a03bb7fd82821d6f34d7bf1239c154..6caff74a53059fd888c3a0cc790c6d3de99b9a89 100644 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml @@ -1,3 +1,7 @@ +apiVersion: demo.k8s.io/v1alpha1 +kind: Benchmarkexecutions +metadata: + name: example-webserver name: "Theodolite Test Context" benchmark: "benchmarkType" load: @@ -20,27 +24,4 @@ execution: duration: 60 repetitions: 1 restrictions: - - "LowerBound" -configOverrides: - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-load-generator-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-kstreams-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "cpu" - value: "1000m" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "memory" - value: "2Gi" \ No newline at end of file + - "LowerBound" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml index 6ad7993a1c914053d4543ff4f6289e0d11ba8ade..f7e0d1ec90d4b7e33fae5889823335ae63c20f51 100644 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecutionCRDShema.yaml @@ -1,51 +1,22 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: Theodolite-Test-Context + name: examples.theodolite.com spec: - name: string - benchmark: string - load: - loadType: string - loadValues: - - 50000 - resources: - resourceType: "Instances" - resourceValues: - - 1 - slos: - - sloType: "lag trend" - threshold: 1000 - prometheusUrl: "http://localhost:32656" - externalSloUrl: "http://localhost:80/evaluate-slope" - offset: 0 - warmup: 0 - execution: - strategy: "LinearSearch" - duration: 60 - repetitions: 1 - restrictions: - - "LowerBound" - configOverrides: - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-load-generator-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "NodeSelectorPatcher" - resource: "uc1-kstreams-deployment.yaml" - variableName: "env" - value: "prod" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "cpu" - value: "1000m" - - patcher: - type: "ResourceLimitPatcher" - resource: "uc1-kstreams-deployment.yaml" - container: "uc-application" - variableName: "memory" - value: "2Gi" \ No newline at end of file + group: theodolite.com + scope: Namespaced + versions: + - name: v1alpha1 + served: true + storage: true + schema: + openAPIV3Schema: + type: object + properties: + spec: + type : object + names: + kind: BenchmarkExecution + listKind: BenchmarkExecutionList + plural: examples + singular: example diff --git a/theodolite-quarkus/src/main/resources/yaml/testResource.yaml b/theodolite-quarkus/src/main/resources/yaml/testResource.yaml new file mode 100644 index 0000000000000000000000000000000000000000..81c3b2b96e26fb1d2fe21b174c3e9f2563556817 --- /dev/null +++ b/theodolite-quarkus/src/main/resources/yaml/testResource.yaml @@ -0,0 +1,5 @@ +apiVersion: demo.k8s.io/v1alpha1 +kind: Benchmarkexecutions +metadata: + name: example-webserver +name: "Theodolite Test Context" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/testcrd.yaml b/theodolite-quarkus/src/main/resources/yaml/testcrd.yaml new file mode 100644 index 0000000000000000000000000000000000000000..73682023cfa87ef4a1ec4f9c1b7d4316933c5b62 --- /dev/null +++ b/theodolite-quarkus/src/main/resources/yaml/testcrd.yaml @@ -0,0 +1,13 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: benchmarkexecutions.demo.k8s.io +spec: + group: demo.k8s.io + version: v1alpha1 + names: + kind: Benchmarkexecutions + plural: benchmarkexecutions + scope: Namespaced + subresources: + status: {} \ No newline at end of file