config by file
This commit is contained in:
parent
9f27ecf8a1
commit
1a8877d419
10 changed files with 42 additions and 49 deletions
|
@ -1,6 +0,0 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Ipv6(val ip: String)
|
|
|
@ -1,12 +1,14 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import org.domaindrivenarchitecture.provs.server.infrastructure.CertManagerEndPoint
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class K3sConfig(
|
data class K3sConfig(
|
||||||
val fqdn: Fqdn,
|
val fqdn: Fqdn,
|
||||||
val nodeIpv4: Ipv4,
|
val node: Node,
|
||||||
val nodeIpv6: Ipv6?,
|
val loopback: Loopback = Loopback(ipv4 = "192.168.5.1", ipv6 = "fc00::5:1"),
|
||||||
val loopbackIpv4: Ipv4? = Ipv4("192.168.5.1"),
|
val reprovision: Reprovision = false,
|
||||||
val loopbackIpv6: Ipv6? = Ipv6("fc00::5:1"),
|
val letsencryptEndpoint: CertManagerEndPoint = CertManagerEndPoint.STAGING
|
||||||
val reprovision: Reprovision? = Reprovision(false)
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,12 +13,12 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.k3s.getK3sConfig
|
||||||
fun Prov.provisionK3s(configFileName: ConfigFileName?) = task {
|
fun Prov.provisionK3s(configFileName: ConfigFileName?) = task {
|
||||||
val k3sConfig: K3sConfig = getK3sConfig(configFileName!!)
|
val k3sConfig: K3sConfig = getK3sConfig(configFileName!!)
|
||||||
|
|
||||||
provisionNetwork(loopbackIpv4 = k3sConfig.loopbackIpv4!!.ip, loopbackIpv6 = k3sConfig.loopbackIpv6!!.ip)
|
provisionNetwork(loopbackIpv4 = k3sConfig.loopback.ipv4, loopbackIpv6 = k3sConfig.loopback.ipv6!!)
|
||||||
if (k3sConfig.reprovision!!.it && testConfigExists()) {
|
if (k3sConfig.reprovision && testConfigExists()) {
|
||||||
deprovisionK3sInfra()
|
deprovisionK3sInfra()
|
||||||
}
|
}
|
||||||
provisionK3sInfra(tlsName = k3sConfig.fqdn.it, nodeIpv4 = k3sConfig.nodeIpv4.ip, nodeIpv6 = k3sConfig.nodeIpv6?.ip,
|
provisionK3sInfra(tlsName = k3sConfig.fqdn, nodeIpv4 = k3sConfig.node.ipv4, nodeIpv6 = k3sConfig.node.ipv6,
|
||||||
loopbackIpv4 = k3sConfig.loopbackIpv4!!.ip, loopbackIpv6 = k3sConfig.loopbackIpv6.ip)
|
loopbackIpv4 = k3sConfig.loopback.ipv4, loopbackIpv6 = k3sConfig.loopback.ipv6)
|
||||||
provisionK3sCertManager(CertManagerEndPoint.STAGING)
|
provisionK3sCertManager(k3sConfig.letsencryptEndpoint)
|
||||||
provisionK3sApple(k3sConfig.fqdn.it, CertManagerEndPoint.STAGING)
|
provisionK3sApple(k3sConfig.fqdn, k3sConfig.letsencryptEndpoint)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,6 @@ package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Ipv4(val ip: String)
|
data class Loopback(
|
||||||
|
val ipv4: Ipv4,
|
||||||
|
val ipv6: Ipv6?)
|
|
@ -3,4 +3,6 @@ package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Fqdn(val it: String)
|
data class Node(
|
||||||
|
val ipv4: Ipv4,
|
||||||
|
val ipv6: Ipv6?)
|
|
@ -1,6 +0,0 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class Reprovision(val it: Boolean)
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
|
typealias Ipv6 = String
|
||||||
|
typealias Ipv4 = String
|
||||||
|
typealias Fqdn = String
|
||||||
|
typealias Reprovision = Boolean
|
|
@ -15,16 +15,9 @@ public fun getK3sConfig(configFileName: ConfigFileName): K3sConfig {
|
||||||
// deserializing
|
// deserializing
|
||||||
val config =
|
val config =
|
||||||
if (configFileName.fileName.lowercase().endsWith(".yaml")) {
|
if (configFileName.fileName.lowercase().endsWith(".yaml")) {
|
||||||
Yaml.default.decodeFromString(K3sSerial.serializer(), inputAsString)
|
Yaml.default.decodeFromString(K3sConfig.serializer(), inputAsString)
|
||||||
} else {
|
} else {
|
||||||
Json.decodeFromString(K3sSerial.serializer(), inputAsString)
|
Json.decodeFromString(K3sConfig.serializer(), inputAsString)
|
||||||
}
|
}
|
||||||
return K3sConfig(
|
return config
|
||||||
Fqdn(config.fqdn),
|
|
||||||
Ipv4(config.nodeIpv4),
|
|
||||||
config.nodeIpv6?.let { Ipv6(it) },
|
|
||||||
config.loopbackIpv4?.let { Ipv4(it) },
|
|
||||||
config.loopbackIpv6?.let { Ipv6(it) },
|
|
||||||
config.reprovision?.let { Reprovision(it) }
|
|
||||||
)
|
|
||||||
}
|
}
|
|
@ -3,10 +3,8 @@ package org.domaindrivenarchitecture.provs.server.infrastructure.k3s
|
||||||
import com.charleskorn.kaml.InvalidPropertyValueException
|
import com.charleskorn.kaml.InvalidPropertyValueException
|
||||||
import com.charleskorn.kaml.UnknownPropertyException
|
import com.charleskorn.kaml.UnknownPropertyException
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName
|
import org.domaindrivenarchitecture.provs.server.domain.ConfigFileName
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Fqdn
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.*
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Ipv4
|
import org.domaindrivenarchitecture.provs.server.infrastructure.CertManagerEndPoint
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Ipv6
|
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Reprovision
|
|
||||||
import org.junit.jupiter.api.Assertions.assertEquals
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
@ -20,12 +18,12 @@ internal class ConfigRepositoryTest {
|
||||||
val config = getK3sConfig(ConfigFileName("src/test/resources/myK3sServerConfig.yaml"))
|
val config = getK3sConfig(ConfigFileName("src/test/resources/myK3sServerConfig.yaml"))
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(Ipv4("159.69.176.151"), config.nodeIpv4)
|
assertEquals(K3sConfig(
|
||||||
assertEquals(Ipv6("2a01:4f8:c010:672f::1"), config.nodeIpv6)
|
"statistics.test.meissa-gmbh.de",
|
||||||
assertEquals(Ipv4("192.168.5.1"), config.loopbackIpv4)
|
Node("159.69.176.151", "2a01:4f8:c010:672f::1"),
|
||||||
assertEquals(Ipv6("fc00::5:1"), config.loopbackIpv6)
|
Loopback("192.168.5.1", "fc00::5:1"),
|
||||||
assertEquals(Fqdn("statistics.test.meissa-gmbh.de"), config.fqdn)
|
true,
|
||||||
assertEquals(Reprovision(true), config.reprovision)
|
CertManagerEndPoint.PROD), config)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
nodeIpv4: 159.69.176.151
|
|
||||||
nodeIpv6: 2a01:4f8:c010:672f::1
|
|
||||||
fqdn: statistics.test.meissa-gmbh.de
|
fqdn: statistics.test.meissa-gmbh.de
|
||||||
|
node:
|
||||||
|
ipv4: 159.69.176.151
|
||||||
|
ipv6: 2a01:4f8:c010:672f::1
|
||||||
reprovision: true
|
reprovision: true
|
||||||
|
letsencryptEndpoint: PROD
|
Loading…
Reference in a new issue