diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index 76e936d6f73..88df3785883 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -2713,13 +2713,24 @@ function main() { KUBE_HOME="/home/kubernetes" KUBE_BIN=${KUBE_HOME}/bin - PYTHON="python" CONTAINERIZED_MOUNTER_HOME="${KUBE_HOME}/containerized_mounter" PV_RECYCLER_OVERRIDE_TEMPLATE="${KUBE_HOME}/kube-manifests/kubernetes/pv-recycler-template.yaml" - if [[ "$(python -V)" =~ "Python 3" ]]; then + if [[ "$(python -V 2>&1)" =~ "Python 2" ]]; then + # found python2, just use that + PYTHON="python" + elif [[ -f "/usr/bin/python2.7" ]]; then + # System python not defaulted to python 2 but using 2.7 during migration PYTHON="/usr/bin/python2.7" + else + # No python2 either by default, let's see if we can find python3 + PYTHON="python3" + if ! command -v ${PYTHON} >/dev/null 2>&1; then + echo "ERROR Python not found. Aborting." + exit 2 + fi fi + echo "Version : " $(${PYTHON} -V 2>&1) if [[ ! -e "${KUBE_HOME}/kube-env" ]]; then echo "The ${KUBE_HOME}/kube-env file does not exist!! Terminate cluster initialization." diff --git a/cluster/gce/gci/configure.sh b/cluster/gce/gci/configure.sh index 7b6a2d3e642..3529944b676 100644 --- a/cluster/gce/gci/configure.sh +++ b/cluster/gce/gci/configure.sh @@ -66,8 +66,13 @@ function download-kube-env { # Convert the yaml format file into a shell-style file. eval $(${PYTHON} -c ''' import pipes,sys,yaml -for k,v in yaml.load(sys.stdin).iteritems(): - print("readonly {var}={value}".format(var = k, value = pipes.quote(str(v)))) +# check version of python and call methods appropriate for that version +if sys.version_info[0] < 3: + items = yaml.load(sys.stdin).iteritems() +else: + items = yaml.load(sys.stdin, Loader=yaml.BaseLoader).items() +for k, v in items: + print("readonly {var}={value}".format(var=k, value=pipes.quote(str(v)))) ''' < "${tmp_kube_env}" > "${KUBE_HOME}/kube-env") rm -f "${tmp_kube_env}" ) @@ -105,8 +110,13 @@ function download-kube-master-certs { # Convert the yaml format file into a shell-style file. eval $(${PYTHON} -c ''' import pipes,sys,yaml -for k,v in yaml.load(sys.stdin).iteritems(): - print("readonly {var}={value}".format(var = k, value = pipes.quote(str(v)))) +# check version of python and call methods appropriate for that version +if sys.version_info[0] < 3: + items = yaml.load(sys.stdin).iteritems() +else: + items = yaml.load(sys.stdin, Loader=yaml.BaseLoader).items() +for k, v in items: + print("readonly {var}={value}".format(var=k, value=pipes.quote(str(v)))) ''' < "${tmp_kube_master_certs}" > "${KUBE_HOME}/kube-master-certs") rm -f "${tmp_kube_master_certs}" ) @@ -530,9 +540,21 @@ KUBE_HOME="/home/kubernetes" KUBE_BIN="${KUBE_HOME}/bin" PYTHON="python" -if [[ "$(python -V)" =~ "Python 3" ]]; then +if [[ "$(python -V 2>&1)" =~ "Python 2" ]]; then + # found python2, just use that + PYTHON="python" +elif [[ -f "/usr/bin/python2.7" ]]; then + # System python not defaulted to python 2 but using 2.7 during migration PYTHON="/usr/bin/python2.7" +else + # No python2 either by default, let's see if we can find python3 + PYTHON="python3" + if ! command -v ${PYTHON} >/dev/null 2>&1; then + echo "ERROR Python not found. Aborting." + exit 2 + fi fi +echo "Version : " $(${PYTHON} -V 2>&1) # download and source kube-env download-kube-env