Skip to content
Snippets Groups Projects

Make the clean up of ServiceMonitors optional when Operator is starting

Merged Benedikt Wetzel requested to merge wetzel/spesb:make-sm-cleanup-optional into master
All threads resolved!
package theodolite.execution.operator
package theodolite.execution.operator
 
import io.fabric8.kubernetes.client.KubernetesClientException
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.dsl.MixedOperation
import io.fabric8.kubernetes.client.dsl.MixedOperation
import io.fabric8.kubernetes.client.dsl.Resource
import io.fabric8.kubernetes.client.dsl.Resource
 
import mu.KotlinLogging
import theodolite.execution.Shutdown
import theodolite.execution.Shutdown
import theodolite.k8s.K8sContextFactory
import theodolite.k8s.K8sContextFactory
import theodolite.k8s.ResourceByLabelHandler
import theodolite.k8s.ResourceByLabelHandler
import theodolite.model.crd.*
import theodolite.model.crd.*
 
private val logger = KotlinLogging.logger {}
 
class ClusterSetup(
class ClusterSetup(
private val executionCRDClient: MixedOperation<ExecutionCRD, BenchmarkExecutionList, Resource<ExecutionCRD>>,
private val executionCRDClient: MixedOperation<ExecutionCRD, BenchmarkExecutionList, Resource<ExecutionCRD>>,
private val benchmarkCRDClient: MixedOperation<BenchmarkCRD, KubernetesBenchmarkList, Resource<BenchmarkCRD>>,
private val benchmarkCRDClient: MixedOperation<BenchmarkCRD, KubernetesBenchmarkList, Resource<BenchmarkCRD>>,
@@ -75,10 +79,15 @@ class ClusterSetup(
@@ -75,10 +79,15 @@ class ClusterSetup(
labelName = "app.kubernetes.io/created-by",
labelName = "app.kubernetes.io/created-by",
labelValue = "theodolite"
labelValue = "theodolite"
)
)
resourceRemover.removeCR(
try {
labelName = "app.kubernetes.io/created-by",
resourceRemover.removeCR(
labelValue = "theodolite",
labelName = "app.kubernetes.io/created-by",
context = serviceMonitorContext
labelValue = "theodolite",
)
context = serviceMonitorContext
 
)
 
} catch (e: KubernetesClientException) {
 
logger.warn { "Service monitors could not be cleaned up. It may be that service monitors are not registered by the Kubernetes API."}
 
logger.debug { "Error is: ${e.message}" }
 
}
}
}
}
}
 
\ No newline at end of file
Loading