Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cezarsa
Last active March 17, 2021 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cezarsa/d232bcfcf6e3960d33e84a965007dd76 to your computer and use it in GitHub Desktop.
Save cezarsa/d232bcfcf6e3960d33e84a965007dd76 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
TSURU_TARGET=${TSURU_TARGET:-https://tsuru.globoi.com}
TSURU_TOKEN=${TSURU_TOKEN:-$(cat ~/.tsuru/token)}
target=$(sed "s|/$||g" <<<$TSURU_TARGET)
clusters="$(curl -fsS -H"Authorization: bearer ${TSURU_TOKEN}" ${target}/provisioner/clusters)"
clusters_len=$(jq '. | length' <<<$clusters)
for ((i=0;i<$clusters_len;i++)); do
cluster_data=$(jq ".[$i]" <<<$clusters)
name=$(jq -r ".name" <<<$cluster_data)
addr=$(jq -r ".addresses[0]" <<<$cluster_data)
cacert=$(jq -r ".cacert" <<<$cluster_data)
token=$(jq -r ".custom_data.token" <<<$cluster_data)
clientcert=$(jq -r ".clientcert" <<<$cluster_data)
clientkey=$(jq -r ".clientkey" <<<$cluster_data)
kubectl config set-cluster "tsuru-${name}" --server=${addr}
if [[ $cacert != "null" ]]; then
kubectl config set "clusters.tsuru-${name}.certificate-authority-data" ${cacert}
fi
if [[ $token != "null" ]]; then
kubectl config set-credentials "tsuru-${name}" --token=${token}
elif [[ $clientcert != "null" ]]; then
kubectl config set-credentials "tsuru-${name}"
kubectl config set "users.tsuru-${name}.client-certificate-data" ${clientcert}
kubectl config set "users.tsuru-${name}.client-key-data" ${clientkey}
fi
kubectl config set-context "tsuru-${name}" --cluster="tsuru-${name}" --user="tsuru-${name}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment