Compare commits

..

No commits in common. "dc4dd03f28c94bc491d1f122dd0e379e25294ce8" and "bb383ca274287a0b8cdeb4509b32d0d4c8b7cb05" have entirely different histories.

5 changed files with 36 additions and 72 deletions

View file

@ -7,8 +7,8 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.check
/**
* Adds a schedule for a monthly reboot of the (Linux) system.
* ATTENTION: Use with care!! System will be shut down, restart might not succeed in all cases.
* Adds a cronJob for a monthly reboot of the (Linux) system.
* ATTENTION: Use with care!!
*/
fun Prov.scheduleMonthlyReboot() = task {
// use controlled "shutdown" instead of direct "reboot"

View file

@ -3,6 +3,5 @@ package org.domaindrivenarchitecture.provs.server.domain.hetzner_csi
import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.server.infrastructure.provisionHetznerCSIForK8s
fun Prov.provisionHetznerCSI(configResolved: HetznerCSIConfigResolved) = task {
provisionHetznerCSIForK8s(configResolved.hcloudApiToken, configResolved.encryptionPassphrase)
}
fun Prov.provisionHetznerCSI(configResolved: HetznerCSIConfigResolved) =
provisionHetznerCSIForK8s(configResolved.hcloudApiToken, configResolved.encryptionPassphrase)

View file

@ -35,13 +35,9 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
val applicationFile = cli.applicationFileName?.let { DefaultApplicationFileRepository(cli.applicationFileName).getFile() }
provisionK3s(k3sConfigReprovision, grafanaConfigResolved, hcloudConfigResolved, applicationFile)
} else {
cli.onlyModules.forEach { module ->
when (module.uppercase()) {
ServerOnlyModule.MONTHLY_REBOOT.name -> scheduleMonthlyReboot()
ServerOnlyModule.HETZNER_CSI.name -> provisionHetznerCSI(hcloudConfigResolved)
ServerOnlyModule.GRAFANA.name -> provisionGrafana(grafanaConfigResolved)
}
}
provisionGrafana(cli.onlyModules, grafanaConfigResolved)
provisionHetznerCSI(cli.onlyModules, hcloudConfigResolved)
scheduleMonthlyRebootOnly(cli.onlyModules)
}
}
@ -95,22 +91,38 @@ fun Prov.provisionK3s(
}
private fun Prov.provisionGrafana(
onlyModules: List<String>?,
grafanaConfigResolved: GrafanaAgentConfigResolved?
) = task {
if (grafanaConfigResolved == null) {
println("ERROR: Could not find grafana config.")
exitProcess(7)
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.GRAFANA.name.lowercase())) {
if (grafanaConfigResolved == null) {
println("ERROR: Could not find grafana config.")
exitProcess(7)
}
provisionGrafanaAgent(grafanaConfigResolved)
}
provisionGrafanaAgent(grafanaConfigResolved)
}
private fun Prov.provisionHetznerCSI(
onlyModules: List<String>?,
hetznerCSIConfigResolved: HetznerCSIConfigResolved?
) = task {
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.HETZNER_CSI.name.lowercase())) {
if (hetznerCSIConfigResolved == null) {
println("ERROR: Could not find hetznerCSI config.")
exitProcess(7)
}
provisionHetznerCSI(hetznerCSIConfigResolved)
}
}
fun Prov.scheduleMonthlyRebootOnly(
onlyModules: List<String>?,
) = task {
if (onlyModules != null && onlyModules.contains(ServerOnlyModule.MONTHLY_REBOOT.name.lowercase())) {
scheduleMonthlyReboot()
}
}

View file

@ -1 +1 @@
0.39.4-SNAPSHOT (2024-12-11T21:08:51)
0.39.3-SNAPSHOT (2024-12-11T20:58:26)

View file

@ -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.remote
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.infrastructure.findHetznerCSIConfig
import org.junit.jupiter.api.Test
val dummyResult = ProvResult(true, cmd = "mocked command")
class ApplicationKtTest {
@Test
fun test_main_with_only_monthly_reboot() {
// given
@ -35,65 +26,27 @@ class ApplicationKtTest {
mockkStatic(::remote)
every { remote(any(), any(), any(), any()) } returns dummyProv
mockkStatic(Prov::provisionHetznerCSI)
every { any<Prov>().provisionHetznerCSI(any()) } returns dummyResult
mockkStatic(Prov::scheduleMonthlyReboot)
every { any<Prov>().scheduleMonthlyReboot() } returns dummyResult
every { any<Prov>().scheduleMonthlyReboot() } returns ProvResult(
true,
cmd = "mocked command"
)
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
main(arrayOf("k3s", "user123:pw@host123.meissa", "-o", "monthly_reboot"))
//then
verify(exactly = 1) { any<Prov>().scheduleMonthlyReboot() }
verify(exactly = 0) { any<Prov>().provisionHetznerCSI(any()) }
verify(exactly = 0) { any<Prov>().provisionK3s(any(), any(), any(), any()) }
// cleanup
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()
}
}