[skip ci] add k3s waiting for cert-manager
This commit is contained in:
parent
79eccf9755
commit
8846c9c170
3 changed files with 47 additions and 17 deletions
|
@ -79,23 +79,44 @@ fun Prov.createFile(
|
|||
fullyQualifiedFilename: String,
|
||||
text: String?,
|
||||
posixFilePermission: String? = null,
|
||||
sudo: Boolean = false
|
||||
): ProvResult =
|
||||
def {
|
||||
val withSudo = if (sudo) "sudo " else ""
|
||||
posixFilePermission?.let {
|
||||
ensureValidPosixFilePermission(posixFilePermission)
|
||||
cmd(withSudo + "install -m $posixFilePermission /dev/null $fullyQualifiedFilename")
|
||||
}
|
||||
if (text != null) {
|
||||
sudo: Boolean = false,
|
||||
overwriteIfExisting: Boolean = false
|
||||
): ProvResult = task {
|
||||
val maxBlockSize = 100000
|
||||
|
||||
if (!overwriteIfExisting && fileExists(fullyQualifiedFilename, sudo)) {
|
||||
return@task ProvResult(true, "File $fullyQualifiedFilename already existing.")
|
||||
}
|
||||
val withSudo = if (sudo) "sudo " else ""
|
||||
|
||||
posixFilePermission?.let {
|
||||
ensureValidPosixFilePermission(posixFilePermission)
|
||||
}
|
||||
val modeOption = posixFilePermission?.let { "-m $it"} ?: ""
|
||||
|
||||
// create empty file resp. clear file
|
||||
cmd(withSudo + "install $modeOption /dev/null $fullyQualifiedFilename")
|
||||
|
||||
if (text != null) {
|
||||
if (text.length <= maxBlockSize) {
|
||||
cmd(
|
||||
"printf '%s' " + text
|
||||
.escapeAndEncloseByDoubleQuoteForShell() + " | ${if (sudo) "sudo" else ""} tee $fullyQualifiedFilename > /dev/null"
|
||||
)
|
||||
} else {
|
||||
cmd(withSudo + "touch $fullyQualifiedFilename")
|
||||
val chunkedTest = text.chunked(maxBlockSize)
|
||||
for (chunk in chunkedTest) {
|
||||
cmd(
|
||||
"printf '%s' " + chunk
|
||||
.escapeAndEncloseByDoubleQuoteForShell() + " | ${if (sudo) "sudo" else ""} tee -a $fullyQualifiedFilename > /dev/null"
|
||||
)
|
||||
}
|
||||
ProvResult(true) // dummy
|
||||
}
|
||||
} else {
|
||||
cmd(withSudo + "touch $fullyQualifiedFilename")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun Prov.createSecretFile(
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.domaindrivenarchitecture.provs.server.infrastructure
|
|||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.Prov
|
||||
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
|
||||
import org.domaindrivenarchitecture.provs.framework.core.repeatTaskUntilSuccess
|
||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.*
|
||||
|
||||
private const val k3sConfigFile = "/etc/rancher/k3s/config.yaml"
|
||||
|
@ -132,7 +133,10 @@ fun Prov.provisionK3sCertManager(endpoint: CertManagerEndPoint) = task {
|
|||
sudo = true
|
||||
)
|
||||
cmd("kubectl apply -f $certManagerDeployment", sudo = true)
|
||||
cmd("kubectl apply -f $certManagerIssuer", sudo = true)
|
||||
|
||||
repeatTaskUntilSuccess(10, 10) {
|
||||
cmd("kubectl apply -f $certManagerIssuer", sudo = true)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base
|
||||
|
||||
import org.domaindrivenarchitecture.provs.framework.core.getResourceAsText
|
||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||
import org.domaindrivenarchitecture.provs.test.testLocal
|
||||
|
@ -39,18 +40,22 @@ internal class FilesystemKtTest {
|
|||
@ContainerTest
|
||||
fun test_createFile_in_container() {
|
||||
// given
|
||||
val prov = defaultTestContainer()
|
||||
val filename = "testfile8"
|
||||
val prov = testLocal() //defaultTestContainer()
|
||||
val filename = "tmp/testfile11"
|
||||
|
||||
val testtext = getResourceAsText("org/domaindrivenarchitecture/provs/infrastructure/k3s/" + "cert-manager.yaml")
|
||||
|
||||
println("aaaaaaaaaaaaaaaaaa len: " + testtext.length)
|
||||
|
||||
// when
|
||||
val res = prov.createFile(filename, testtext)
|
||||
val res2 = prov.createFile("sudo$filename", testtext, sudo = true)
|
||||
val res = prov.createFile(filename, testtext, overwriteIfExisting = true)
|
||||
// val res2 = prov.createFile("sudo$filename", testtext, sudo = true)
|
||||
|
||||
// then
|
||||
assertTrue(res.success)
|
||||
assertTrue(res2.success)
|
||||
// assertTrue(res2.success)
|
||||
assertEquals(testtext, prov.fileContent(filename))
|
||||
assertEquals(testtext, prov.fileContent("sudo$filename"))
|
||||
// assertEquals(testtext, prov.fileContent("sudo$filename"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue