mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Revert "Revert "cluster: Use python3 everywhere""
This reverts commit 7038338e0f
.
This commit is contained in:
parent
31030820be
commit
dac06aefb0
@ -1781,7 +1781,7 @@ function start-kube-proxy {
|
|||||||
# $5: pod name, which should be either etcd or etcd-events
|
# $5: pod name, which should be either etcd or etcd-events
|
||||||
function prepare-etcd-manifest {
|
function prepare-etcd-manifest {
|
||||||
local host_name=${ETCD_HOSTNAME:-$(hostname -s)}
|
local host_name=${ETCD_HOSTNAME:-$(hostname -s)}
|
||||||
local -r host_ip=$(${PYTHON} -c "import socket;print(socket.gethostbyname(\"${host_name}\"))")
|
local -r host_ip=$(python3 -c "import socket;print(socket.gethostbyname(\"${host_name}\"))")
|
||||||
local etcd_cluster=""
|
local etcd_cluster=""
|
||||||
local cluster_state="new"
|
local cluster_state="new"
|
||||||
local etcd_protocol="http"
|
local etcd_protocol="http"
|
||||||
@ -3288,24 +3288,6 @@ function main() {
|
|||||||
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"
|
||||||
|
|
||||||
log-start 'SetPythonVersion'
|
|
||||||
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)"
|
|
||||||
log-end 'SetPythonVersion'
|
|
||||||
|
|
||||||
log-start 'SourceKubeEnv'
|
log-start 'SourceKubeEnv'
|
||||||
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."
|
||||||
|
@ -87,13 +87,9 @@ function download-kube-env {
|
|||||||
-o "${tmp_kube_env}" \
|
-o "${tmp_kube_env}" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env
|
http://metadata.google.internal/computeMetadata/v1/instance/attributes/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 "$(python3 -c '''
|
||||||
import pipes,sys,yaml
|
import pipes,sys,yaml
|
||||||
# check version of python and call methods appropriate for that version
|
items = yaml.load(sys.stdin, Loader=yaml.BaseLoader).items()
|
||||||
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:
|
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")"
|
||||||
@ -131,13 +127,9 @@ function download-kube-master-certs {
|
|||||||
-o "${tmp_kube_master_certs}" \
|
-o "${tmp_kube_master_certs}" \
|
||||||
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-certs
|
http://metadata.google.internal/computeMetadata/v1/instance/attributes/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 "$(python3 -c '''
|
||||||
import pipes,sys,yaml
|
import pipes,sys,yaml
|
||||||
# check version of python and call methods appropriate for that version
|
items = yaml.load(sys.stdin, Loader=yaml.BaseLoader).items()
|
||||||
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:
|
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")"
|
||||||
@ -160,7 +152,7 @@ function validate-hash {
|
|||||||
# Get default service account credentials of the VM.
|
# Get default service account credentials of the VM.
|
||||||
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
|
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
|
||||||
function get-credentials {
|
function get-credentials {
|
||||||
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | ${PYTHON} -c \
|
curl --fail --retry 5 --retry-delay 3 --retry-connrefused --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python3 -c \
|
||||||
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
|
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,25 +853,6 @@ log-wrap 'SetBrokenMotd' set-broken-motd
|
|||||||
|
|
||||||
KUBE_HOME="/home/kubernetes"
|
KUBE_HOME="/home/kubernetes"
|
||||||
KUBE_BIN="${KUBE_HOME}/bin"
|
KUBE_BIN="${KUBE_HOME}/bin"
|
||||||
PYTHON="python"
|
|
||||||
|
|
||||||
log-start 'SetPythonVersion'
|
|
||||||
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)"
|
|
||||||
log-end 'SetPythonVersion'
|
|
||||||
|
|
||||||
# download and source kube-env
|
# download and source kube-env
|
||||||
log-wrap 'DownloadKubeEnv' retry-forever 30 download-kube-env
|
log-wrap 'DownloadKubeEnv' retry-forever 30 download-kube-env
|
||||||
|
Loading…
Reference in New Issue
Block a user