Skip to content

Instantly share code, notes, and snippets.

@rvennam
Forked from dcberg/iks-merged-config.sh
Created February 1, 2019 04:21
Show Gist options
  • Save rvennam/8ea62f0929c5ddb99ce3ff010e39b7d9 to your computer and use it in GitHub Desktop.
Save rvennam/8ea62f0929c5ddb99ce3ff010e39b7d9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# IBM Cloud Kubernetes Service cluster config dir
clustersdir=~/.bluemix/plugins/container-service/clusters
#Produce a Kubernetes merged config string to be used with the KUBECONF environment variable.
# CHANGE VALUE
# Note the value is the IBM ID used to log into ibmcloud. This is the same
# value that appears in the downloaded IKS cluster config files for the
# context user field.
username="rvennam@us.ibm.com" #set to IBM ID used with ibmcloud login
mergedconfig="$HOME/.kube/config"
while IFS= read -r -d '' file
do
clustername=$(awk '/current-context/{print $2}' < $file)
sed -i.bak "/$clustername-$username/!s/$username/$clustername-$username/g" $file && rm $file.bak
mergedconfig="$mergedconfig:$file"
done < <(find $clustersdir -type f -name "*.yml" -print0)
echo $mergedconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment