Prepare for add cli option

-r or --reprovision for convenience
This commit is contained in:
erik 2022-08-16 15:20:19 +02:00
parent 1d61273fe2
commit 77351933fe
3 changed files with 22 additions and 7 deletions

View file

@ -34,7 +34,8 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
),
module.configFileName,
module.applicationFileName,
module.submodules
module.submodules,
module.reprovision
)
else -> return ServerCliCommand(
ServerType.valueOf(module.name.uppercase()),
@ -52,6 +53,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
var configFileName: ConfigFileName? = null
var applicationFileName: ApplicationFileName? = null
var submodules: List<String>? = null
var reprovision: Boolean = false
}
class K3s : ServerSubcommand("k3s", "the k3s module") {
@ -73,11 +75,17 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
"o",
"provisions only parts ",
)
val cliReprovision by option(
ArgType.Boolean,
"reprovision",
"r",
"redo provisioning, deletes old config first"
)
override fun execute() {
super.configFileName = cliConfigFileName?.let { ConfigFileName(it) }
super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) }
super.submodules = if (only != null) listOf(only!!.name.lowercase()) else null
super.reprovision = cliReprovision == true
super.parsed = true
}
}

View file

@ -10,7 +10,8 @@ class K3sCliCommand(
target: TargetCliCommand,
configFileName: ConfigFileName?,
val applicationFileName: ApplicationFileName?,
val submodules: List<String>? = null
val submodules: List<String>? = null,
val reprovision: Reprovision = false
) :
ServerCliCommand(
serverType, target, configFileName

View file

@ -11,11 +11,17 @@ fun Prov.provisionK3s(cli: K3sCliCommand) = task {
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
if (cli.submodules == null) {
if (cli.submodules == null && !cli.reprovision) {
// full k3s
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
} else {
}
else if (cli.reprovision) {
deprovisionK3sInfra()
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
provisionK3sWorker(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
}
else {
// submodules only
provisionGrafanaSanitized(cli.submodules, grafanaConfigResolved)
}
@ -57,10 +63,10 @@ fun Prov.provisionK3sWorker(
}
private fun Prov.provisionGrafanaSanitized(
submodules: List<String>,
submodules: List<String>?,
grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
if (submodules!!.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) {
println("ERROR: Could not find grafana config.")
exitProcess(7)