From 404235a9e2471acfc21c13221fe22c8c69245d02 Mon Sep 17 00:00:00 2001 From: ansgarz Date: Mon, 17 Jan 2022 21:11:00 +0100 Subject: [PATCH] v0.8.36 add options to k3s --- build.gradle | 2 +- .../k3s/application/Application.kt | 2 +- .../server_software/k3s/domain/K3s.kt | 22 +++++++++++-------- .../k3s/infrastructure/apple/Apple.kt | 6 ++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 51e3530..941145e 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization' group = 'org.domaindrivenarchitecture.provs' -version = '0.8.36-SNAPSHOT' +version = '0.8.36' repositories { mavenCentral() diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/application/Application.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/application/Application.kt index 12fce49..d4d6676 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/application/Application.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/application/Application.kt @@ -1,7 +1,7 @@ package org.domaindrivenarchitecture.provs.extensions.server_software.k3s.application 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 /** diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/domain/K3s.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/domain/K3s.kt index d67e88d..739d3d0 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/domain/K3s.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/domain/K3s.kt @@ -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.ProvResult @@ -8,21 +8,27 @@ import org.domaindrivenarchitecture.provs.ubuntu.install.base.aptInstall /** * 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 host is specified, then tls (if configured) also applies to host. + * 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.installK3sServer(docker: Boolean = false, host: String? = null) = task { - val tls = host?.let { "INSTALL_K3S_EXEC=\"--tls-san ${it}\"" } ?: "" +fun Prov.installK3sServer(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 | sh -s - --docker + curl -sfL https://get.k3s.io | $k3sOptions sh -s - --docker """.trimIndent()) } else { - cmd("curl -sfL https://get.k3s.io | $tls sh -") + cmd("curl -sfL https://get.k3s.io | $k3sOptions sh -") } } else { ProvResult(true) @@ -38,5 +44,3 @@ fun Prov.uninstallK3sServer() = task { fun Prov.applyK3sConfig(configAsYaml: String) = task { cmd(echoCommandForText(configAsYaml) + " | sudo k3s kubectl apply -f -") } - - diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/infrastructure/apple/Apple.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/infrastructure/apple/Apple.kt index 15d8417..d3d9c9e 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/infrastructure/apple/Apple.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/extensions/server_software/k3s/infrastructure/apple/Apple.kt @@ -4,8 +4,8 @@ import org.domaindrivenarchitecture.provs.core.Prov import org.domaindrivenarchitecture.provs.core.ProvResult import org.domaindrivenarchitecture.provs.core.remote import org.domaindrivenarchitecture.provs.core.repeatTaskUntilSuccess -import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.applyK3sConfig -import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.installK3sServer +import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain.applyK3sConfig +import org.domaindrivenarchitecture.provs.extensions.server_software.k3s.domain.installK3sServer /** @@ -80,7 +80,7 @@ fun main() { val host = "123.34.56.78" remote(host, "root").task { - installK3sServer(host = host) + installK3sServer(tlsHost = host) applyK3sConfig(appleConfig()) // optional check