Compare commits
No commits in common. "dc4dd03f28c94bc491d1f122dd0e379e25294ce8" and "bb383ca274287a0b8cdeb4509b32d0d4c8b7cb05" have entirely different histories.
dc4dd03f28
...
bb383ca274
5 changed files with 36 additions and 72 deletions
|
@ -7,8 +7,8 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.check
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a schedule for a monthly reboot of the (Linux) system.
|
* Adds a cronJob for a monthly reboot of the (Linux) system.
|
||||||
* ATTENTION: Use with care!! System will be shut down, restart might not succeed in all cases.
|
* ATTENTION: Use with care!!
|
||||||
*/
|
*/
|
||||||
fun Prov.scheduleMonthlyReboot() = task {
|
fun Prov.scheduleMonthlyReboot() = task {
|
||||||
// use controlled "shutdown" instead of direct "reboot"
|
// use controlled "shutdown" instead of direct "reboot"
|
||||||
|
|
|
@ -3,6 +3,5 @@ package org.domaindrivenarchitecture.provs.server.domain.hetzner_csi
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||||
import org.domaindrivenarchitecture.provs.server.infrastructure.provisionHetznerCSIForK8s
|
import org.domaindrivenarchitecture.provs.server.infrastructure.provisionHetznerCSIForK8s
|
||||||
|
|
||||||
fun Prov.provisionHetznerCSI(configResolved: HetznerCSIConfigResolved) = task {
|
fun Prov.provisionHetznerCSI(configResolved: HetznerCSIConfigResolved) =
|
||||||
provisionHetznerCSIForK8s(configResolved.hcloudApiToken, configResolved.encryptionPassphrase)
|
provisionHetznerCSIForK8s(configResolved.hcloudApiToken, configResolved.encryptionPassphrase)
|
||||||
}
|
|
|
@ -35,13 +35,9 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
|
||||||
val applicationFile = cli.applicationFileName?.let { DefaultApplicationFileRepository(cli.applicationFileName).getFile() }
|
val applicationFile = cli.applicationFileName?.let { DefaultApplicationFileRepository(cli.applicationFileName).getFile() }
|
||||||
provisionK3s(k3sConfigReprovision, grafanaConfigResolved, hcloudConfigResolved, applicationFile)
|
provisionK3s(k3sConfigReprovision, grafanaConfigResolved, hcloudConfigResolved, applicationFile)
|
||||||
} else {
|
} else {
|
||||||
cli.onlyModules.forEach { module ->
|
provisionGrafana(cli.onlyModules, grafanaConfigResolved)
|
||||||
when (module.uppercase()) {
|
provisionHetznerCSI(cli.onlyModules, hcloudConfigResolved)
|
||||||
ServerOnlyModule.MONTHLY_REBOOT.name -> scheduleMonthlyReboot()
|
scheduleMonthlyRebootOnly(cli.onlyModules)
|
||||||
ServerOnlyModule.HETZNER_CSI.name -> provisionHetznerCSI(hcloudConfigResolved)
|
|
||||||
ServerOnlyModule.GRAFANA.name -> provisionGrafana(grafanaConfigResolved)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,22 +91,38 @@ fun Prov.provisionK3s(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Prov.provisionGrafana(
|
private fun Prov.provisionGrafana(
|
||||||
|
onlyModules: List<String>?,
|
||||||
grafanaConfigResolved: GrafanaAgentConfigResolved?
|
grafanaConfigResolved: GrafanaAgentConfigResolved?
|
||||||
) = task {
|
) = task {
|
||||||
|
|
||||||
|
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.GRAFANA.name.lowercase())) {
|
||||||
if (grafanaConfigResolved == null) {
|
if (grafanaConfigResolved == null) {
|
||||||
println("ERROR: Could not find grafana config.")
|
println("ERROR: Could not find grafana config.")
|
||||||
exitProcess(7)
|
exitProcess(7)
|
||||||
}
|
}
|
||||||
provisionGrafanaAgent(grafanaConfigResolved)
|
provisionGrafanaAgent(grafanaConfigResolved)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Prov.provisionHetznerCSI(
|
private fun Prov.provisionHetznerCSI(
|
||||||
|
onlyModules: List<String>?,
|
||||||
hetznerCSIConfigResolved: HetznerCSIConfigResolved?
|
hetznerCSIConfigResolved: HetznerCSIConfigResolved?
|
||||||
) = task {
|
) = task {
|
||||||
|
|
||||||
|
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.HETZNER_CSI.name.lowercase())) {
|
||||||
if (hetznerCSIConfigResolved == null) {
|
if (hetznerCSIConfigResolved == null) {
|
||||||
println("ERROR: Could not find hetznerCSI config.")
|
println("ERROR: Could not find hetznerCSI config.")
|
||||||
exitProcess(7)
|
exitProcess(7)
|
||||||
}
|
}
|
||||||
provisionHetznerCSI(hetznerCSIConfigResolved)
|
provisionHetznerCSI(hetznerCSIConfigResolved)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Prov.scheduleMonthlyRebootOnly(
|
||||||
|
onlyModules: List<String>?,
|
||||||
|
) = task {
|
||||||
|
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.MONTHLY_REBOOT.name.lowercase())) {
|
||||||
|
scheduleMonthlyReboot()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.39.4-SNAPSHOT (2024-12-11T21:08:51)
|
0.39.3-SNAPSHOT (2024-12-11T20:58:26)
|
|
@ -7,20 +7,11 @@ import org.domaindrivenarchitecture.provs.framework.core.local
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
|
import org.domaindrivenarchitecture.provs.framework.core.processors.DummyProcessor
|
||||||
import org.domaindrivenarchitecture.provs.framework.core.remote
|
import org.domaindrivenarchitecture.provs.framework.core.remote
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.scheduledjobs.domain.scheduleMonthlyReboot
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.scheduledjobs.domain.scheduleMonthlyReboot
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSourceType
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSupplier
|
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.hetzner_csi.HetznerCSIConfig
|
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.hetzner_csi.provisionHetznerCSI
|
|
||||||
import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s
|
import org.domaindrivenarchitecture.provs.server.domain.k3s.provisionK3s
|
||||||
import org.domaindrivenarchitecture.provs.server.infrastructure.findHetznerCSIConfig
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
|
||||||
val dummyResult = ProvResult(true, cmd = "mocked command")
|
|
||||||
|
|
||||||
|
|
||||||
class ApplicationKtTest {
|
class ApplicationKtTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun test_main_with_only_monthly_reboot() {
|
fun test_main_with_only_monthly_reboot() {
|
||||||
// given
|
// given
|
||||||
|
@ -35,65 +26,27 @@ class ApplicationKtTest {
|
||||||
mockkStatic(::remote)
|
mockkStatic(::remote)
|
||||||
every { remote(any(), any(), any(), any()) } returns dummyProv
|
every { remote(any(), any(), any(), any()) } returns dummyProv
|
||||||
|
|
||||||
mockkStatic(Prov::provisionHetznerCSI)
|
|
||||||
every { any<Prov>().provisionHetznerCSI(any()) } returns dummyResult
|
|
||||||
|
|
||||||
mockkStatic(Prov::scheduleMonthlyReboot)
|
mockkStatic(Prov::scheduleMonthlyReboot)
|
||||||
every { any<Prov>().scheduleMonthlyReboot() } returns dummyResult
|
every { any<Prov>().scheduleMonthlyReboot() } returns ProvResult(
|
||||||
|
true,
|
||||||
|
cmd = "mocked command"
|
||||||
|
)
|
||||||
|
|
||||||
mockkStatic(Prov::provisionK3s)
|
mockkStatic(Prov::provisionK3s)
|
||||||
every { any<Prov>().provisionK3s(any(), any(), any(), any()) } returns dummyResult
|
every { any<Prov>().provisionK3s(any(), any(), any(), any()) } returns ProvResult(
|
||||||
|
true,
|
||||||
|
cmd = "mocked command"
|
||||||
|
)
|
||||||
|
|
||||||
// when
|
// when
|
||||||
main(arrayOf("k3s", "user123:pw@host123.meissa", "-o", "monthly_reboot"))
|
main(arrayOf("k3s", "user123:pw@host123.meissa", "-o", "monthly_reboot"))
|
||||||
|
|
||||||
//then
|
//then
|
||||||
verify(exactly = 1) { any<Prov>().scheduleMonthlyReboot() }
|
verify(exactly = 1) { any<Prov>().scheduleMonthlyReboot() }
|
||||||
verify(exactly = 0) { any<Prov>().provisionHetznerCSI(any()) }
|
|
||||||
verify(exactly = 0) { any<Prov>().provisionK3s(any(), any(), any(), any()) }
|
verify(exactly = 0) { any<Prov>().provisionK3s(any(), any(), any(), any()) }
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
unmockkAll()
|
unmockkAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun test_main_with_only_hetzner_csi() {
|
|
||||||
// given
|
|
||||||
val dummyProv = Prov.newInstance(DummyProcessor())
|
|
||||||
|
|
||||||
mockkObject(Prov)
|
|
||||||
every { Prov.newInstance(any(), any(), any(), any()) } returns dummyProv
|
|
||||||
|
|
||||||
mockkStatic(::local)
|
|
||||||
every { local() } returns dummyProv
|
|
||||||
|
|
||||||
mockkStatic(::remote)
|
|
||||||
every { remote(any(), any(), any(), any()) } returns dummyProv
|
|
||||||
|
|
||||||
mockkStatic(::findHetznerCSIConfig)
|
|
||||||
every { findHetznerCSIConfig(any()) } returns HetznerCSIConfig(
|
|
||||||
hcloudApiToken = SecretSupplier(SecretSourceType.PLAIN,"dummy"),
|
|
||||||
encryptionPassphrase = SecretSupplier(SecretSourceType.PLAIN,"dummy"),
|
|
||||||
)
|
|
||||||
|
|
||||||
mockkStatic(Prov::provisionHetznerCSI)
|
|
||||||
every { any<Prov>().provisionHetznerCSI(any()) } returns dummyResult
|
|
||||||
|
|
||||||
mockkStatic(Prov::scheduleMonthlyReboot)
|
|
||||||
every { any<Prov>().scheduleMonthlyReboot() } returns dummyResult
|
|
||||||
|
|
||||||
mockkStatic(Prov::provisionK3s)
|
|
||||||
every { any<Prov>().provisionK3s(any(), any(), any(), any()) } returns dummyResult
|
|
||||||
|
|
||||||
// when
|
|
||||||
main(arrayOf("k3s", "user123:pw@host123.meissa", "-o", "hetzner_csi"))
|
|
||||||
|
|
||||||
//then
|
|
||||||
verify(exactly = 1) { any<Prov>().provisionHetznerCSI(any()) }
|
|
||||||
verify(exactly = 0) { any<Prov>().scheduleMonthlyReboot() }
|
|
||||||
verify(exactly = 0) { any<Prov>().provisionK3s(any(), any(), any(), any()) }
|
|
||||||
|
|
||||||
// cleanup
|
|
||||||
unmockkAll()
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue