diff --git a/etc/prole_cfg.sh b/etc/prole_cfg.sh index 4f45ff3..bdf745c 100644 --- a/etc/prole_cfg.sh +++ b/etc/prole_cfg.sh @@ -743,16 +743,47 @@ if [[ -n "$_prole_cfg_file" ]]; then if [[ -z "$_cfg_ctx" ]]; then _cfg_ctx=$(_prole_cfg_extract_key_in_files "KUBECONTEXT" "${_prole_cfg_files[@]}") fi + _cfg_mode_hint=$(prole_normalize_mode "${DEPLOYMENT_MODE:-${PROLE_MODE:-${CLUSTER_ENV:-${prole_mode:-}}}}") + _cfg_app_ctx="${APP_CLUSTER_KUBECONTEXT:-${init_cluster_app_cluster_kubecontext:-}}" + if [[ "$_cfg_mode_hint" == "k8s" ]]; then + if [[ -z "$_cfg_app_ctx" ]]; then + _cfg_app_ctx=$(_prole_cfg_extract_key_in_files "APP_CLUSTER_KUBECONTEXT" "${_prole_cfg_files[@]}") + fi + if [[ -z "$_cfg_app_ctx" ]]; then + _cfg_app_ctx=$(_prole_cfg_extract_key_in_files "app_cluster_kubecontext" "${_prole_cfg_files[@]}") + fi + if [[ -z "$_cfg_app_ctx" ]]; then + _cfg_app_ctx=$(_prole_cfg_extract_key_in_files "init_cluster.app_cluster_kubecontext" "${_prole_cfg_files[@]}") + fi + if [[ -z "$_cfg_app_ctx" ]]; then + _cfg_app_ctx=$(_prole_cfg_extract_key_in_files "init_cluster_app_cluster_kubecontext" "${_prole_cfg_files[@]}") + fi + if [[ -n "$_cfg_app_ctx" ]]; then + _cfg_ctx="$_cfg_app_ctx" + fi + fi if [[ -n "$_cfg_ctx" ]]; then - # Respect explicitly provided runtime context (e.g., installer per-role env) - # and only fall back to prole.cfg when no runtime context is set. - if [[ -z "${KUBE_CONTEXT_NAME:-}" && -z "${KUBECTL_CONTEXT:-}" && -z "${KUBECONTEXT:-}" ]]; then + _runtime_ctx="${KUBECTL_CONTEXT:-${KUBE_CONTEXT_NAME:-${KUBECONTEXT:-}}}" + _override_runtime_ctx=0 + # Respect explicitly provided runtime context (e.g., installer per-role env), + # but in k8s split-cluster mode override legacy aliases with APP context. + if [[ -z "$_runtime_ctx" ]]; then + _override_runtime_ctx=1 + elif [[ "$_cfg_mode_hint" == "k8s" && -n "$_cfg_app_ctx" ]]; then + case "$_runtime_ctx" in + prod|production|prole-prod-cluster) + _override_runtime_ctx=1 + ;; + esac + fi + if [[ $_override_runtime_ctx -eq 1 ]]; then export KUBE_CONTEXT_NAME="$_cfg_ctx" export KUBECTL_CONTEXT="$_cfg_ctx" export KUBECONTEXT="$_cfg_ctx" fi + unset _runtime_ctx _override_runtime_ctx fi - unset _cfg_ns _cfg_sns _cfg_dm _cfg_sh _cfg_sbh _cfg_sapi _cfg_sstudio _cfg_sing _cfg_gitdom _cfg_githosts _cfg_ging _cfg_auth_enabled _cfg_auth_host _cfg_auth_verify _cfg_auth_login _cfg_auth_headers _cfg_ctx _prole_cfg_files _prole_cfg_f + unset _cfg_ns _cfg_sns _cfg_dm _cfg_sh _cfg_sbh _cfg_sapi _cfg_sstudio _cfg_sing _cfg_gitdom _cfg_githosts _cfg_ging _cfg_auth_enabled _cfg_auth_host _cfg_auth_verify _cfg_auth_login _cfg_auth_headers _cfg_ctx _cfg_mode_hint _cfg_app_ctx _prole_cfg_files _prole_cfg_f fi if [[ -z "${PROLE_HOME:-}" && -d "$_prole_cfg_home_guess" ]]; then