Skip to content

Commit 1dd53fd

Browse files
committed
Fix issue with GCE scripts assuming Python2.
For bug kubernetes#87482. Newer OSs are now defaulting to Python3. This breaks the kube-up scripts for GCE. Adding code to detect this and explicitly use Python2.
1 parent f88f58c commit 1dd53fd

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cluster/gce/gci/configure-helper.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ function start-kube-proxy {
15271527
# $5: pod name, which should be either etcd or etcd-events
15281528
function prepare-etcd-manifest {
15291529
local host_name=${ETCD_HOSTNAME:-$(hostname -s)}
1530-
local host_ip=$(python -c "import socket;print(socket.gethostbyname(\"${host_name}\"))")
1530+
local host_ip=$(${PYTHON} -c "import socket;print(socket.gethostbyname(\"${host_name}\"))")
15311531
local etcd_cluster=""
15321532
local cluster_state="new"
15331533
local etcd_protocol="http"
@@ -2713,17 +2713,21 @@ function main() {
27132713

27142714
KUBE_HOME="/home/kubernetes"
27152715
KUBE_BIN=${KUBE_HOME}/bin
2716+
PYTHON="python"
27162717
CONTAINERIZED_MOUNTER_HOME="${KUBE_HOME}/containerized_mounter"
27172718
PV_RECYCLER_OVERRIDE_TEMPLATE="${KUBE_HOME}/kube-manifests/kubernetes/pv-recycler-template.yaml"
27182719

2720+
if [[ "$(python -V)" =~ "Python 3" ]]; then
2721+
PYTHON="/usr/bin/python2.7"
2722+
fi
2723+
27192724
if [[ ! -e "${KUBE_HOME}/kube-env" ]]; then
27202725
echo "The ${KUBE_HOME}/kube-env file does not exist!! Terminate cluster initialization."
27212726
exit 1
27222727
fi
27232728

27242729
source "${KUBE_HOME}/kube-env"
27252730

2726-
27272731
if [[ -f "${KUBE_HOME}/kubelet-config.yaml" ]]; then
27282732
echo "Found Kubelet config file at ${KUBE_HOME}/kubelet-config.yaml"
27292733
KUBELET_CONFIG_FILE_ARG="--config ${KUBE_HOME}/kubelet-config.yaml"

cluster/gce/gci/configure.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function download-kube-env {
6464
-o "${tmp_kube_env}" \
6565
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-env
6666
# Convert the yaml format file into a shell-style file.
67-
eval $(python -c '''
67+
eval $(${PYTHON} -c '''
6868
import pipes,sys,yaml
6969
for k,v in yaml.load(sys.stdin).iteritems():
7070
print("readonly {var}={value}".format(var = k, value = pipes.quote(str(v))))
@@ -103,7 +103,7 @@ function download-kube-master-certs {
103103
-o "${tmp_kube_master_certs}" \
104104
http://metadata.google.internal/computeMetadata/v1/instance/attributes/kube-master-certs
105105
# Convert the yaml format file into a shell-style file.
106-
eval $(python -c '''
106+
eval $(${PYTHON} -c '''
107107
import pipes,sys,yaml
108108
for k,v in yaml.load(sys.stdin).iteritems():
109109
print("readonly {var}={value}".format(var = k, value = pipes.quote(str(v))))
@@ -126,7 +126,7 @@ function validate-hash {
126126
# Get default service account credentials of the VM.
127127
GCE_METADATA_INTERNAL="http://metadata.google.internal/computeMetadata/v1/instance"
128128
function get-credentials {
129-
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | python -c \
129+
curl --fail --retry 5 --retry-delay 3 ${CURL_RETRY_CONNREFUSED} --silent --show-error "${GCE_METADATA_INTERNAL}/service-accounts/default/token" -H "Metadata-Flavor: Google" -s | ${PYTHON} -c \
130130
'import sys; import json; print(json.loads(sys.stdin.read())["access_token"])'
131131
}
132132

@@ -471,6 +471,11 @@ set-broken-motd
471471

472472
KUBE_HOME="/home/kubernetes"
473473
KUBE_BIN="${KUBE_HOME}/bin"
474+
PYTHON="python"
475+
476+
if [[ "$(python -V)" =~ "Python 3" ]]; then
477+
PYTHON="/usr/bin/python2.7"
478+
fi
474479

475480
# download and source kube-env
476481
download-kube-env

0 commit comments

Comments
 (0)