v0.8.36 add options to k3s

This commit is contained in:
ansgarz 2022-01-17 21:11:00 +01:00
parent 080b006d6e
commit 404235a9e2
4 changed files with 18 additions and 14 deletions

View file

@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization'
group = 'org.domaindrivenarchitecture.provs' group = 'org.domaindrivenarchitecture.provs'
version = '0.8.36-SNAPSHOT' version = '0.8.36'
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -1,7 +1,7 @@
package org.domaindrivenarchitecture.provs.extensions.server_software.k3s.application package org.domaindrivenarchitecture.provs.extensions.server_software.k3s.application
import org.domaindrivenarchitecture.provs.core.Prov import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.installK3sServer import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain.installK3sServer
/** /**

View file

@ -1,4 +1,4 @@
package org.domaindrivenarchitecture.provs.extensions.server_software.k3s package org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain
import org.domaindrivenarchitecture.provs.core.Prov import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.core.ProvResult
@ -8,21 +8,27 @@ import org.domaindrivenarchitecture.provs.ubuntu.install.base.aptInstall
/** /**
* Installs a k3s server. * Installs a k3s server.
* If docker is true, then k3s will be installed with docker option and also docker will be installed (may conflict if docker is already existing). * 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 host is specified, then tls (if configured) also applies to host. * If tlsHost is specified, then tls (if configured) also applies to the specified host.
*/ */
fun Prov.installK3sServer(docker: Boolean = false, host: String? = null) = task { fun Prov.installK3sServer(docker: Boolean = false, tlsHost: String? = null, options: String? = null) = task {
val tls = host?.let { "INSTALL_K3S_EXEC=\"--tls-san ${it}\"" } ?: "" val tlsSanOption = tlsHost?.let { "--tls-san ${it}" } ?: ""
val k3sOptions = if (tlsHost == null && options == null)
""
else
"INSTALL_K3S_EXEC=\"$options $tlsSanOption\""
aptInstall("curl") aptInstall("curl")
if (!chk("k3s -version")) { if (!chk("k3s -version")) {
if (docker) { if (docker) {
// might not work if docker already installed // might not work if docker already installed
sh(""" sh("""
curl https://releases.rancher.com/install-docker/19.03.sh | sh curl https://releases.rancher.com/install-docker/19.03.sh | sh
curl -sfL https://get.k3s.io | sh -s - --docker curl -sfL https://get.k3s.io | $k3sOptions sh -s - --docker
""".trimIndent()) """.trimIndent())
} else { } else {
cmd("curl -sfL https://get.k3s.io | $tls sh -") cmd("curl -sfL https://get.k3s.io | $k3sOptions sh -")
} }
} else { } else {
ProvResult(true) ProvResult(true)
@ -38,5 +44,3 @@ fun Prov.uninstallK3sServer() = task {
fun Prov.applyK3sConfig(configAsYaml: String) = task { fun Prov.applyK3sConfig(configAsYaml: String) = task {
cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -") cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -")
} }

View file

@ -4,8 +4,8 @@ import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.core.ProvResult
import org.domaindrivenarchitecture.provs.core.remote import org.domaindrivenarchitecture.provs.core.remote
import org.domaindrivenarchitecture.provs.core.repeatTaskUntilSuccess import org.domaindrivenarchitecture.provs.core.repeatTaskUntilSuccess
import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.applyK3sConfig import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain.applyK3sConfig
import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.installK3sServer import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain.installK3sServer
/** /**
@ -80,7 +80,7 @@ fun main() {
val host = "123.34.56.78" val host = "123.34.56.78"
remote(host, "root").task { remote(host, "root").task {
installK3sServer(host = host) installK3sServer(tlsHost = host)
applyK3sConfig(appleConfig()) applyK3sConfig(appleConfig())
// optional check // optional check