refactor domain & infra for k3s
This commit is contained in:
parent
e9f79ed0a3
commit
1defd46c97
6 changed files with 56 additions and 48 deletions
|
@ -1,7 +1,10 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain
|
package org.domaindrivenarchitecture.provs.server.domain
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s
|
||||||
|
|
||||||
fun provisionServer(prov: Prov, cmd: ServerCliCommand) {
|
fun provisionServer(prov: Prov, cmd: ServerCliCommand) {
|
||||||
|
when(cmd.serverType) {
|
||||||
|
ServerType.K3S -> prov.provisionK3s()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.application
|
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.installK3sServer
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs use case of provisioning a k3s server
|
|
||||||
*/
|
|
||||||
fun Prov.provisionK3s() = task {
|
|
||||||
installK3sServer()
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain
|
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.echoCommandForText
|
import org.domaindrivenarchitecture.provs.framework.core.echoCommandForText
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
||||||
|
import org.domaindrivenarchitecture.provs.server.infrastructure.provisionK3sInfra
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,36 +12,6 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInsta
|
||||||
* If docker is true, then docker will be installed (may conflict if docker is already existing) and k3s will be installed with docker option.
|
* If docker is true, then docker will be installed (may conflict if docker is already existing) and k3s will be installed with docker option.
|
||||||
* If tlsHost is specified, then tls (if configured) also applies to the specified host.
|
* If tlsHost is specified, then tls (if configured) also applies to the specified host.
|
||||||
*/
|
*/
|
||||||
fun Prov.installK3sServer(docker: Boolean = false, tlsHost: String? = null, options: String? = null) = task {
|
fun Prov.provisionK3s() = task {
|
||||||
val tlsSanOption = tlsHost?.let { "--tls-san ${it}" } ?: ""
|
provisionK3sInfra()
|
||||||
|
|
||||||
val k3sOptions = if (tlsHost == null && options == null)
|
|
||||||
""
|
|
||||||
else
|
|
||||||
"INSTALL_K3S_EXEC=\"$options $tlsSanOption\""
|
|
||||||
|
|
||||||
aptInstall("curl")
|
|
||||||
if (!chk("k3s -version")) {
|
|
||||||
if (docker) {
|
|
||||||
// might not work if docker already installed
|
|
||||||
sh("""
|
|
||||||
curl https://releases.rancher.com/install-docker/19.03.sh | sh
|
|
||||||
curl -sfL https://get.k3s.io | $k3sOptions sh -s - --docker
|
|
||||||
""".trimIndent())
|
|
||||||
} else {
|
|
||||||
cmd("curl -sfL https://get.k3s.io | $k3sOptions sh -")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ProvResult(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun Prov.uninstallK3sServer() = task {
|
|
||||||
cmd("sudo /usr/local/bin/k3s-uninstall.sh")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun Prov.applyK3sConfig(configAsYaml: String) = task {
|
|
||||||
cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.core.echoCommandForText
|
||||||
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs a k3s server.
|
||||||
|
* If docker is true, then docker will be installed (may conflict if docker is already existing) and k3s will be installed with docker option.
|
||||||
|
* If tlsHost is specified, then tls (if configured) also applies to the specified host.
|
||||||
|
*/
|
||||||
|
fun Prov.provisionK3sInfra(docker: Boolean = false, tlsHost: String? = null, options: String? = null) = task {
|
||||||
|
val tlsSanOption = tlsHost?.let { "--tls-san ${it}" } ?: ""
|
||||||
|
|
||||||
|
val k3sOptions = if (tlsHost == null && options == null)
|
||||||
|
""
|
||||||
|
else
|
||||||
|
"INSTALL_K3S_EXEC=\"$options $tlsSanOption\""
|
||||||
|
|
||||||
|
aptInstall("curl")
|
||||||
|
if (!chk("k3s -version")) {
|
||||||
|
if (docker) {
|
||||||
|
// might not work if docker already installed
|
||||||
|
sh("""
|
||||||
|
curl https://releases.rancher.com/install-docker/19.03.sh | sh
|
||||||
|
curl -sfL https://get.k3s.io | $k3sOptions sh -s - --docker
|
||||||
|
""".trimIndent())
|
||||||
|
} else {
|
||||||
|
cmd("curl -sfL https://get.k3s.io | $k3sOptions sh -")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ProvResult(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Prov.uninstallK3sServer() = task {
|
||||||
|
cmd("sudo /usr/local/bin/k3s-uninstall.sh")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Prov.applyK3sConfig(configAsYaml: String) = task {
|
||||||
|
cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -")
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.domain
|
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.docker
|
import org.domaindrivenarchitecture.provs.framework.core.docker
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.docker.containerExec
|
import org.domaindrivenarchitecture.provs.framework.core.docker.containerExec
|
||||||
|
@ -7,6 +7,8 @@ import org.domaindrivenarchitecture.provs.framework.core.local
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
|
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
|
||||||
import org.domaindrivenarchitecture.provs.server.apple.appleConfig
|
import org.domaindrivenarchitecture.provs.server.apple.appleConfig
|
||||||
import org.domaindrivenarchitecture.provs.server.apple.checkAppleService
|
import org.domaindrivenarchitecture.provs.server.apple.checkAppleService
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.applyK8sConfig
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.installK3sAsContainers
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.NonCi
|
import org.domaindrivenarchitecture.provs.test.tags.NonCi
|
||||||
import org.junit.jupiter.api.Assertions.assertTrue
|
import org.junit.jupiter.api.Assertions.assertTrue
|
Loading…
Reference in a new issue