add provisioning of an additional k3s application
This commit is contained in:
parent
a9b74342a7
commit
a8c8864f75
8 changed files with 76 additions and 24 deletions
|
@ -1,7 +1,9 @@
|
|||
package org.domaindrivenarchitecture.provs.server.application
|
||||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.cli.createProvInstance
|
||||
import org.domaindrivenarchitecture.provs.server.domain.provisionServer
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
|
@ -21,6 +23,7 @@ fun main(args: Array<String>) {
|
|||
exitProcess(1)
|
||||
}
|
||||
val prov = createProvInstance(cmd.target)
|
||||
provisionServer(prov, cmd)
|
||||
|
||||
when(cmd.serverType) {
|
||||
ServerType.K3S -> prov.provisionK3s(cmd as K3sCliCommand)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
|||
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sCliCommand
|
||||
|
||||
class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
||||
|
||||
|
@ -21,7 +23,18 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
|
||||
val module = modules.first { it.parsed }
|
||||
|
||||
return ServerCliCommand(
|
||||
val serverType = ServerType.valueOf(module.name.uppercase())
|
||||
when(serverType) {
|
||||
ServerType.K3S -> return K3sCliCommand(
|
||||
ServerType.valueOf(module.name.uppercase()),
|
||||
TargetCliCommand(
|
||||
target,
|
||||
passwordInteractive
|
||||
),
|
||||
module.configFileName,
|
||||
module.applicationFileName
|
||||
)
|
||||
else -> return ServerCliCommand(
|
||||
ServerType.valueOf(module.name.uppercase()),
|
||||
TargetCliCommand(
|
||||
target,
|
||||
|
@ -30,10 +43,12 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
module.configFileName
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ServerSubcommand(name: String, description: String) : Subcommand(name, description) {
|
||||
var parsed: Boolean = false
|
||||
var configFileName: ConfigFileName? = null
|
||||
var applicationFileName: ApplicationFileName? = null
|
||||
}
|
||||
|
||||
class K3s : ServerSubcommand("k3s", "the k3s module") {
|
||||
|
@ -43,9 +58,16 @@ class CliArgumentsParser(name: String) : CliTargetParser(name) {
|
|||
"c",
|
||||
"the filename containing the yaml config for k3s"
|
||||
)
|
||||
val cliApplicationFileName by option(
|
||||
ArgType.String,
|
||||
"application-file",
|
||||
"a",
|
||||
"the filename containing the yaml a application deployment"
|
||||
)
|
||||
|
||||
override fun execute() {
|
||||
super.configFileName = cliConfigFileName?.let { ConfigFileName(it) }
|
||||
super.applicationFileName = cliApplicationFileName?.let { ApplicationFileName(it) }
|
||||
super.parsed = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ enum class ServerType {
|
|||
K3D, K3S
|
||||
}
|
||||
|
||||
class ServerCliCommand(
|
||||
open class ServerCliCommand(
|
||||
val serverType: ServerType,
|
||||
val target: TargetCliCommand,
|
||||
val configFileName: ConfigFileName?,)
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
package org.domaindrivenarchitecture.provs.server.domain
|
||||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s
|
||||
|
||||
fun provisionServer(prov: Prov, cmd: ServerCliCommand) {
|
||||
when(cmd.serverType) {
|
||||
ServerType.K3S -> prov.provisionK3s(cmd.configFileName)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||
|
||||
import java.io.File
|
||||
|
||||
data class ApplicationFileName(val fileName: String) {
|
||||
fun fullqualified() : String {
|
||||
return File(fileName).absoluteFile.absolutePath
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.domaindrivenarchitecture.provs.server.domain.k3s
|
||||
|
||||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||
import org.domaindrivenarchitecture.provs.configuration.domain.TargetCliCommand
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerCliCommand
|
||||
import org.domaindrivenarchitecture.provs.server.domain.ServerType
|
||||
|
||||
class K3sCliCommand (
|
||||
serverType: ServerType,
|
||||
target: TargetCliCommand,
|
||||
configFileName: ConfigFileName?,
|
||||
val applicationFileName: ApplicationFileName?) :
|
||||
ServerCliCommand(serverType, target, configFileName) {
|
||||
}
|
|
@ -9,8 +9,8 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.k3s.getK3sConfig
|
|||
/**
|
||||
* Installs a k3s server.
|
||||
*/
|
||||
fun Prov.provisionK3s(configFileName: ConfigFileName?) = task {
|
||||
val k3sConfig: K3sConfig = getK3sConfig(configFileName)
|
||||
fun Prov.provisionK3s(cli: K3sCliCommand) = task {
|
||||
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
|
||||
|
||||
provisionNetwork(k3sConfig)
|
||||
if (k3sConfig.reprovision && testConfigExists()) {
|
||||
|
@ -25,5 +25,8 @@ fun Prov.provisionK3s(configFileName: ConfigFileName?) = task {
|
|||
if (k3sConfig.echo == true) {
|
||||
provisionK3sEcho(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint)
|
||||
}
|
||||
if (cli.applicationFileName != null) {
|
||||
provisionK3sApplication(cli.applicationFileName)
|
||||
}
|
||||
ProvResult(true)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
|||
import org.domaindrivenarchitecture.provs.framework.core.repeatTaskUntilSuccess
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.*
|
||||
import org.domaindrivenarchitecture.provs.server.domain.CertmanagerEndpoint
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Certmanager
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig
|
||||
|
||||
|
@ -174,3 +175,13 @@ fun Prov.provisionK3sEcho(fqdn: String, endpoint: CertmanagerEndpoint? = null) =
|
|||
)
|
||||
cmd("kubectl apply -f $k3sEcho", sudo = true)
|
||||
}
|
||||
|
||||
fun Prov.provisionK3sApplication(applicationFileName: ApplicationFileName) = task {
|
||||
copyFileFromLocal(
|
||||
fullyQualifiedLocalFilename = applicationFileName.fullqualified(),
|
||||
fullyQualifiedFilename = k3sManualManifestsDir + "application.yaml",
|
||||
posixFilePermission = "644",
|
||||
sudo = true
|
||||
)
|
||||
cmd("kubectl apply -f ${k3sManualManifestsDir}application.yaml", sudo = true)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue