From 876836f6a3b65dc708be026720aa570381e06dd1 Mon Sep 17 00:00:00 2001 From: ansgarz Date: Sat, 14 May 2022 13:23:43 +0200 Subject: [PATCH] refactor provisionK3s --- .../provs/server/domain/k3s/K3sService.kt | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index 8fb395f..92fff75 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -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, grafanaConfigResolved: GrafanaAgentConfigResolved?) = task { if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) { if (grafanaConfigResolved == null) {