csi-kata-directvolume: Fix shellcheck issues in directvol-deploy.sh

Fix shellcheck warnings and notes identified by running
shellcheck --severity=style.

Signed-off-by: Fabiano Fidêncio <ffidencio@nvidia.com>
This commit is contained in:
Fabiano Fidêncio
2026-04-21 12:32:06 +02:00
parent 10f81ae534
commit e1ab24d320

View File

@@ -14,7 +14,7 @@ BASE_DIR=$(dirname "$0")
# KUBELET_DATA_DIR can be set to replace the default /var/lib/kubelet.
# All nodes must use the same directory.
default_kubelet_data_dir=/var/lib/kubelet
: ${KUBELET_DATA_DIR:=${default_kubelet_data_dir}}
: "${KUBELET_DATA_DIR:=${default_kubelet_data_dir}}"
# namespace kata-directvolume
DIRECTVOL_NAMESPACE="kata-directvolume"
@@ -32,60 +32,68 @@ run () {
# deploy kata directvolume plugin and registrar sidecar
echo "deploying kata directvolume components"
for i in $(ls ${BASE_DIR}/kata-directvolume/csi-directvol-*.yaml | sort); do
echo " $i"
modified="$(cat "$i" | sed -e "s;${default_kubelet_data_dir}/;${KUBELET_DATA_DIR}/;" | while IFS= read -r line; do
nocomments="$(echo "$line" | sed -e 's/ *#.*$//')"
if echo "$nocomments" | grep -q '^[[:space:]]*image:[[:space:]]*'; then
for i in $(find "${BASE_DIR}/kata-directvolume" -name 'csi-directvol-*.yaml' | sort); do
echo " ${i}"
modified="$(sed -e "s;${default_kubelet_data_dir}/;${KUBELET_DATA_DIR}/;" "${i}" | while IFS= read -r line; do
# shellcheck disable=SC2001
nocomments="$(echo "${line}" | sed -e 's/ *#.*$//')"
if echo "${nocomments}" | grep -q '^[[:space:]]*image:[[:space:]]*'; then
# Split 'image: quay.io/k8scsi/csi-attacher:vx.y.z'
# into image (quay.io/k8scsi/csi-attacher:vx.y.z),
# registry (quay.io/k8scsi),
# name (csi-attacher),
# tag (vx.y.z).
image=$(echo "$nocomments" | sed -e 's;.*image:[[:space:]]*;;')
registry=$(echo "$image" | sed -e 's;\(.*\)/.*;\1;')
name=$(echo "$image" | sed -e 's;.*/\([^:]*\).*;\1;')
tag=$(echo "$image" | sed -e 's;.*:;;')
# shellcheck disable=SC2001
image=$(echo "${nocomments}" | sed -e 's;.*image:[[:space:]]*;;')
# shellcheck disable=SC2001
registry=$(echo "${image}" | sed -e 's;\(.*\)/.*;\1;')
# shellcheck disable=SC2001
name=$(echo "${image}" | sed -e 's;.*/\([^:]*\).*;\1;')
tag="${image##*:}"
# Variables are with underscores and upper case.
varname=$(echo $name | tr - _ | tr a-z A-Z)
varname=$(echo "${name}" | tr - _ | tr '[:lower:]' '[:upper:]')
# Now replace registry and/or tag, if set as env variables.
# If not set, the replacement is the same as the original value.
# Only do this for the images which are meant to be configurable.
if update_image "$name"; then
prefix=$(eval echo \${${varname}_REGISTRY:-${IMAGE_REGISTRY:-${registry}}}/ | sed -e 's;none/;;')
if [ "$IMAGE_TAG" = "canary" ] &&
[ -f ${BASE_DIR}/canary-blacklist.txt ] &&
grep -q "^$name\$" ${BASE_DIR}/canary-blacklist.txt; then
if update_image "${name}"; then
# shellcheck disable=SC2154
prefix=$(eval "echo \${${varname}_REGISTRY:-${IMAGE_REGISTRY:-${registry}}}/" | sed -e 's;none/;;')
# shellcheck disable=SC2154
if [[ "${IMAGE_TAG}" = "canary" ]] &&
[[ -f "${BASE_DIR}/canary-blacklist.txt" ]] &&
grep -q "^${name}\$" "${BASE_DIR}/canary-blacklist.txt"; then
# Ignore IMAGE_TAG=canary for this particular image because its
# canary image is blacklisted in the deployment blacklist.
suffix=$(eval echo :\${${varname}_TAG:-${tag}})
suffix=$(eval "echo :\${${varname}_TAG:-${tag}}")
else
suffix=$(eval echo :\${${varname}_TAG:-${IMAGE_TAG:-${tag}}})
suffix=$(eval "echo :\${${varname}_TAG:-${IMAGE_TAG:-${tag}}}")
fi
line="$(echo "$nocomments" | sed -e "s;$image;${prefix}${name}${suffix};")"
# shellcheck disable=SC2001
line="$(echo "${nocomments}" | sed -e "s;${image};${prefix}${name}${suffix};")"
fi
echo "kata-directvolume plugin using $line" >&2
echo "kata-directvolume plugin using ${line}" >&2
fi
if ! $have_csistoragecapacity; then
line="$(echo "$line" | grep -v -e 'storageCapacity: true' -e '--enable-capacity')"
# shellcheck disable=SC2154
if ! ${have_csistoragecapacity}; then
line="$(echo "${line}" | grep -v -e 'storageCapacity: true' -e '--enable-capacity')"
fi
echo "$line"
echo "${line}"
done)"
if ! echo "$modified" | kubectl apply -f -; then
echo "modified version of $i:"
echo "$modified"
if ! echo "${modified}" | kubectl apply -f -; then
echo "modified version of ${i}:"
echo "${modified}"
exit 1
fi
done
wait_for_daemonset () {
retries=10
while [ $retries -ge 0 ]; do
ready=$(kubectl get -n $1 daemonset $2 -o jsonpath="{.status.numberReady}")
required=$(kubectl get -n $1 daemonset $2 -o jsonpath="{.status.desiredNumberScheduled}")
if [ $ready -gt 0 ] && [ $ready -eq $required ]; then
while [[ ${retries} -ge 0 ]]; do
ready=$(kubectl get -n "$1" daemonset "$2" -o jsonpath="{.status.numberReady}")
required=$(kubectl get -n "$1" daemonset "$2" -o jsonpath="{.status.desiredNumberScheduled}")
if [[ "${ready}" -gt 0 ]] && [[ "${ready}" -eq "${required}" ]]; then
return 0
fi
retries=$((retries - 1))
@@ -96,7 +104,7 @@ wait_for_daemonset () {
# Wait until the DaemonSet is running on all nodes.
if ! wait_for_daemonset ${DIRECTVOL_NAMESPACE} csi-kata-directvol-plugin; then
if ! wait_for_daemonset "${DIRECTVOL_NAMESPACE}" csi-kata-directvol-plugin; then
echo
echo "driver not ready"
echo "Deployment:"
@@ -104,9 +112,9 @@ if ! wait_for_daemonset ${DIRECTVOL_NAMESPACE} csi-kata-directvol-plugin; then
echo
echo "Pod logs:"
kubectl get pods -l app.kubernetes.io/instance=directvolume.csi.katacontainers.io --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{" "}{range .spec.containers[*]}{.name}{" "}{end}{"\n"}{end}' | while read -r pod containers; do
for c in $containers; do
for c in ${containers}; do
echo
(set +e; set -x; kubectl logs $pod $c)
(set +e; set -x; kubectl logs "${pod}" "${c}")
done
done
exit 1