Skip to content
Snippets Groups Projects
Commit a11e3a49 authored by Sören Henning's avatar Sören Henning
Browse files

Replace org.json by Jackson

parent c758f507
No related branches found
No related tags found
No related merge requests found
Pipeline #12768 passed
...@@ -3,7 +3,6 @@ package rocks.theodolite.kubernetes ...@@ -3,7 +3,6 @@ package rocks.theodolite.kubernetes
import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext
import mu.KotlinLogging import mu.KotlinLogging
import org.json.JSONObject
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
...@@ -21,7 +20,8 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -21,7 +20,8 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
fun removePods(labelName: String, labelValue: String) { fun removePods(labelName: String, labelValue: String) {
this.client this.client
.pods() .pods()
.withLabel("$labelName=$labelValue").delete() .withLabel(labelName, labelValue)
.delete()
logger.info { "Pod with label: $labelName=$labelValue deleted" } logger.info { "Pod with label: $labelName=$labelValue deleted" }
} }
...@@ -33,7 +33,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -33,7 +33,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
fun removeServices(labelName: String, labelValue: String) { fun removeServices(labelName: String, labelValue: String) {
this.client this.client
.services() .services()
.withLabel("$labelName=$labelValue") .withLabel(labelName, labelValue)
.delete() .delete()
} }
...@@ -46,7 +46,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -46,7 +46,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
this.client this.client
.apps() .apps()
.deployments() .deployments()
.withLabel("$labelName=$labelValue") .withLabel(labelName, labelValue)
.delete() .delete()
} }
...@@ -60,7 +60,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -60,7 +60,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
this.client this.client
.apps() .apps()
.statefulSets() .statefulSets()
.withLabel("$labelName=$labelValue") .withLabel(labelName, labelValue)
.delete() .delete()
} }
...@@ -72,7 +72,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -72,7 +72,7 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
fun removeConfigMaps(labelName: String, labelValue: String) { fun removeConfigMaps(labelName: String, labelValue: String) {
this.client this.client
.configMaps() .configMaps()
.withLabel("$labelName=$labelValue") .withLabel(labelName, labelValue)
.delete() .delete()
} }
...@@ -81,16 +81,11 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) { ...@@ -81,16 +81,11 @@ class ResourceByLabelHandler(private val client: NamespacedKubernetesClient) {
* @param [labelName] the label name * @param [labelName] the label name
* @param [labelValue] the value of this label * @param [labelValue] the value of this label
*/ */
fun removeCR(labelName: String, labelValue: String, context: CustomResourceDefinitionContext) { fun removeGenericResources(labelName: String, labelValue: String, context: CustomResourceDefinitionContext) {
val customResources = JSONObject( this.client
this.client.customResource(context) .genericKubernetesResources(context)
.list(client.namespace, mapOf(Pair(labelName, labelValue))) .withLabel(labelName, labelValue)
) .delete();
.getJSONArray("items")
(0 until customResources.length())
.map { customResources.getJSONObject(it).getJSONObject("metadata").getString("name") }
.forEach { this.client.customResource(context).delete(client.namespace, it) }
} }
/** /**
......
...@@ -80,7 +80,7 @@ class ClusterSetup( ...@@ -80,7 +80,7 @@ class ClusterSetup(
labelValue = "theodolite" labelValue = "theodolite"
) )
try { try {
resourceRemover.removeCR( resourceRemover.removeGenericResources(
labelName = "app.kubernetes.io/created-by", labelName = "app.kubernetes.io/created-by",
labelValue = "theodolite", labelValue = "theodolite",
context = serviceMonitorContext context = serviceMonitorContext
......
package rocks.theodolite.kubernetes.patcher package rocks.theodolite.kubernetes.patcher
import com.fasterxml.jackson.annotation.JsonTypeName
import com.fasterxml.jackson.core.JsonToken
import com.fasterxml.jackson.databind.node.JsonNodeType
import io.fabric8.kubernetes.api.model.GenericKubernetesResource import io.fabric8.kubernetes.api.model.GenericKubernetesResource
import io.fabric8.kubernetes.api.model.HasMetadata import io.fabric8.kubernetes.api.model.HasMetadata
import org.json.JSONString
/** /**
* Patches an arbitrary field in a [GenericKubernetesResource]. * Patches an arbitrary field in a [GenericKubernetesResource].
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment