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

Merge branch 'main' into vertical-scaling

parents b9a46007 c45768a4
No related branches found
No related tags found
1 merge request!303Add resource type for threads (vertical scaling)
...@@ -27,8 +27,8 @@ class ConfigMapYamlPatcher( ...@@ -27,8 +27,8 @@ class ConfigMapYamlPatcher(
val parser = Yaml(dumperOptions) val parser = Yaml(dumperOptions)
// Change value // Change value
val yaml = parser.loadAs(yamlFile, LinkedHashMap<String, String>()::class.java) val yaml = parser.loadAs(yamlFile, LinkedHashMap<String, Any>()::class.java)
yaml[variableName] = value yaml[variableName] = value.toLongOrNull() ?: value.toDoubleOrNull() ?: value.toBooleanStrictOrNull() ?: value
// Convert back to String and set in Kubernetes resource // Convert back to String and set in Kubernetes resource
resource.data[fileName] = parser.dump(yaml) resource.data[fileName] = parser.dump(yaml)
......
package rocks.theodolite.kubernetes.patcher
import io.fabric8.kubernetes.api.model.ConfigMap
import io.fabric8.kubernetes.api.model.ConfigMapBuilder
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
internal class ConfigMapYamlPatcherTest {
private lateinit var configMap: ConfigMap
private val patcher = ConfigMapYamlPatcher("some-file.yaml", "second")
@BeforeEach
fun setUp() {
val data = mapOf(
"some-file.yaml" to """
first: some-test
second: 1
third: 1234
""".trimIndent()
)
this.configMap = ConfigMapBuilder()
.withNewMetadata()
.withName("example")
.endMetadata()
.addToData(data)
.build()
}
@ParameterizedTest
@ValueSource(strings = ["some-string", "42", "42.42", "true"])
fun setSettingString(inputValue: String) {
val patched = patcher.patchSingleResource(this.configMap, inputValue)
assertTrue(patched is ConfigMap)
//patched.let { it as ConfigMap }.data
patched as ConfigMap
val yaml = patched.data["some-file.yaml"]
assertTrue(yaml != null)
val line = yaml!!.lines().getOrNull(1)
assertTrue(line != null)
val value = line!!.split(": ").getOrNull(1)
assertEquals(inputValue, value)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment