add grafana only option
This commit is contained in:
parent
d686349a68
commit
7590e2df2e
7 changed files with 99 additions and 25 deletions
|
@ -9,7 +9,7 @@ private const val USER_HOST_DELIMITER = "@"
|
||||||
private const val USER_PW_DELIMITER = ":"
|
private const val USER_PW_DELIMITER = ":"
|
||||||
|
|
||||||
|
|
||||||
class TargetCliCommand(
|
data class TargetCliCommand(
|
||||||
val target: String,
|
val target: String,
|
||||||
val passwordInteractive: Boolean = false
|
val passwordInteractive: Boolean = false
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ServerSubmodule
|
||||||
|
|
||||||
class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
||||||
passwordInteractive
|
passwordInteractive
|
||||||
),
|
),
|
||||||
module.configFileName,
|
module.configFileName,
|
||||||
module.applicationFileName
|
module.applicationFileName,
|
||||||
|
module.submodules
|
||||||
)
|
)
|
||||||
else -> return ServerCliCommand(
|
else -> return ServerCliCommand(
|
||||||
ServerType.valueOf(module.name.uppercase()),
|
ServerType.valueOf(module.name.uppercase()),
|
||||||
|
@ -49,6 +51,7 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
||||||
var parsed: Boolean = false
|
var parsed: Boolean = false
|
||||||
var configFileName: ConfigFileName? = null
|
var configFileName: ConfigFileName? = null
|
||||||
var applicationFileName: ApplicationFileName? = null
|
var applicationFileName: ApplicationFileName? = null
|
||||||
|
var submodules: List<String>? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class K3s : ServerSubcommand("k3s", "the k3s module") {
|
class K3s : ServerSubcommand("k3s", "the k3s module") {
|
||||||
|
@ -64,10 +67,17 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
||||||
"a",
|
"a",
|
||||||
"the filename containing the yaml a application deployment"
|
"the filename containing the yaml a application deployment"
|
||||||
)
|
)
|
||||||
|
val only by option(
|
||||||
|
ArgType.Choice<ServerSubmodule>(),
|
||||||
|
"only",
|
||||||
|
"o",
|
||||||
|
"provisions only parts ",
|
||||||
|
)
|
||||||
|
|
||||||
override fun execute() {
|
override fun execute() {
|
||||||
super.configFileName = cliConfigFileName?.let { ConfigFileName(it) }
|
super.configFileName = cliConfigFileName?.let { ConfigFileName(it) }
|
||||||
super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) }
|
super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) }
|
||||||
|
super.submodules = if (only != null) listOf(only!!.name.lowercase()) else null
|
||||||
super.parsed = true
|
super.parsed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,13 @@ import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||||
|
|
||||||
class K3sCliCommand (
|
class K3sCliCommand(
|
||||||
serverType: ServerType,
|
serverType: ServerType,
|
||||||
target: TargetCliCommand,
|
target: TargetCliCommand,
|
||||||
configFileName: ConfigFileName?,
|
configFileName: ConfigFileName?,
|
||||||
val applicationFileName: ApplicationFileName?) :
|
val applicationFileName: ApplicationFileName?,
|
||||||
ServerCliCommand(serverType, target, configFileName) {
|
val submodules: List<String>? = null
|
||||||
}
|
) :
|
||||||
|
ServerCliCommand(
|
||||||
|
serverType, target, configFileName
|
||||||
|
)
|
|
@ -4,34 +4,51 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.GrafanaAgentConfigResolved
|
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.GrafanaAgentConfigResolved
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.provisionGrafanaAgent
|
import org.domaindrivenarchitecture.provs.server.domain.k8s_grafana_agent.provisionGrafanaAgent
|
||||||
import org.domaindrivenarchitecture.provs.server.infrastructure.*
|
import org.domaindrivenarchitecture.provs.server.infrastructure.*
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs a k3s server.
|
* Installs a k3s server.
|
||||||
*/
|
*/
|
||||||
fun Prov.provisionK3s(cli: K3sCliCommand) = task {
|
fun Prov.provisionK3s(cli: K3sCliCommand) = task {
|
||||||
|
|
||||||
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
||||||
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
|
val grafanaConfigResolved: GrafanaAgentConfigResolved? = findK8sGrafanaConfig(cli.configFileName)?.resolveSecret()
|
||||||
|
|
||||||
provisionNetwork(k3sConfig)
|
if (cli.submodules == null) {
|
||||||
if (k3sConfig.reprovision && testConfigExists()) {
|
provisionNetwork(k3sConfig)
|
||||||
deprovisionK3sInfra()
|
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)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
provisionMeissaDesktopSubmodules(cli.submodules, grafanaConfigResolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
installK3s(k3sConfig)
|
}
|
||||||
|
|
||||||
if (k3sConfig.certmanager != null) {
|
private fun Prov.provisionMeissaDesktopSubmodules(submodules: List<String>, grafanaConfigResolved: GrafanaAgentConfigResolved?) = task {
|
||||||
provisionK3sCertManager(k3sConfig.certmanager)
|
if (submodules.contains(ServerSubmodule.GRAFANA.name.lowercase())) {
|
||||||
}
|
if (grafanaConfigResolved == null) {
|
||||||
|
println("ERROR: Could not find grafana config.")
|
||||||
if (k3sConfig.echo == true) {
|
exitProcess(7)
|
||||||
provisionK3sEcho(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (grafanaConfigResolved != null) {
|
|
||||||
provisionGrafanaAgent(grafanaConfigResolved)
|
provisionGrafanaAgent(grafanaConfigResolved)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cli.applicationFileName != null) {
|
|
||||||
provisionK3sApplication(cli.applicationFileName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||||
|
|
||||||
|
enum class ServerSubmodule {
|
||||||
|
GRAFANA
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.infrastructure
|
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||||
|
|
||||||
|
import com.charleskorn.kaml.MissingRequiredPropertyException
|
||||||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.readFromFile
|
import org.domaindrivenarchitecture.provs.framework.core.readFromFile
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.toYaml
|
import org.domaindrivenarchitecture.provs.framework.core.toYaml
|
||||||
|
@ -18,7 +19,11 @@ fun findK8sGrafanaConfig(fileName: ConfigFileName? = null): GrafanaAgentConfig?
|
||||||
|
|
||||||
// create a default config
|
// create a default config
|
||||||
return if (File(filePath).exists()) {
|
return if (File(filePath).exists()) {
|
||||||
readFromFile(filePath).yamlToType<GrafanaAgentConfigHolder>().grafana
|
try {
|
||||||
|
readFromFile(filePath).yamlToType<GrafanaAgentConfigHolder>().grafana
|
||||||
|
} catch (e: MissingRequiredPropertyException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package org.domaindrivenarchitecture.provs.server.application
|
package org.domaindrivenarchitecture.provs.server.application
|
||||||
|
|
||||||
|
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.Assertions.assertTrue
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.Assertions.*
|
|
||||||
|
|
||||||
internal class CliArgumentParserTest {
|
internal class CliArgumentParserTest {
|
||||||
|
|
||||||
|
@ -18,4 +22,34 @@ internal class CliArgumentParserTest {
|
||||||
assertTrue(result.isValid())
|
assertTrue(result.isValid())
|
||||||
assertEquals(ServerType.K3S, result.serverType)
|
assertEquals(ServerType.K3S, result.serverType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_parseServerArguments_are_valid_for_k3s_withOnly_grafana() {
|
||||||
|
// given
|
||||||
|
val parser = CliArgumentsParser("test")
|
||||||
|
|
||||||
|
// when
|
||||||
|
val result: K3sCliCommand = parser.parseCommand(args = arrayOf("k3s", "local", "-o", "grafana")) as K3sCliCommand
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(result.isValid())
|
||||||
|
assertEquals(ServerType.K3S, result.serverType)
|
||||||
|
assertEquals(listOf("grafana"), result.submodules)
|
||||||
|
assertEquals(TargetCliCommand("local"), result.target)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_parseServerArguments_are_valid_for_k3s_remote_with_application_yaml() {
|
||||||
|
// given
|
||||||
|
val parser = CliArgumentsParser("test")
|
||||||
|
|
||||||
|
// when
|
||||||
|
val result: K3sCliCommand = parser.parseCommand(args = arrayOf("k3s", "user@host.com", "-a", "app.yaml")) as K3sCliCommand
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertTrue(result.isValid())
|
||||||
|
assertEquals(ServerType.K3S, result.serverType)
|
||||||
|
assertEquals(ApplicationFileName("app.yaml"), result.applicationFileName)
|
||||||
|
assertEquals(TargetCliCommand("user@host.com"), result.target)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue