refactor k3s: split install & configure
This commit is contained in:
parent
31c60931dd
commit
e03d8d5d58
5 changed files with 60 additions and 55 deletions
|
@ -16,11 +16,13 @@ fun Prov.provisionK3s(configFileName: ConfigFileName?) = task {
|
|||
if (k3sConfig.reprovision && testConfigExists()) {
|
||||
deprovisionK3sInfra()
|
||||
}
|
||||
|
||||
provisionK3sInfra(k3sConfig)
|
||||
|
||||
if (k3sConfig.certmanager != null) {
|
||||
provisionK3sCertManager(k3sConfig.certmanager)
|
||||
}
|
||||
if (k3sConfig.apple != null && k3sConfig.apple) {
|
||||
if (k3sConfig.apple == true) {
|
||||
provisionK3sApple(k3sConfig.fqdn, k3sConfig.certmanager?.letsencryptEndpoint)
|
||||
}
|
||||
ProvResult(true)
|
||||
|
|
|
@ -19,10 +19,20 @@ private const val certManagerIssuer = k3sManualManifestsDir + "issuer.yaml"
|
|||
private const val k3sApple = k3sManualManifestsDir + "apple.yaml"
|
||||
private const val k3sInstall = "/usr/local/bin/k3s-install.sh"
|
||||
|
||||
|
||||
fun Prov.testConfigExists(): Boolean {
|
||||
return fileExists(k3sConfigFile)
|
||||
}
|
||||
|
||||
fun Prov.provisionK3sInfra(k3sConfig: K3sConfig) = task {
|
||||
if (!testConfigExists()) {
|
||||
installK3s()
|
||||
configureK3s(k3sConfig)
|
||||
} else {
|
||||
ProvResult(true)
|
||||
}
|
||||
}
|
||||
|
||||
fun Prov.deprovisionK3sInfra() = task {
|
||||
deleteFile(k3sInstall, sudo = true)
|
||||
deleteFile(k3sApple, sudo = true)
|
||||
|
@ -31,13 +41,19 @@ fun Prov.deprovisionK3sInfra() = task {
|
|||
cmd("k3s-uninstall.sh")
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a k3s server.
|
||||
* If docker is true, then docker will be installed (may conflict if docker is already existing) and k3s will be installed with docker option.
|
||||
* If tlsHost is specified, then tls (if configured) also applies to the specified host.
|
||||
*/
|
||||
fun Prov.provisionK3sInfra(k3sConfig: K3sConfig) = task {
|
||||
if (!testConfigExists()) {
|
||||
|
||||
fun Prov.installK3s() = task {
|
||||
createFileFromResource(
|
||||
k3sInstall,
|
||||
"k3s-install.sh",
|
||||
k3sResourcePath,
|
||||
"755",
|
||||
sudo = true
|
||||
)
|
||||
cmd("INSTALL_K3S_CHANNEL=latest k3s-install.sh")
|
||||
}
|
||||
|
||||
fun Prov.configureK3s(k3sConfig: K3sConfig) = task {
|
||||
createDirs(k8sCredentialsPath, sudo = true)
|
||||
createDirs(k3sAutomatedManifestsDir, sudo = true)
|
||||
createDirs(k3sManualManifestsDir, sudo = true)
|
||||
|
@ -61,14 +77,6 @@ fun Prov.provisionK3sInfra(k3sConfig: K3sConfig) = task {
|
|||
"644",
|
||||
sudo = true
|
||||
)
|
||||
createFileFromResource(
|
||||
k3sInstall,
|
||||
"k3s-install.sh",
|
||||
k3sResourcePath,
|
||||
"755",
|
||||
sudo = true
|
||||
)
|
||||
cmd("INSTALL_K3S_CHANNEL=latest k3s-install.sh")
|
||||
if (k3sConfig.isDualStack()) {
|
||||
// see https://github.com/k3s-io/k3s/discussions/5003
|
||||
createFileFromResource(
|
||||
|
@ -83,9 +91,6 @@ fun Prov.provisionK3sInfra(k3sConfig: K3sConfig) = task {
|
|||
ProvResult(true)
|
||||
}
|
||||
cmd("ln -s /etc/rancher/k3s/k3s.yaml " + k8sCredentialsPath + "admin.conf", sudo = true)
|
||||
} else {
|
||||
ProvResult(true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,3 @@ fun getK3sConfig(fileName: ConfigFileName? = null): K3sConfig {
|
|||
fun writeK3sConfig(fileName: ConfigFileName, config: K3sConfig) {
|
||||
writeToFile(fileName.fileName, config.toYaml())
|
||||
}
|
||||
fun main() {
|
||||
getK3sConfig()
|
||||
}
|
|
@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test
|
|||
import org.junit.jupiter.api.assertThrows
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
internal class ConfigRepositoryKtTest {
|
||||
internal class K3sConfigRepositoryKtTest {
|
||||
|
||||
@Test
|
||||
fun getConfig_successful() {
|
|
@ -1,4 +1,4 @@
|
|||
package org.domaindrivenarchitecture.provs.server.infrastructure.k3s
|
||||
package org.domaindrivenarchitecture.provs.server.infrastructure
|
||||
|
||||
import kotlinx.serialization.SerializationException
|
||||
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||||
|
@ -7,12 +7,13 @@ import org.domaindrivenarchitecture.provs.server.domain.k3s.Certmanager
|
|||
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Loopback
|
||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.Node
|
||||
import org.domaindrivenarchitecture.provs.server.infrastructure.k3s.getK3sConfig
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import java.io.FileNotFoundException
|
||||
|
||||
internal class ConfigRepositoryTest {
|
||||
internal class K3sConfigRepositoryTest {
|
||||
|
||||
@Test
|
||||
fun getConfig_successful() {
|
Loading…
Reference in a new issue