mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 16:49:35 +00:00
Merge pull request #59572 from ipuustin/shell-bugfix2
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix various bash scripts to make them more robust and uniform **What this PR does / why we need it**: The shellcheck tool (https://github.com/koalaman/shellcheck) finds a bunch of issues in kubernetes bash scripts. I started fixing the issues to make the scripts more robust and correct. This PR fixes some "low-hanging fruit" and also cleans up file `hack/update-godep-licenses.sh` in a more complete fashion. **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
595ed7f613
@ -81,10 +81,10 @@ flex_clean() {
|
|||||||
umount_silent ${MOUNTER_PATH}
|
umount_silent ${MOUNTER_PATH}
|
||||||
rm -rf ${MOUNTER_PATH}
|
rm -rf ${MOUNTER_PATH}
|
||||||
|
|
||||||
if [ -n ${IMAGE_URL:-} ]; then
|
if [[ -n ${IMAGE_URL:-} ]]; then
|
||||||
docker rmi -f ${IMAGE_URL} &> /dev/null || /bin/true
|
docker rmi -f ${IMAGE_URL} &> /dev/null || /bin/true
|
||||||
fi
|
fi
|
||||||
if [ -n ${MOUNTER_DEFAULT_NAME:-} ]; then
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ function gcloud-compute-list() {
|
|||||||
fi
|
fi
|
||||||
echo -e "Attempt ${attempt} failed to list ${resource}. Retrying." >&2
|
echo -e "Attempt ${attempt} failed to list ${resource}. Retrying." >&2
|
||||||
attempt=$(($attempt+1))
|
attempt=$(($attempt+1))
|
||||||
if [[ ${attempt} > 5 ]]; then
|
if [[ ${attempt} -gt 5 ]]; then
|
||||||
echo -e "List ${resource} failed!" >&2
|
echo -e "List ${resource} failed!" >&2
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
@ -53,7 +53,7 @@ function detect-k8s-subnetwork() {
|
|||||||
local subnetwork_url=$(gcloud compute instances describe \
|
local subnetwork_url=$(gcloud compute instances describe \
|
||||||
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \
|
${KUBE_MASTER} --project=${PROJECT} --zone=${ZONE} \
|
||||||
--format='value(networkInterfaces[0].subnetwork)')
|
--format='value(networkInterfaces[0].subnetwork)')
|
||||||
if [ -n ${subnetwork_url} ]; then
|
if [[ -n ${subnetwork_url} ]]; then
|
||||||
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/})
|
IP_ALIAS_SUBNETWORK=$(echo ${subnetwork_url##*/})
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -74,10 +74,10 @@ process_content () {
|
|||||||
# Start search at package root
|
# Start search at package root
|
||||||
case ${package} in
|
case ${package} in
|
||||||
github.com/*|golang.org/*|bitbucket.org/*)
|
github.com/*|golang.org/*|bitbucket.org/*)
|
||||||
package_root=$(echo ${package} |awk -F/ '{ print $1"/"$2"/"$3 }')
|
package_root=$(echo "${package}" |awk -F/ '{ print $1"/"$2"/"$3 }')
|
||||||
;;
|
;;
|
||||||
go4.org/*)
|
go4.org/*)
|
||||||
package_root=$(echo ${package} |awk -F/ '{ print $1 }')
|
package_root=$(echo "${package}" |awk -F/ '{ print $1 }')
|
||||||
;;
|
;;
|
||||||
gopkg.in/*)
|
gopkg.in/*)
|
||||||
# Root of gopkg.in package always ends with '.v(number)' and my contain
|
# Root of gopkg.in package always ends with '.v(number)' and my contain
|
||||||
@ -85,10 +85,10 @@ process_content () {
|
|||||||
# - gopkg.in/yaml.v2
|
# - gopkg.in/yaml.v2
|
||||||
# - gopkg.in/inf.v0
|
# - gopkg.in/inf.v0
|
||||||
# - gopkg.in/square/go-jose.v2
|
# - gopkg.in/square/go-jose.v2
|
||||||
package_root=$(echo ${package} |grep -oh '.*\.v[0-9]')
|
package_root=$(echo "${package}" |grep -oh '.*\.v[0-9]')
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
package_root=$(echo ${package} |awk -F/ '{ print $1"/"$2 }')
|
package_root=$(echo "${package}" |awk -F/ '{ print $1"/"$2 }')
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ process_content () {
|
|||||||
[[ -d ${DEPS_DIR}/${dir_root} ]] || continue
|
[[ -d ${DEPS_DIR}/${dir_root} ]] || continue
|
||||||
|
|
||||||
# One (set) of these is fine
|
# One (set) of these is fine
|
||||||
find ${DEPS_DIR}/${dir_root} \
|
find "${DEPS_DIR}/${dir_root}" \
|
||||||
-xdev -follow -maxdepth ${find_maxdepth} \
|
-xdev -follow -maxdepth ${find_maxdepth} \
|
||||||
-type f "${find_names[@]}"
|
-type f "${find_names[@]}"
|
||||||
done | sort -u))
|
done | sort -u))
|
||||||
@ -107,9 +107,14 @@ process_content () {
|
|||||||
local f
|
local f
|
||||||
index="${package}-${type}"
|
index="${package}-${type}"
|
||||||
if [[ -z "${CONTENT[${index}]-}" ]]; then
|
if [[ -z "${CONTENT[${index}]-}" ]]; then
|
||||||
for f in ${local_files[@]-}; do
|
for f in "${local_files[@]-}"; do
|
||||||
|
if [[ -z "$f" ]]; then
|
||||||
|
# Set the default value and then check it to prevent
|
||||||
|
# accessing potentially empty array
|
||||||
|
continue
|
||||||
|
fi
|
||||||
# Find some copyright info in any file and break
|
# Find some copyright info in any file and break
|
||||||
if egrep -i -wq "${ensure_pattern}" "${f}"; then
|
if grep -E -i -wq "${ensure_pattern}" "${f}"; then
|
||||||
CONTENT[${index}]="${f}"
|
CONTENT[${index}]="${f}"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -151,19 +156,17 @@ declare -Ag CONTENT
|
|||||||
echo "================================================================================"
|
echo "================================================================================"
|
||||||
echo "= Kubernetes licensed under: ="
|
echo "= Kubernetes licensed under: ="
|
||||||
echo
|
echo
|
||||||
cat ${LICENSE_ROOT}/LICENSE
|
cat "${LICENSE_ROOT}/LICENSE"
|
||||||
echo
|
echo
|
||||||
echo "= LICENSE $(cat ${LICENSE_ROOT}/LICENSE | md5sum | awk '{print $1}')"
|
echo "= LICENSE $(cat "${LICENSE_ROOT}/LICENSE" | md5sum | awk '{print $1}')"
|
||||||
echo "================================================================================"
|
echo "================================================================================"
|
||||||
) > ${TMP_LICENSE_FILE}
|
) > ${TMP_LICENSE_FILE}
|
||||||
|
|
||||||
# Loop through every package in Godeps.json
|
# Loop through every package in Godeps.json
|
||||||
for PACKAGE in $(cat Godeps/Godeps.json | \
|
for PACKAGE in $(jq -r ".Deps[].ImportPath" < Godeps/Godeps.json | sort -f); do
|
||||||
jq -r ".Deps[].ImportPath" | \
|
process_content "${PACKAGE}" LICENSE
|
||||||
sort -f); do
|
process_content "${PACKAGE}" COPYRIGHT
|
||||||
process_content ${PACKAGE} LICENSE
|
process_content "${PACKAGE}" COPYING
|
||||||
process_content ${PACKAGE} COPYRIGHT
|
|
||||||
process_content ${PACKAGE} COPYING
|
|
||||||
|
|
||||||
# display content
|
# display content
|
||||||
echo
|
echo
|
||||||
@ -195,7 +198,7 @@ __EOF__
|
|||||||
cat "${file}"
|
cat "${file}"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "= ${file} $(cat ${file} | md5sum | awk '{print $1}')"
|
echo "= ${file} $(cat "${file}" | md5sum | awk '{print $1}')"
|
||||||
echo "================================================================================"
|
echo "================================================================================"
|
||||||
echo
|
echo
|
||||||
done >> ${TMP_LICENSE_FILE}
|
done >> ${TMP_LICENSE_FILE}
|
||||||
|
@ -30,7 +30,7 @@ make -C "${KUBE_ROOT}" WHAT="${BINS[*]}"
|
|||||||
|
|
||||||
clicheck=$(kube::util::find-binary "clicheck")
|
clicheck=$(kube::util::find-binary "clicheck")
|
||||||
|
|
||||||
if ! output=`$clicheck 2>&1`
|
if ! output=$($clicheck 2>&1)
|
||||||
then
|
then
|
||||||
echo "$output"
|
echo "$output"
|
||||||
echo
|
echo
|
||||||
|
@ -65,7 +65,7 @@ _kubetmp="${_kubetmp}/kubernetes"
|
|||||||
# Do all our work in the new GOPATH
|
# Do all our work in the new GOPATH
|
||||||
export GOPATH="${_tmpdir}"
|
export GOPATH="${_tmpdir}"
|
||||||
|
|
||||||
pushd "${_kubetmp}" 2>&1 > /dev/null
|
pushd "${_kubetmp}" > /dev/null 2>&1
|
||||||
# Restore the Godeps into our temp directory
|
# Restore the Godeps into our temp directory
|
||||||
hack/godep-restore.sh
|
hack/godep-restore.sh
|
||||||
|
|
||||||
@ -78,11 +78,11 @@ pushd "${_kubetmp}" 2>&1 > /dev/null
|
|||||||
|
|
||||||
# Recreate the Godeps using the nice clean set we just downloaded
|
# Recreate the Godeps using the nice clean set we just downloaded
|
||||||
hack/godep-save.sh
|
hack/godep-save.sh
|
||||||
popd 2>&1 > /dev/null
|
popd > /dev/null 2>&1
|
||||||
|
|
||||||
ret=0
|
ret=0
|
||||||
|
|
||||||
pushd "${KUBE_ROOT}" 2>&1 > /dev/null
|
pushd "${KUBE_ROOT}" > /dev/null 2>&1
|
||||||
# Test for diffs
|
# Test for diffs
|
||||||
if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\":' Godeps/Godeps.json ${_kubetmp}/Godeps/Godeps.json)"; then
|
if ! _out="$(diff -Naupr --ignore-matching-lines='^\s*\"GoVersion\":' --ignore-matching-line='^\s*\"GodepVersion\":' --ignore-matching-lines='^\s*\"Comment\":' Godeps/Godeps.json ${_kubetmp}/Godeps/Godeps.json)"; then
|
||||||
echo "Your Godeps.json is different:" >&2
|
echo "Your Godeps.json is different:" >&2
|
||||||
@ -117,9 +117,9 @@ pushd "${KUBE_ROOT}" 2>&1 > /dev/null
|
|||||||
fi
|
fi
|
||||||
ret=1
|
ret=1
|
||||||
fi
|
fi
|
||||||
popd 2>&1 > /dev/null
|
popd > /dev/null 2>&1
|
||||||
|
|
||||||
if [[ ${ret} > 0 ]]; then
|
if [[ ${ret} -gt 0 ]]; then
|
||||||
exit ${ret}
|
exit ${ret}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ pushd "${BASH_DIR}" > /dev/null
|
|||||||
done
|
done
|
||||||
popd > /dev/null
|
popd > /dev/null
|
||||||
|
|
||||||
if [[ ${ret} > 0 ]]; then
|
if [[ ${ret} -gt 0 ]]; then
|
||||||
exit ${ret}
|
exit ${ret}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user