diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/AbstractStateHandler.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/AbstractStateHandler.kt index 775669bec3f682661416106731dc2563c2ba6595..24efeddf37bf57a4fc2b0c5625e3950ef687c56d 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/AbstractStateHandler.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/AbstractStateHandler.kt @@ -17,7 +17,7 @@ abstract class AbstractStateHandler<S : HasMetadata>( private val crd: Class<S> ) { - private val crdClient: MixedOperation<S, KubernetesResourceList<S>, Resource<S>> = this.client.resources(this.crd) + protected val crdClient: MixedOperation<S, KubernetesResourceList<S>, Resource<S>> = this.client.resources(this.crd) @Synchronized fun setState(resourceName: String, setter: (S) -> S?) { @@ -29,7 +29,8 @@ abstract class AbstractStateHandler<S : HasMetadata>( // find out the difference between patchStatus and replaceStatus // see also https://github.com/fabric8io/kubernetes-client/pull/3798 if (resourcePatched != null) { - this.crdClient.withName(resourcePatched.metadata.name).patchStatus(resourcePatched) + //this.crdClient.withName(resourcePatched.metadata.name).patchStatus(resourcePatched) + this.client.resource(resourcePatched).patchStatus() } } } catch (e: KubernetesClientException) { diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionStateHandler.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionStateHandler.kt index 2ef38a1d74c358b1c9ffa44d2d574aedf91a62e0..77fc23f7ff8a38ab4027c9faa42aa9afc77324cf 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionStateHandler.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionStateHandler.kt @@ -19,13 +19,19 @@ class ExecutionStateHandler(val client: NamespacedKubernetesClient) : private val executionStateAccessor = { cr: ExecutionCRD -> cr.status.executionState.value } fun setExecutionState(resourceName: String, status: ExecutionState): Boolean { - super.setState(resourceName) { cr -> cr.status.executionState = status; cr } + val execution = super.crdClient.withName(resourceName).get() + if (execution != null) { + execution.status.executionState = status + this.crdClient.resource(execution).patchStatus() + } + //super.setState(resourceName) { it.apply { this.status.executionState = status } } return blockUntilStateIsSet(resourceName, status.value, executionStateAccessor) } fun getExecutionState(resourceName: String): ExecutionState { val statusString = this.getState(resourceName, executionStateAccessor) return ExecutionState.values().first { it.value == statusString } + //return ExecutionState.entries.first { it.value == statusString } } private fun updateDurationState(resourceName: String) { diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandlerTestWithInformer.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandlerTestWithInformer.kt index 9c894b862d1146fe2a9857f2834c611dc23edeaa..7e78d0735102cb3c948b0c70a4c08c234cc410fb 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandlerTestWithInformer.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandlerTestWithInformer.kt @@ -64,8 +64,8 @@ class ExecutionEventHandlerTestWithInformer { @AfterEach fun tearDown() { - server.after() this.server.client.informers().stopAllRegisteredInformers() + this.server.after() } @Test @@ -95,6 +95,7 @@ class ExecutionEventHandlerTestWithInformer { @Test @DisplayName("Test onAdd method for executions without execution state") fun testOnAddWithoutStatus() { + println("Start testOnAddWithoutStatus") // Create first version of execution resource val executionResource = getExecutionFromSystemResource("k8s-resource-files/test-execution.yaml") val execution = executionResource.create() @@ -139,6 +140,7 @@ class ExecutionEventHandlerTestWithInformer { @Test @DisplayName("Test onUpdate method for execution with no status") fun testOnUpdateWithoutStatus() { + println("start testOnUpdateWithoutStatus") // Start informer this.executionClient.inform(eventHandler) @@ -168,6 +170,7 @@ class ExecutionEventHandlerTestWithInformer { @MethodSource("provideOnUpdateTestArguments") @DisplayName("Test onUpdate method for execution with different status") fun testOnUpdateWithStatus(beforeState: ExecutionState, expectedState: ExecutionState) { + println("Start testOnUpdateWithStatus / $beforeState / $expectedState") // Create first version of execution resource val firstExecutionResource = getExecutionFromSystemResource("k8s-resource-files/test-execution.yaml") val firstExecution = firstExecutionResource.create() @@ -233,37 +236,56 @@ class ExecutionEventHandlerTestWithInformer { @Test fun testOnDeleteWithExecutionNotRunning() { + println("start testOnDeleteWithExecutionNotRunning") // Create first version of execution resource val firstExecutionResource = getExecutionFromSystemResource("k8s-resource-files/test-execution.yaml") val firstExecution = firstExecutionResource.create() val executionName = firstExecution.metadata.name + println("Create first version of execution resource") + // Update status of execution to be running firstExecution.status.executionState = ExecutionState.RUNNING firstExecutionResource.patchStatus(firstExecution) + println("Update status of execution to be running") + // Get execution from server val firstExecutionResponse = this.executionClient.withName(executionName).get() // Assert that execution created at server assertNotNull(firstExecutionResponse) + println("Get execution from server") + + Thread.sleep(1000) + // Start informer this.executionClient.inform(eventHandler) + println("Start informer") + // We consider execution to be running whenever(this.controller.isExecutionRunning(executionName)).thenReturn(false) + println("We consider execution to be running") + // Delete execution - this.executionClient.delete(firstExecutionResponse) + this.executionClient.resource(firstExecutionResponse).delete() + + println("Delete execution") // Get execution from server val secondExecutionResponse = this.executionClient.withName(executionName).get() // Assert that execution created at server assertNull(secondExecutionResponse) + println("Get execution from server") + // Await informer called this.deleteCountDownLatch.await(10, TimeUnit.SECONDS) + println("Await informer called") + verify(this.controller, never()).stop(false) }