Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2601926

Browse files
authored
Merge pull request kubernetes#35455 from maisem/automated-cherry-pick-of-#31367-upstream-release-1.3
Automated cherry pick of kubernetes#31367
2 parents 4c9b4b1 + e7fb1af commit 2601926

File tree

4 files changed

+54
-30
lines changed

4 files changed

+54
-30
lines changed

cluster/gce/gci/configure-helper.sh

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,26 @@ function load-docker-images {
392392
fi
393393
}
394394

395-
# A kubelet systemd service is built in GCI image, but by default it is not started
396-
# when an instance is up. To start kubelet, the command line flags should be written
397-
# to /etc/default/kubelet in the format "KUBELET_OPTS=<flags>", and then start kubelet
398-
# using systemctl. This function assembles the command line and start the kubelet
399-
# systemd service.
395+
# This function assembles the kubelet systemd service file and starts it
396+
# using systemctl.
400397
function start-kubelet {
401398
echo "Start kubelet"
399+
local kubelet_bin="${KUBE_HOME}/bin/kubelet"
400+
local -r version="$("${kubelet_bin}" --version=true | cut -f2 -d " ")"
401+
local -r builtin_kubelet="/usr/bin/kubelet"
402+
if [[ "${TEST_CLUSTER:-}" == "true" ]]; then
403+
# Determine which binary to use on test clusters. We use the built-in
404+
# version only if the downloaded version is the same as the built-in
405+
# version. This allows GCI to run some of the e2e tests to qualify the
406+
# built-in kubelet.
407+
if [[ -x "${builtin_kubelet}" ]]; then
408+
local -r builtin_version="$("${builtin_kubelet}" --version=true | cut -f2 -d " ")"
409+
if [[ "${builtin_version}" == "${version}" ]]; then
410+
kubelet_bin="${builtin_kubelet}"
411+
fi
412+
fi
413+
fi
414+
echo "Using kubelet binary at ${kubelet_bin}"
402415
local flags="${KUBELET_TEST_LOG_LEVEL:-"--v=2"} ${KUBELET_TEST_ARGS:-}"
403416
flags+=" --allow-privileged=true"
404417
flags+=" --babysit-daemons=true"
@@ -459,7 +472,26 @@ function start-kubelet {
459472
if [[ "${ALLOCATE_NODE_CIDRS:-}" == "true" ]]; then
460473
flags+=" --configure-cbr0=${ALLOCATE_NODE_CIDRS}"
461474
fi
462-
echo "KUBELET_OPTS=\"${flags}\"" > /etc/default/kubelet
475+
476+
local -r kubelet_env_file="/etc/default/kubelet"
477+
echo "KUBELET_OPTS=\"${flags}\"" > "${kubelet_env_file}"
478+
479+
# Write the systemd service file for kubelet.
480+
cat <<EOF >/etc/systemd/system/kubelet.service
481+
[Unit]
482+
Description=Kubernetes kubelet
483+
Requires=network-online.target
484+
After=network-online.target
485+
486+
[Service]
487+
Restart=always
488+
RestartSec=10
489+
EnvironmentFile=${kubelet_env_file}
490+
ExecStart=${kubelet_bin} \$KUBELET_OPTS
491+
492+
[Install]
493+
WantedBy=multi-user.target
494+
EOF
463495

464496
# Delete docker0 to avoid interference
465497
iptables -t nat -F || true
@@ -937,7 +969,7 @@ function start-lb-controller {
937969

938970
function reset-motd {
939971
# kubelet is installed both on the master and nodes, and the version is easy to parse (unlike kubectl)
940-
local -r version="$(/usr/bin/kubelet --version=true | cut -f2 -d " ")"
972+
local -r version="$("${KUBE_HOME}"/bin/kubelet --version=true | cut -f2 -d " ")"
941973
# This logic grabs either a release tag (v1.2.1 or v1.2.1-alpha.1),
942974
# or the git hash that's in the build info.
943975
local gitref="$(echo "${version}" | sed -r "s/(v[0-9]+\.[0-9]+\.[0-9]+)(-[a-z]+\.[0-9]+)?.*/\1\2/g")"

cluster/gce/gci/configure.sh

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,19 @@ function install-kube-binary-config {
128128
cp -r "${KUBE_HOME}/kubernetes/addons" "${dst_dir}"
129129
fi
130130
local -r kube_bin="${KUBE_HOME}/bin"
131-
# If the built-in binary version is different from the expected version, we use
132-
# the downloaded binary. The simplest implementation is to always use the downloaded
133-
# binary without checking the version. But we have another version guardian in GKE.
134-
# So, we compare the versions to ensure this run-time binary replacement is only
135-
# applied for OSS kubernetes.
136-
cp "${src_dir}/kubelet" "${kube_bin}"
137-
local -r builtin_version="$(/usr/bin/kubelet --version=true | cut -f2 -d " ")"
138-
local -r required_version="$(/home/kubernetes/bin/kubelet --version=true | cut -f2 -d " ")"
139-
if [[ "${TEST_CLUSTER:-}" == "true" ]] || \
140-
[[ "${builtin_version}" != "${required_version}" ]]; then
141-
cp "${src_dir}/kubectl" "${kube_bin}"
142-
chmod 755 "${kube_bin}/kubelet"
143-
chmod 755 "${kube_bin}/kubectl"
144-
mount --bind "${kube_bin}/kubelet" /usr/bin/kubelet
145-
mount --bind "${kube_bin}/kubectl" /usr/bin/kubectl
146-
else
147-
rm -f "${kube_bin}/kubelet"
148-
fi
131+
mv "${src_dir}/kubelet" "${kube_bin}"
132+
mv "${src_dir}/kubectl" "${kube_bin}"
133+
149134
if [[ "${NETWORK_PROVIDER:-}" == "kubenet" ]] || \
150135
[[ "${NETWORK_PROVIDER:-}" == "cni" ]]; then
151136
#TODO(andyzheng0831): We should make the cni version number as a k8s env variable.
152137
local -r cni_tar="cni-26b61728ac940c3faf827927782326e921be17b0.tar.gz"
153138
download-or-bust "" "https://storage.googleapis.com/kubernetes-release/network-plugins/${cni_tar}"
154-
tar xzf "${KUBE_HOME}/${cni_tar}" -C "${kube_bin}" --overwrite
155-
mv "${kube_bin}/bin"/* "${kube_bin}"
156-
rmdir "${kube_bin}/bin"
139+
local -r cni_dir="${KUBE_HOME}/cni"
140+
mkdir -p "${cni_dir}"
141+
tar xzf "${KUBE_HOME}/${cni_tar}" -C "${cni_dir}" --overwrite
142+
mv "${cni_dir}/bin"/* "${kube_bin}"
143+
rmdir "${cni_dir}/bin"
157144
rm -f "${KUBE_HOME}/${cni_tar}"
158145
fi
159146

@@ -186,8 +173,7 @@ function install-kube-binary-config {
186173
fi
187174
cp "${dst_dir}/kubernetes/gci-trusty/gci-configure-helper.sh" "${KUBE_HOME}/bin/configure-helper.sh"
188175
cp "${dst_dir}/kubernetes/gci-trusty/health-monitor.sh" "${KUBE_HOME}/bin/health-monitor.sh"
189-
chmod 544 "${KUBE_HOME}/bin/configure-helper.sh"
190-
chmod 544 "${KUBE_HOME}/bin/health-monitor.sh"
176+
chmod -R 755 "${kube_bin}"
191177

192178
# Clean up.
193179
rm -rf "${KUBE_HOME}/kubernetes"

cluster/gce/gci/master.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ write_files:
3333
[Service]
3434
Type=oneshot
3535
RemainAfterExit=yes
36+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure-helper.sh
3637
ExecStart=/home/kubernetes/bin/configure-helper.sh
3738
3839
[Install]
@@ -51,6 +52,7 @@ write_files:
5152
RestartSec=10
5253
RemainAfterExit=yes
5354
RemainAfterExit=yes
55+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/health-monitor.sh
5456
ExecStart=/home/kubernetes/bin/health-monitor.sh docker
5557
5658
[Install]
@@ -69,6 +71,7 @@ write_files:
6971
RestartSec=10
7072
RemainAfterExit=yes
7173
RemainAfterExit=yes
74+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/health-monitor.sh
7275
ExecStart=/home/kubernetes/bin/health-monitor.sh kubelet
7376
7477
[Install]

cluster/gce/gci/node.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ write_files:
3333
[Service]
3434
Type=oneshot
3535
RemainAfterExit=yes
36+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/configure-helper.sh
3637
ExecStart=/home/kubernetes/bin/configure-helper.sh
3738
3839
[Install]
@@ -51,6 +52,7 @@ write_files:
5152
RestartSec=10
5253
RemainAfterExit=yes
5354
RemainAfterExit=yes
55+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/health-monitor.sh
5456
ExecStart=/home/kubernetes/bin/health-monitor.sh docker
5557
5658
[Install]
@@ -69,6 +71,7 @@ write_files:
6971
RestartSec=10
7072
RemainAfterExit=yes
7173
RemainAfterExit=yes
74+
ExecStartPre=/bin/chmod 544 /home/kubernetes/bin/health-monitor.sh
7275
ExecStart=/home/kubernetes/bin/health-monitor.sh kubelet
7376
7477
[Install]

0 commit comments

Comments
 (0)