refactor provisionK3s

This commit is contained in:
ansgarz 2022-05-14 13:23:43 +02:00
parent 7ca6723b4d
commit 876836f6a3

View file

@ -6,43 +6,50 @@ import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.provis
import org.domaindrivenarchitecture.provs.server.infrastructure.* import org.domaindrivenarchitecture.provs.server.infrastructure.*
import kotlin.system.exitProcess import kotlin.system.exitProcess
/**
* Installs a k3s server.
*/
fun Prov.provisionK3s(cli: K3sCliCommand) = task { fun Prov.provisionK3s(cli: K3sCliCommand) = task {
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret() val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
if (cli.submodules == null) { if (cli.submodules == null) {
provisionNetwork(k3sConfig) // full k3s
if (k3sConfig.reprovision && testConfigExists()) { val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
deprovisionK3sInfra() provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
}
installK3s(k3sConfig)
if (k3sConfig.certmanager != null) {
provisionK3sCertManager(k3sConfig.certmanager)
}
if (k3sConfig.echo == true) {
provisionK3sEcho(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint)
}
if (grafanaConfigResolved != null) {
provisionGrafanaAgent(grafanaConfigResolved)
}
if (cli.applicationFileName != null) {
provisionK3sApplication(cli.applicationFileName)
}
} else { } else {
// submodules only
provisionMeissaDesktopSubmodules(cli.submodules, grafanaConfigResolved) provisionMeissaDesktopSubmodules(cli.submodules, grafanaConfigResolved)
} }
} }
/**
* Installs a k3s server.
*/
fun Prov.provisionK3s(k3sConfig: K3sConfig, grafanaConfigResolved: GrafanaAgentConfigResolved?, applicationFileName: ApplicationFileName?) = task {
provisionNetwork(k3sConfig)
if (k3sConfig.reprovision && testConfigExists()) {
deprovisionK3sInfra()
}
installK3s(k3sConfig)
if (k3sConfig.certmanager != null) {
provisionK3sCertManager(k3sConfig.certmanager)
}
if (k3sConfig.echo == true) {
provisionK3sEcho(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint)
}
if (grafanaConfigResolved != null) {
provisionGrafanaAgent(grafanaConfigResolved)
}
if (applicationFileName != null) {
provisionK3sApplication(applicationFileName)
}
}
private fun Prov.provisionMeissaDesktopSubmodules(submodules: List<String>, grafanaConfigResolved: GrafanaAgentConfigResolved?) = task { private fun Prov.provisionMeissaDesktopSubmodules(submodules: List<String>, grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) { if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) { if (grafanaConfigResolved == null) {