From 37064bbfb0ca97b3c68f464b1ee2597905432cf7 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 28 May 2019 14:53:02 +0200 Subject: [PATCH] Select environments in bin/get-k8s-master-configs --- bin/get-k8s-master-configs | 53 +++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/bin/get-k8s-master-configs b/bin/get-k8s-master-configs index 6bfc3e4..0905b8d 100755 --- a/bin/get-k8s-master-configs +++ b/bin/get-k8s-master-configs @@ -7,7 +7,7 @@ VERBOSE="n" DEBUG="n" QUIET='n' -VERSION="0.1" +VERSION="0.2" # console colors: RED="" @@ -24,6 +24,24 @@ BASE_DIR="$(dirname ${0})" REL_K8S_CFGDIR='.kube' REL_K8S_CFGFILE='config.yaml' +declare -A ENV_HOST=() +declare -A ENV_PORT=() +declare -A ENV_USER=() +declare -A ENV_GROUP=() +declare -A ENV_HOME=() + +ENV_HOST['live']='live-master01-k8s-spk.spk.pixelpark.net' +ENV_HOST['stage']='stage-master01-k8s-spk.spk.pixelpark.net' + +ENV_PORT['live']=1080 +ENV_PORT['stage']=1080 + +ENV_USER['live']='k8s-live' +ENV_USER['stage']='k8s-stage' + +ENV_GROUP['live']='users' +ENV_GROUP['stage']='users' + #------------------------------------------------------------------- detect_color() { @@ -171,6 +189,12 @@ get_options() { exit 1 fi + if [[ "$( type -t curl || true )" != "file" ]] ; then + error "Command '${RED}curl${NORMAL}' not found, please install the appropriate package." + echo >&2 + exit 5 + fi + local cur_user_id=$( id -u ) if [[ "${cur_user_id}" != "0" ]] ; then error "Wrong user '${RED}$( id -u -n )${NORMAL}'." @@ -217,6 +241,31 @@ error() { echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2 } +#------------------------------------------------------------------------------ +get_config() { + + local env="$1" + + info "Get current Kubernetes configuration for environment '${GREEN}${env}${NORMAL}'." + + local host="${ENV_HOST[${env}]}" + local port="${ENV_PORT[${env}]}" + local user="${ENV_USER[${env}]}" + local group="${ENV_GROUP[${env}]}" + + local url="http://${host}" + if [[ "${port}" != "80" ]] ; then + url+=":${port}" + fi + url+="/" + debug "URL to get the config: '${url}'." + + local user_home=$( getent passwd "${user}" | head -n 1 | awk -F: '{print $6}' ) + debug "Home diectory of user '${user}': '${user_home}'" + + +} + ################################################################################ ## ## Main @@ -227,6 +276,8 @@ error() { main() { get_options "$@" + get_config 'live' + get_config 'stage' } -- 2.39.5