Last active
October 18, 2018 17:15
-
-
Save stormbeta/c9ada0489cb7a215a4568c637e8056e2 to your computer and use it in GitHub Desktop.
Config Helper for kubectl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# Intended for use in your bashrc config | |
function reload-kubeconfigs { | |
# Combine kubeconfigs into ':'-delimited list as KUBECONFIG, which will be auto-merged by kubectl | |
local default="${HOME}/.kube/config" | |
local config_dir="${HOME}/.kube/config.d" | |
local config_paths="" | |
[[ ! -d "$config_dir" ]] && mkdir -p "$config_dir" | |
function __join { local IFS="$1"; shift; echo "$*"; } | |
if [[ -n "$(ls "$config_dir")" ]]; then | |
local configs=( "${config_dir}/"* ) | |
config_paths="$(__join : "${configs[@]}")" | |
fi | |
if [[ -f "$default" ]]; then | |
config_paths="${default}:${config_paths}" | |
fi | |
export KUBECONFIG="$config_paths" | |
} | |
reload-kubeconfigs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment