Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shellcheck failure in gce/gci/flexvolume_node_setup.sh #81061

Merged
merged 1 commit into from Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 17 additions & 18 deletions cluster/gce/gci/flexvolume_node_setup.sh
Expand Up @@ -41,7 +41,7 @@ usage() {
exit 1
}

if [ -z ${MOUNTER_IMAGE} ]; then
if [ -z "${MOUNTER_IMAGE}" ]; then
echo "ERROR: No Container Registry mounter image is specified."
echo
usage
Expand All @@ -50,7 +50,7 @@ fi
# Unmounts a mount point lazily. If a mount point does not exist, continue silently,
# and without error.
umount_silent() {
umount -l $1 &> /dev/null || /bin/true
umount -l "$1" &> /dev/null || /bin/true
}

# Waits for kubelet to restart for 1 minute.
Expand Down Expand Up @@ -82,10 +82,10 @@ flex_clean() {
rm -rf ${MOUNTER_PATH}

if [[ -n ${IMAGE_URL:-} ]]; then
docker rmi -f ${IMAGE_URL} &> /dev/null || /bin/true
docker rmi -f "${IMAGE_URL}" &> /dev/null || /bin/true
fi
if [[ -n ${MOUNTER_DEFAULT_NAME:-} ]]; then
docker rm -f ${MOUNTER_DEFAULT_NAME} &> /dev/null || /bin/true
docker rm -f "${MOUNTER_DEFAULT_NAME}" &> /dev/null || /bin/true
fi
}

Expand All @@ -99,31 +99,31 @@ generate_chroot_wrapper() {
exit 1
fi

for driver_dir in ${MOUNTER_PATH}/flexvolume/*; do
for driver_dir in "${MOUNTER_PATH}/flexvolume"/*; do
if [ -d "$driver_dir" ]; then

filecount=$(ls -1 $driver_dir | wc -l)
if [ $filecount -gt 1 ]; then
filecount=$(cd "$driver_dir"; find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 -n1 basename | wc -l)
if [ "$filecount" -gt 1 ]; then
echo "ERROR: Expected 1 file in the FlexVolume directory but found $filecount."
exit 1
fi

driver_file=$( ls $driver_dir | head -n 1 )
driver_file=$(cd "$driver_dir"; find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 -n1 basename | head -n 1)

# driver_path points to the actual driver inside the mount utility image,
# relative to image root.
# wrapper_path is the wrapper script location, which is known to kubelet.
driver_path=flexvolume/$( basename $driver_dir )/${driver_file}
wrapper_dir=${VOLUME_PLUGIN_DIR}/$( basename $driver_dir )
driver_path=flexvolume/$( basename "$driver_dir" )/${driver_file}
wrapper_dir=${VOLUME_PLUGIN_DIR}/$( basename "$driver_dir" )
wrapper_path=${wrapper_dir}/${driver_file}

mkdir -p $wrapper_dir
cat >$wrapper_path <<EOF
mkdir -p "$wrapper_dir"
cat >"$wrapper_path" <<EOF
#!/usr/bin/env bash
chroot ${MOUNTER_PATH} ${driver_path} "\$@"
EOF

chmod 755 $wrapper_path
chmod 755 "$wrapper_path"
echo "FlexVolume driver installed at ${wrapper_path}"
fi
done
Expand All @@ -139,11 +139,11 @@ ACCESS_TOKEN=$(curl -s -H 'Metadata-Flavor: Google' $SVC_ACCT_ENDPOINT/token | c
PROJECT_ID=$(curl -s -H 'Metadata-Flavor: Google' $METADATA/project/project-id)
IMAGE_URL=gcr.io/${PROJECT_ID}/${MOUNTER_IMAGE}
MOUNTER_DEFAULT_NAME=flexvolume_mounter
sudo -u ${SUDO_USER} docker login -u _token -p $ACCESS_TOKEN https://gcr.io > /dev/null
sudo -u ${SUDO_USER} docker run --name=${MOUNTER_DEFAULT_NAME} ${IMAGE_URL}
sudo -u "${SUDO_USER}" docker login -u _token -p "$ACCESS_TOKEN" https://gcr.io > /dev/null
sudo -u "${SUDO_USER}" docker run --name=${MOUNTER_DEFAULT_NAME} "${IMAGE_URL}"
docker export ${MOUNTER_DEFAULT_NAME} > /tmp/${MOUNTER_DEFAULT_NAME}.tar
docker rm ${MOUNTER_DEFAULT_NAME} > /dev/null
docker rmi ${IMAGE_URL} > /dev/null
docker rmi "${IMAGE_URL}" > /dev/null

echo
echo "Loading mount utilities onto this instance..."
Expand Down Expand Up @@ -175,8 +175,7 @@ echo "Restarting Kubelet..."
echo

systemctl restart kubelet.service
kubelet_wait
if [ $? -eq 0 ]; then
if kubelet_wait; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if [ $? -eq 0 ]; then
     ^-- SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?.

echo
echo "FlexVolume is ready."
else
Expand Down
1 change: 0 additions & 1 deletion hack/.shellcheck_failures
Expand Up @@ -6,7 +6,6 @@
./cluster/gce/config-test.sh
./cluster/gce/gci/configure-helper.sh
./cluster/gce/gci/configure.sh
./cluster/gce/gci/flexvolume_node_setup.sh
./cluster/gce/gci/health-monitor.sh
./cluster/gce/gci/master-helper.sh
./cluster/gce/upgrade.sh
Expand Down