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 kotlin.system.exitProcess
/**
* Installs a k3s server.
*/
fun Prov.provisionK3s(cli: K3sCliCommand) = task {
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
if (cli.submodules == null) {
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 (cli.applicationFileName != null) {
provisionK3sApplication(cli.applicationFileName)
}
// full k3s
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
} else {
// submodules only
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 {
if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) {