diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt index 52899e2..7491b67 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -86,6 +86,39 @@ fun Prov.installKubectlAndTools(): ProvResult = task { ) } + + task("install k8sConnect") { + val k8sConnectFile = "/usr/local/bin/k8s-connect.sh" + createFileFromResource( + k8sConnectFile, + "k8s-connect.sh", + resourcePath, + "555", + sudo = true + ) + } + + task("install k3sCreateContext") { + val k3sContextFile = "/usr/local/bin/k3s-create-context.sh" + createFileFromResource( + k3sContextFile, + "k3s-create-context.sh", + resourcePath, + "555", + sudo = true + ) + } + + task("install k3sConnect") { + val k3sConnectFile = "/usr/local/bin/k3s-connect.sh" + createFileFromResource( + k3sConnectFile, + "k3s-connect.sh", + resourcePath, + "555", + sudo = true + ) + } } fun Prov.installTerraform(): ProvResult = task { diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh new file mode 100644 index 0000000..9975104 --- /dev/null +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e +set -o noglob + +function main() { + local cluster_name="${1}"; shift + + /usr/local/bin/k3s-create-context.sh ${cluster_name} + kubectl config use-context ${cluster_name} + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 +} + +if [ $# -eq 1 ] +then + main $1 +else + echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" + exit -1 +fi diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh new file mode 100644 index 0000000..4e5e6a3 --- /dev/null +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -e +set -o noglob + +function main() { + local cluster_name="${1}"; shift + + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de \ + "cat /etc/rancher/k3s/k3s.yaml" | \ + 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 +} + +if [ $# -eq 1 ] +then + main $1 +else + echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" + exit -1 +fi diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh new file mode 100644 index 0000000..f01ece7 --- /dev/null +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e +set -o noglob + +function main() { + local cluster_name="${1}"; shift + + /usr/local/bin/k8s-create-context.sh ${cluster_name} + kubectl config use-context ${cluster_name} + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.meissa-gmbh.de -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 +} + +if [ $# -eq 1 ] +then + main $1 +else + echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" + exit -1 +fi diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh index 34954bd..3a16eac 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh @@ -18,4 +18,10 @@ function main() { > ~/.kube/custom-contexts/${cluster_name}.yml } -main $1 +if [ $# -eq 1 ] +then + main $1 +else + echo "Requires argument cluster_name in server fqdn {cluster_name}.meissa-gmbh.de" + exit -1 +fi