Skip to content

Commit

Permalink
feat: seamless configuration for pulling kubeconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Dec 20, 2023
1 parent 765558d commit 7509ce3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ env:

includes:
util: tasks/Taskfile.util.yaml
kubectl: tasks/Taskfile.kubectl.yaml
suicune:opal-ruby:
taskfile: tasks/Taskfile.cluster.yaml
vars:
Expand Down
32 changes: 32 additions & 0 deletions scripts/local/update-kubectl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -eou pipefail

L=$(echo "$LANDSCAPE" | tr '[:upper:]' '[:lower:]')
C=$(echo "$CLUSTER" | tr '[:upper:]' '[:lower:]')

name="${L}-${C}"

# wait for virtual cluster to be ready
echo "⌛️ Waiting for cluster '$name' to be ready..."
kubectl --context "${name}" -n pichu wait --for=jsonpath=.status.readyReplicas=1 --timeout=300s deployment "${L}-pichu-iodine"
kubectl --context "${name}" -n pikachu wait --for=jsonpath=.status.readyReplicas=1 --timeout=300s deployment "${L}-pikachu-iodine"
kubectl --context "${name}" -n raichu wait --for=jsonpath=.status.readyReplicas=1 --timeout=300s deployment "${L}-raichu-iodine"

echo "✅ Virtual clusters are ready!"

pichu_kube=$(kubectl get secrets --context "${name}" -n pichu "vc-${L}-pichu-iodine" -o jsonpath='{.data.config}' | base64 -d)
pikachu_kube=$(kubectl get secrets --context "${name}" -n pikachu "vc-${L}-pikachu-iodine" -o jsonpath='{.data.config}' | base64 -d)
raichu_kube=$(kubectl get secrets --context "${name}" -n raichu "vc-${L}-raichu-iodine" -o jsonpath='{.data.config}' | base64 -d)

echo "📝 Writing to '$HOME/.kube/k3dconfigs/pichu-${C}'"
echo "${pichu_kube}" >"$HOME/.kube/k3dconfigs/pichu-${C}"
echo "📝 Writing to '$HOME/.kube/k3dconfigs/pikachu-${C}'"
echo "${pikachu_kube}" >"$HOME/.kube/k3dconfigs/pikachu-${C}"
echo "📝 Writing to '$HOME/.kube/k3dconfigs/raichu-${C}'"
echo "${raichu_kube}" >"$HOME/.kube/k3dconfigs/raichu-${C}"

echo "🛠️ Attempting to merge kubeconfig cluster '$name'..."
KUBECONFIG=$(cd ~/.kube/configs && find "$(pwd)"/* | awk 'ORS=":"')$(cd ~/.kube/k3dconfigs && find "$(pwd)"/* | awk 'ORS=":"') kubectl config view --flatten >~/.kube/config
chmod 600 ~/.kube/config
echo "✅ Config is merged!"
17 changes: 17 additions & 0 deletions tasks/Taskfile.kubectl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

tasks:
entei:opal:
desc: Obtain Entei Opal Virtual Cluster KubeConfigs
env:
CLUSTER: opal
LANDSCAPE: entei
cmds:
- ./scripts/local/update-kubectl.sh
entei:ruby:
desc: Obtain Entei Ruby Virtual Cluster KubeConfigs
env:
CLUSTER: ruby
LANDSCAPE: entei
cmds:
- ./scripts/local/update-kubectl.sh

0 comments on commit 7509ce3

Please sign in to comment.