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