diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/AbstractStateHandler.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/AbstractStateHandler.kt index 9d7436526f18081c7130870956d8a5eea5fc8997..0b5d6040bdea1316f8fb55bcc3f204c5443f6eee 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/AbstractStateHandler.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/AbstractStateHandler.kt @@ -4,10 +4,13 @@ import io.fabric8.kubernetes.api.model.HasMetadata import io.fabric8.kubernetes.api.model.KubernetesResourceList import io.fabric8.kubernetes.api.model.Namespaced import io.fabric8.kubernetes.client.CustomResource +import io.fabric8.kubernetes.client.KubernetesClientException import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.dsl.MixedOperation import io.fabric8.kubernetes.client.dsl.Resource +import mu.KotlinLogging import java.lang.Thread.sleep +private val logger = KotlinLogging.logger {} abstract class AbstractStateHandler<T, L, D>( private val client: NamespacedKubernetesClient, @@ -20,11 +23,15 @@ abstract class AbstractStateHandler<T, L, D>( @Synchronized override fun setState(resourceName: String, f: (T) -> T?) { - this.crdClient - .list().items - .filter { it.metadata.name == resourceName } - .map { customResource -> f(customResource) } - .forEach { this.crdClient.updateStatus(it) } + try { + this.crdClient + .list().items + .filter { it.metadata.name == resourceName } + .map { customResource -> f(customResource) } + .forEach { this.crdClient.updateStatus(it) } + } catch (e: KubernetesClientException) { + logger.warn { "Status cannot be set for resource $resourceName" } + } } @Synchronized diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt index 62c1ddd4eecb41aecde7000eb048455c95cab949..1209195ee09cebe382f010f38e955dea1c860cd1 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt @@ -80,7 +80,7 @@ class ExecutionHandler( override fun onDelete(execution: ExecutionCRD, b: Boolean) { logger.info { "Delete execution ${execution.metadata.name}" } if (execution.status.executionState == States.RUNNING.value - && this.controller.isExecutionRunning(execution.spec.name) + && this.controller.isExecutionRunning(execution.metadata.name) ) { this.controller.stop() }