mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
python snippets should work on both old and new python versions
This commit is contained in:
parent
7e8f31b313
commit
f20e17e9dd
@ -2713,13 +2713,24 @@ function main() {
|
|||||||
|
|
||||||
KUBE_HOME="/home/kubernetes"
|
KUBE_HOME="/home/kubernetes"
|
||||||
KUBE_BIN=${KUBE_HOME}/bin
|
KUBE_BIN=${KUBE_HOME}/bin
|
||||||
PYTHON="python"
|
|
||||||
CONTAINERIZED_MOUNTER_HOME="${KUBE_HOME}/containerized_mounter"
|
CONTAINERIZED_MOUNTER_HOME="${KUBE_HOME}/containerized_mounter"
|
||||||
PV_RECYCLER_OVERRIDE_TEMPLATE="${KUBE_HOME}/kube-manifests/kubernetes/pv-recycler-template.yaml"
|
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"
|
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
|
||||||
|
fi
|
||||||
|
echo "Version : " $(${PYTHON} -V 2>&1)
|
||||||
|
|
||||||
if [[ ! -e "${KUBE_HOME}/kube-env" ]]; then
|
if [[ ! -e "${KUBE_HOME}/kube-env" ]]; then
|
||||||
echo "The ${KUBE_HOME}/kube-env file does not exist!! Terminate cluster initialization."
|
echo "The ${KUBE_HOME}/kube-env file does not exist!! Terminate cluster initialization."
|
||||||
|
@ -66,7 +66,12 @@ function download-kube-env {
|
|||||||
# Convert the yaml format file into a shell-style file.
|
# Convert the yaml format file into a shell-style file.
|
||||||
eval $(${PYTHON} -c '''
|
eval $(${PYTHON} -c '''
|
||||||
import pipes,sys,yaml
|
import pipes,sys,yaml
|
||||||
for k,v in yaml.load(sys.stdin).iteritems():
|
# 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))))
|
print("readonly {var}={value}".format(var=k, value=pipes.quote(str(v))))
|
||||||
''' < "${tmp_kube_env}" > "${KUBE_HOME}/kube-env")
|
''' < "${tmp_kube_env}" > "${KUBE_HOME}/kube-env")
|
||||||
rm -f "${tmp_kube_env}"
|
rm -f "${tmp_kube_env}"
|
||||||
@ -105,7 +110,12 @@ function download-kube-master-certs {
|
|||||||
# Convert the yaml format file into a shell-style file.
|
# Convert the yaml format file into a shell-style file.
|
||||||
eval $(${PYTHON} -c '''
|
eval $(${PYTHON} -c '''
|
||||||
import pipes,sys,yaml
|
import pipes,sys,yaml
|
||||||
for k,v in yaml.load(sys.stdin).iteritems():
|
# 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))))
|
print("readonly {var}={value}".format(var=k, value=pipes.quote(str(v))))
|
||||||
''' < "${tmp_kube_master_certs}" > "${KUBE_HOME}/kube-master-certs")
|
''' < "${tmp_kube_master_certs}" > "${KUBE_HOME}/kube-master-certs")
|
||||||
rm -f "${tmp_kube_master_certs}"
|
rm -f "${tmp_kube_master_certs}"
|
||||||
@ -530,9 +540,21 @@ KUBE_HOME="/home/kubernetes"
|
|||||||
KUBE_BIN="${KUBE_HOME}/bin"
|
KUBE_BIN="${KUBE_HOME}/bin"
|
||||||
PYTHON="python"
|
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"
|
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
|
||||||
|
fi
|
||||||
|
echo "Version : " $(${PYTHON} -V 2>&1)
|
||||||
|
|
||||||
# download and source kube-env
|
# download and source kube-env
|
||||||
download-kube-env
|
download-kube-env
|
||||||
|
Loading…
Reference in New Issue
Block a user