You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1.1 KiB
Kotlin
26 lines
1.1 KiB
Kotlin
2 years ago
|
package org.domaindrivenarchitecture.provs.server.infrastructure.k3s
|
||
|
|
||
2 years ago
|
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
|
||
2 years ago
|
import org.domaindrivenarchitecture.provs.framework.core.readFromFile
|
||
2 years ago
|
import org.domaindrivenarchitecture.provs.framework.core.toYaml
|
||
|
import org.domaindrivenarchitecture.provs.framework.core.writeToFile
|
||
2 years ago
|
import org.domaindrivenarchitecture.provs.framework.core.yamlToType
|
||
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.K3sConfig
|
||
2 years ago
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.Node
|
||
|
import java.io.File
|
||
2 years ago
|
|
||
2 years ago
|
private const val DEFAULT_CONFIG_FILE = "server-config.yaml"
|
||
2 years ago
|
|
||
2 years ago
|
fun getK3sConfig(fileName: ConfigFileName? = null): K3sConfig {
|
||
2 years ago
|
val filename = fileName?.fileName ?: DEFAULT_CONFIG_FILE
|
||
2 years ago
|
|
||
|
if ((filename.substringAfterLast("/") == DEFAULT_CONFIG_FILE) && !File(filename).exists()) {
|
||
|
writeK3sConfig(ConfigFileName(filename), K3sConfig("localhost", Node("127.0.0.1"), apple = true))
|
||
2 years ago
|
}
|
||
2 years ago
|
return readFromFile(filename).yamlToType()
|
||
|
}
|
||
|
|
||
|
fun writeK3sConfig(fileName: ConfigFileName, config: K3sConfig) {
|
||
|
writeToFile(fileName.fileName, config.toYaml())
|
||
2 years ago
|
}
|