add k8s context env

This commit is contained in:
jem 2021-10-01 13:27:50 +02:00
parent 862f40432c
commit eeb767dae3

View file

@ -17,6 +17,7 @@ fun Prov.installDevOps() = def {
installYq() installYq()
} }
fun Prov.installYq( fun Prov.installYq(
version: String = "4.13.2", version: String = "4.13.2",
sha256sum: String = "d7c89543d1437bf80fee6237eadc608d1b121c21a7cbbe79057d5086d74f8d79" sha256sum: String = "d7c89543d1437bf80fee6237eadc608d1b121c21a7cbbe79057d5086d74f8d79"
@ -68,6 +69,28 @@ fun Prov.installKubectl(): ProvResult = def {
""".trimIndent() """.trimIndent()
createFile("~/.bashrc.d/ssh_alias.sh", tunnelAlias, "640") createFile("~/.bashrc.d/ssh_alias.sh", tunnelAlias, "640")
// TODO: externalize to file - trippeld excaping is realy ugly
var k8sContext = """
function main() {
local cluster_name="\$\{'$'}1"; shift
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@\$\{cluster_name}.meissa-gmbh.de \
"cat /etc/kubernetes/admin.conf" | \
yq e ".clusters[0].name=\"\$\{cluster_name}\" \
| .clusters[0].cluster.server=\"https://kubernetes:6443\" \
| .contexts[0].context.cluster=\"\$\{cluster_name}\" \
| .contexts[0].context.user=\"\$\{cluster_name}\" \
| .contexts[0].name=\"\$\{cluster_name}\" \
| del(.current-context) \
| del(.preferences) \
| .users[0].name=\"\$\{cluster_name}\"" - \
> ~/.kube/custom-contexts/\$\{cluster_name}.yml
}
main ${'$'}1
""".trimIndent()
createFile("/usr/local/bin/k8s-create-context.sh", k8sContext, "555")
aptInstall("kubectl") aptInstall("kubectl")
cmd("kubectl completion bash >> /etc/bash_completion.d/kubernetes", sudo = true) cmd("kubectl completion bash >> /etc/bash_completion.d/kubernetes", sudo = true)
} else { } else {