add alias k=kubectl to k3s
This commit is contained in:
parent
0f5afd9825
commit
5fd7ab588f
4 changed files with 68 additions and 1 deletions
|
@ -72,7 +72,7 @@ For the remote server please configure a config file (default file name: server-
|
|||
fqdn: "myhostname.com"
|
||||
node:
|
||||
ipv4: "192.168.56.123" # ip address
|
||||
echo: true # for demo reasons only - deploy an echo app
|
||||
echo: true # for demo reasons only - deploys an echo app
|
||||
```
|
||||
|
||||
To add a grafana agent to your k3s installation add the following to the config:
|
||||
|
|
|
@ -219,6 +219,10 @@ fun Prov.fileContentLargeFile(file: String, sudo: Boolean = false, chunkSize: In
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends text at the end of the specified file. Creates the file if not yet existing.
|
||||
* If doNotAddIfExisting is true, then the text is not added (again) if already contained somewhere in the file.
|
||||
*/
|
||||
fun Prov.addTextToFile(
|
||||
text: String,
|
||||
file: File,
|
||||
|
|
|
@ -110,6 +110,8 @@ fun Prov.installK3s(k3sConfig: K3sConfig): ProvResult {
|
|||
cmd("kubectl set env deployment -n kube-system local-path-provisioner DEPLOY_DATE=\"$(date)\"")
|
||||
|
||||
cmd("ln -sf $k3sKubeConfig " + k8sCredentialsDir + "admin.conf", sudo = true)
|
||||
|
||||
configureShellAliases()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -205,3 +207,7 @@ private fun Prov.createK3sFileFromResourceTemplate(
|
|||
private fun File.templateName(): String {
|
||||
return this.name.replace(".yaml", ".template.yaml")
|
||||
}
|
||||
|
||||
internal fun Prov.configureShellAliases() = task {
|
||||
addTextToFile( "\nalias k=kubectl\n", File(".bash_aliases",))
|
||||
}
|
|
@ -494,4 +494,61 @@ internal class FilesystemKtTest {
|
|||
assertTrue(linkExists)
|
||||
assertEquals("textinlinkfilesudo", content)
|
||||
}
|
||||
|
||||
@ContainerTest
|
||||
fun test_addTextToFile() {
|
||||
// given
|
||||
val prov = defaultTestContainer()
|
||||
val file = "testfile_with_added_text"
|
||||
val text1 = "added text"
|
||||
val text2 = "\nadded text2\n"
|
||||
prov.deleteFile(file)
|
||||
|
||||
// when
|
||||
val res = prov.addTextToFile(text1, File(file)) // add text to non-existing file
|
||||
val containsText = prov.fileContainsText(file, text1)
|
||||
val res2 = prov.addTextToFile(text1, File(file)) // test idempotence
|
||||
val fileContent2 = prov.fileContent(file)
|
||||
|
||||
val res3 = prov.addTextToFile(text2, File(file)) // add second text
|
||||
val containsText3 = prov.fileContainsText(file, text1)
|
||||
val res4 = prov.addTextToFile(text1, File(file)) // test idempotence
|
||||
val fileContent4 = prov.fileContent(file)
|
||||
|
||||
// then
|
||||
assertTrue(res.success)
|
||||
assertTrue(containsText)
|
||||
assertTrue(res2.success)
|
||||
assertEquals(text1, fileContent2)
|
||||
|
||||
assertTrue(res3.success)
|
||||
assertTrue(containsText3)
|
||||
assertTrue(res4.success)
|
||||
assertEquals(text1 + text2, fileContent4)
|
||||
}
|
||||
@ContainerTest
|
||||
fun test_addTextToFile_with_doNotAddIfExisting_false() {
|
||||
// given
|
||||
val prov = defaultTestContainer()
|
||||
val file = "testfile_with_added_text_2"
|
||||
val text1 = "added text1"
|
||||
val text2 = "\nadded text2\n"
|
||||
prov.deleteFile(file)
|
||||
|
||||
// when
|
||||
val res = prov.addTextToFile(text1, File(file), doNotAddIfExisting = false) // add text to non-existing file
|
||||
val res2 = prov.addTextToFile(text1, File(file), doNotAddIfExisting = false) // add again
|
||||
|
||||
val res3 = prov.addTextToFile(text2, File(file), doNotAddIfExisting = false) // add second text
|
||||
val res4 = prov.addTextToFile(text1, File(file), doNotAddIfExisting = false) // add first text again
|
||||
val fileContent = prov.fileContent(file)
|
||||
|
||||
// then
|
||||
assertTrue(res.success)
|
||||
assertTrue(res2.success)
|
||||
|
||||
assertTrue(res3.success)
|
||||
assertTrue(res4.success)
|
||||
assertEquals(text1 + text1 + text2 + text1, fileContent)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue