Skip to content

Commit

Permalink
Merge pull request #3338 from twiest/bug_2056387
Browse files Browse the repository at this point in the history
Bug 2056387: fix alibaba kubelet node name unit
  • Loading branch information
openshift-merge-robot authored Oct 1, 2022
2 parents 61fead5 + 58e071b commit 71469ce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ path: "/usr/local/bin/alibaba-kubelet-nodename"
contents:
inline: |
#!/bin/bash
set -e -o pipefail
set -euo pipefail
NODECONF=/etc/systemd/system/kubelet.service.d/20-alibaba-node-name.conf
ENV_FILE=/run/kubelet-alibaba.env
if [ -e "${NODECONF}" ]; then
echo "Not replacing existing ${NODECONF}"
if [ -e "${ENV_FILE}" ]; then
echo "Not replacing existing ${ENV_FILE}"
exit 0
fi
Expand All @@ -20,7 +20,6 @@ contents:
INSTANCEID=$(curl -s ${META_EP}/instance-id)
cat > "${NODECONF}" <<EOF
[Service]
Environment="KUBELET_NODE_NAME=${REGIONID}.${INSTANCEID}"
cat > "${ENV_FILE}" <<EOF
KUBELET_NODE_NAME=${REGIONID}.${INSTANCEID}
EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
mode: 0755
path: "/usr/local/lib/systemd/system-generators/alibaba-kubelet-extra-env-generator.sh"
contents:
inline: |
#!/bin/sh
set -euo pipefail
# This systemd.generator(7) determines the alibaba nodename and sets
# it as a variable for the kubelet.service unit file.
#
# Place in /usr/local/lib/systemd/system-generators
# Generators don't have logging right now
# https://github.com/systemd/systemd/issues/15638
exec 1>/dev/kmsg; exec 2>&1
# If invoked with no arguments (for testing) write to /tmp.
earlydir="/tmp"
if [ -n "$2" ]; then
earlydir="$2"
fi
kubelet_service_d_dir="$earlydir/kubelet.service.d"
node_env="$kubelet_service_d_dir/alibaba-extra-env.conf"
mkdir -p "$kubelet_service_d_dir"
# This must NOT be a here-document otherwise this script will generate this error:
# alibaba-kubelet-extra-env-generator.sh: cannot create temp file for here-document: Read-only file system
echo -e "[Service]\nEnvironmentFile=/run/kubelet-alibaba.env" > "${node_env}"

0 comments on commit 71469ce

Please sign in to comment.