Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit e44db99

Browse files
vteratipallythaJeztah
authored andcommitted
Make script work for both python2.7 and 3.6
Signed-off-by: Varsha Teratipally <[email protected]> (cherry picked from commit bf3dcfe) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4cb63f2 commit e44db99

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

cluster/gce/configure.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ set -o errexit
1919
set -o nounset
2020
set -o pipefail
2121

22+
if [[ "$(python -V 2>&1)" =~ "Python 2" ]]; then
23+
# found python2, just use that
24+
PYTHON="python"
25+
elif [[ -f "/usr/bin/python2.7" ]]; then
26+
# System python not defaulted to python 2 but using 2.7 during migration
27+
PYTHON="/usr/bin/python2.7"
28+
else
29+
# No python2 either by default, let's see if we can find python3
30+
PYTHON="python3"
31+
if ! command -v ${PYTHON} >/dev/null 2>&1; then
32+
echo "ERROR Python not found. Aborting."
33+
exit 2
34+
fi
35+
fi
36+
echo "Version : " $(${PYTHON} -V 2>&1)
37+
2238
# CONTAINERD_HOME is the directory for containerd.
2339
CONTAINERD_HOME="/home/containerd"
2440
cd "${CONTAINERD_HOME}"
@@ -53,9 +69,13 @@ fetch_env() {
5369
fi
5470
echo "${tmp_env_content}" > "${tmp_env_file}"
5571
# Convert the yaml format file into a shell-style file.
56-
eval $(python -c '''
72+
eval $(${PYTHON} -c '''
5773
import pipes,sys,yaml
58-
for k,v in yaml.load(sys.stdin).iteritems():
74+
if sys.version_info[0] < 3:
75+
items = yaml.load(sys.stdin).iteritems()
76+
else:
77+
items = yaml.load(sys.stdin, Loader=yaml.BaseLoader).items()
78+
for k,v in items:
5979
print("readonly {var}={value}".format(var = k, value = pipes.quote(str(v))))
6080
''' < "${tmp_env_file}" > "${CONTAINERD_HOME}/${env_file_name}")
6181
rm -f "${tmp_env_file}"
@@ -163,10 +183,8 @@ version = 2
163183
required_plugins = ["io.containerd.grpc.v1.cri"]
164184
# Kubernetes doesn't use containerd restart manager.
165185
disabled_plugins = ["io.containerd.internal.v1.restart"]
166-
167186
[debug]
168187
level = "${log_level}"
169-
170188
[plugins."io.containerd.grpc.v1.cri"]
171189
stream_server_address = "127.0.0.1"
172190
stream_server_port = "0"
@@ -192,7 +210,6 @@ if [[ -n "${containerd_extra_runtime_handler}" ]]; then
192210
cat >> ${config_path} <<EOF
193211
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${containerd_extra_runtime_handler}]
194212
runtime_type = "${CONTAINERD_EXTRA_RUNTIME_TYPE:-io.containerd.runc.v1}"
195-
196213
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.${containerd_extra_runtime_handler}.options]
197214
${CONTAINERD_EXTRA_RUNTIME_OPTIONS:-}
198215
EOF

0 commit comments

Comments
 (0)