Merge branch 'master' of gitlab.com:domaindrivenarchitecture/provs

This commit is contained in:
jerger 2022-11-25 21:24:19 +01:00
commit 85b999245b
3 changed files with 15 additions and 13 deletions

View file

@ -18,7 +18,7 @@ apply plugin: "kotlinx-serialization"
group = "org.domaindrivenarchitecture.provs"
version = "0.16.1-SNAPSHOT"
version = "0.17.1-SNAPSHOT"
repositories {
mavenCentral()

View file

@ -15,10 +15,8 @@ fun Prov.provisionK3sCommand(cli: K3sCliCommand) = task {
val k3sConfig: K3sConfig = getK3sConfig(cli.configFileName)
DefaultApplicationFileRepository().assertExists(cli.applicationFileName)
if (cli.reprovision || k3sConfig.reprovision) {
deprovisionK3sInfra()
}
provisionK3s(k3sConfig, grafanaConfigResolved, cli.applicationFileName)
val k3sConfigReprovision = k3sConfig.copy(reprovision = cli.reprovision || k3sConfig.reprovision)
provisionK3s(k3sConfigReprovision, grafanaConfigResolved, cli.applicationFileName)
} else {
provisionGrafana(cli.onlyModules, grafanaConfigResolved)
}
@ -32,6 +30,10 @@ fun Prov.provisionK3s(
grafanaConfigResolved: GrafanaAgentConfigResolved? = null,
applicationFileName: ApplicationFileName? = null) = task {
if (k3sConfig.reprovision) {
deprovisionK3sInfra()
}
provisionNetwork(k3sConfig)
installK3s(k3sConfig)

View file

@ -111,7 +111,7 @@ fun Prov.installK3s(k3sConfig: K3sConfig): ProvResult {
}
applyK3sFileFromResource(localPathProvisionerConfig)
cmd("kubectl set env deployment -n kube-system local-path-provisioner DEPLOY_DATE=\"$(date)\"")
cmd("kubectl set env deployment -n kube-system local-path-provisioner DEPLOY_DATE=\"$(date)\"", sudo = true)
cmd("ln -sf $k3sKubeConfig " + k8sCredentialsDir + "admin.conf", sudo = true)
@ -160,13 +160,13 @@ fun Prov.provisionK3sApplication(applicationFileName: ApplicationFileName) = tas
}
// ============================ private and internal functions =============================
// ============================ functions to create k3s files and apply =============================
internal fun Prov.applyK3sFile(file: File) = task {
fun Prov.applyK3sFile(file: File) = task {
cmd("kubectl apply -f ${file.path}", sudo = true)
}
private fun Prov.createK3sFileFromResource(
fun Prov.createK3sFileFromResource(
file: File,
posixFilePermission: FileMode? = "644"
) = task {
@ -179,12 +179,12 @@ private fun Prov.createK3sFileFromResource(
)
}
private fun Prov.applyK3sFileFromResource(file: File, posixFilePermission: String? = "644") = task {
fun Prov.applyK3sFileFromResource(file: File, posixFilePermission: String? = "644") = task {
createK3sFileFromResource(file, posixFilePermission)
applyK3sFile(file)
}
private fun Prov.applyK3sFileFromResourceTemplate(
fun Prov.applyK3sFileFromResourceTemplate(
file: File,
values: Map<String, String>,
posixFilePermission: String? = "644",
@ -194,7 +194,7 @@ private fun Prov.applyK3sFileFromResourceTemplate(
applyK3sFile(file)
}
private fun Prov.createK3sFileFromResourceTemplate(
fun Prov.createK3sFileFromResourceTemplate(
file: File,
values: Map<String, String>,
posixFilePermission: String? = "644",
@ -215,5 +215,5 @@ private fun File.templateName(): String {
}
internal fun Prov.configureShellAliases() = task {
addTextToFile( "\nalias k=kubectl\n", File(".bash_aliases",))
addTextToFile( "\nalias k=\"sudo kubectl\"\n", File(".bash_aliases",))
}