mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #75859 from k-toyoda-pi/fix_shellcheck_failure_make-rules
fix shellcheck failures in /hack/make-rules/test.sh
This commit is contained in:
commit
0f5650d68b
@ -22,7 +22,6 @@
|
|||||||
./hack/lib/test.sh
|
./hack/lib/test.sh
|
||||||
./hack/lib/version.sh
|
./hack/lib/version.sh
|
||||||
./hack/make-rules/make-help.sh
|
./hack/make-rules/make-help.sh
|
||||||
./hack/make-rules/test.sh
|
|
||||||
./hack/pin-dependency.sh
|
./hack/pin-dependency.sh
|
||||||
./hack/test-integration.sh
|
./hack/test-integration.sh
|
||||||
./hack/update-vendor.sh
|
./hack/update-vendor.sh
|
||||||
|
@ -31,7 +31,7 @@ ALL_VERSIONS_CSV=$(IFS=',';echo "${KUBE_AVAILABLE_GROUP_VERSIONS[*]// /,}";IFS=$
|
|||||||
KUBE_TEST_API_VERSIONS="${KUBE_TEST_API_VERSIONS:-${ALL_VERSIONS_CSV}}"
|
KUBE_TEST_API_VERSIONS="${KUBE_TEST_API_VERSIONS:-${ALL_VERSIONS_CSV}}"
|
||||||
|
|
||||||
# Give integration tests longer to run by default.
|
# Give integration tests longer to run by default.
|
||||||
KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 600s}
|
KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout=600s}
|
||||||
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
|
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
|
||||||
LOG_LEVEL=${LOG_LEVEL:-2}
|
LOG_LEVEL=${LOG_LEVEL:-2}
|
||||||
KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
|
KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
|
||||||
|
@ -18,7 +18,7 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
|
||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
|
|
||||||
kube::golang::setup_env
|
kube::golang::setup_env
|
||||||
@ -43,7 +43,7 @@ fi
|
|||||||
|
|
||||||
kube::test::find_dirs() {
|
kube::test::find_dirs() {
|
||||||
(
|
(
|
||||||
cd ${KUBE_ROOT}
|
cd "${KUBE_ROOT}"
|
||||||
find -L . -not \( \
|
find -L . -not \( \
|
||||||
\( \
|
\( \
|
||||||
-path './_artifacts/*' \
|
-path './_artifacts/*' \
|
||||||
@ -105,7 +105,7 @@ kube::test::find_dirs() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 120s}
|
KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout=120s}
|
||||||
KUBE_COVER=${KUBE_COVER:-n} # set to 'y' to enable coverage collection
|
KUBE_COVER=${KUBE_COVER:-n} # set to 'y' to enable coverage collection
|
||||||
KUBE_COVERMODE=${KUBE_COVERMODE:-atomic}
|
KUBE_COVERMODE=${KUBE_COVERMODE:-atomic}
|
||||||
# How many 'go test' instances to run simultaneously when running tests in
|
# How many 'go test' instances to run simultaneously when running tests in
|
||||||
@ -165,12 +165,12 @@ while getopts "hp:i:" opt ; do
|
|||||||
kube::test::usage
|
kube::test::usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
?)
|
:)
|
||||||
|
kube::log::usage "Option -${OPTARG} <value>"
|
||||||
kube::test::usage
|
kube::test::usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
:)
|
?)
|
||||||
kube::log::usage "Option -${OPTARG} <value>"
|
|
||||||
kube::test::usage
|
kube::test::usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
@ -179,6 +179,7 @@ done
|
|||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
# Use eval to preserve embedded quoted strings.
|
# Use eval to preserve embedded quoted strings.
|
||||||
|
testargs=()
|
||||||
eval "testargs=(${KUBE_TEST_ARGS:-})"
|
eval "testargs=(${KUBE_TEST_ARGS:-})"
|
||||||
|
|
||||||
# Used to filter verbose test output.
|
# Used to filter verbose test output.
|
||||||
@ -206,10 +207,14 @@ for arg; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [[ ${#testcases[@]} -eq 0 ]]; then
|
if [[ ${#testcases[@]} -eq 0 ]]; then
|
||||||
testcases=($(kube::test::find_dirs))
|
while IFS='' read -r line; do testcases+=("$line"); done < <(kube::test::find_dirs)
|
||||||
fi
|
fi
|
||||||
set -- "${testcases[@]+${testcases[@]}}"
|
set -- "${testcases[@]+${testcases[@]}}"
|
||||||
|
|
||||||
|
if [[ -n "${KUBE_RACE}" ]] ; then
|
||||||
|
goflags+=("${KUBE_RACE}")
|
||||||
|
fi
|
||||||
|
|
||||||
junitFilenamePrefix() {
|
junitFilenamePrefix() {
|
||||||
if [[ -z "${KUBE_JUNIT_REPORT_DIR}" ]]; then
|
if [[ -z "${KUBE_JUNIT_REPORT_DIR}" ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
@ -221,7 +226,8 @@ junitFilenamePrefix() {
|
|||||||
# barely fits there and in coverage mode test names are
|
# barely fits there and in coverage mode test names are
|
||||||
# appended to generated file names, easily exceeding
|
# appended to generated file names, easily exceeding
|
||||||
# 255 chars in length. So let's just use a sha1 hash of it.
|
# 255 chars in length. So let's just use a sha1 hash of it.
|
||||||
local KUBE_TEST_API_HASH="$(echo -n "${KUBE_TEST_API//\//-}"| ${SHA1SUM} |awk '{print $1}')"
|
local KUBE_TEST_API_HASH
|
||||||
|
KUBE_TEST_API_HASH="$(echo -n "${KUBE_TEST_API//\//-}"| ${SHA1SUM} |awk '{print $1}')"
|
||||||
echo "${KUBE_JUNIT_REPORT_DIR}/junit_${KUBE_TEST_API_HASH}_$(kube::util::sortable_date)"
|
echo "${KUBE_JUNIT_REPORT_DIR}/junit_${KUBE_TEST_API_HASH}_$(kube::util::sortable_date)"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +245,8 @@ verifyAndSuggestPackagePath() {
|
|||||||
# Because k8s sets a localized $GOPATH for testing, seeing the actual
|
# Because k8s sets a localized $GOPATH for testing, seeing the actual
|
||||||
# directory can be confusing. Instead, just show $GOPATH if it exists in the
|
# directory can be confusing. Instead, just show $GOPATH if it exists in the
|
||||||
# $specified_package_path.
|
# $specified_package_path.
|
||||||
local printable_package_path=$(echo "${specified_package_path}" | sed "s|${GOPATH}|\${GOPATH}|")
|
local printable_package_path
|
||||||
|
printable_package_path=${specified_package_path//${GOPATH}/\$\{GOPATH\}}
|
||||||
kube::log::error "specified test path '${printable_package_path}' does not exist"
|
kube::log::error "specified test path '${printable_package_path}' does not exist"
|
||||||
|
|
||||||
if [ -d "${alternative_package_path}" ]; then
|
if [ -d "${alternative_package_path}" ]; then
|
||||||
@ -250,7 +257,7 @@ verifyAndSuggestPackagePath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verifyPathsToPackagesUnderTest() {
|
verifyPathsToPackagesUnderTest() {
|
||||||
local packages_under_test=($@)
|
local packages_under_test=("$@")
|
||||||
|
|
||||||
for package_path in "${packages_under_test[@]}"; do
|
for package_path in "${packages_under_test[@]}"; do
|
||||||
local local_package_path="${package_path}"
|
local local_package_path="${package_path}"
|
||||||
@ -272,16 +279,16 @@ produceJUnitXMLReport() {
|
|||||||
|
|
||||||
local test_stdout_filenames
|
local test_stdout_filenames
|
||||||
local junit_xml_filename
|
local junit_xml_filename
|
||||||
test_stdout_filenames=$(ls ${junit_filename_prefix}*.stdout)
|
test_stdout_filenames=$(ls "${junit_filename_prefix}"*.stdout)
|
||||||
junit_xml_filename="${junit_filename_prefix}.xml"
|
junit_xml_filename="${junit_filename_prefix}.xml"
|
||||||
if ! command -v go-junit-report >/dev/null 2>&1; then
|
if ! command -v go-junit-report >/dev/null 2>&1; then
|
||||||
kube::log::error "go-junit-report not found; please install with " \
|
kube::log::error "go-junit-report not found; please install with " \
|
||||||
"go get -u github.com/jstemmer/go-junit-report"
|
"go get -u github.com/jstemmer/go-junit-report"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
cat ${test_stdout_filenames} | go-junit-report > "${junit_xml_filename}"
|
go-junit-report < "${test_stdout_filenames}" > "${junit_xml_filename}"
|
||||||
if [[ ! ${KUBE_KEEP_VERBOSE_TEST_OUTPUT} =~ ^[yY]$ ]]; then
|
if [[ ! ${KUBE_KEEP_VERBOSE_TEST_OUTPUT} =~ ^[yY]$ ]]; then
|
||||||
rm ${test_stdout_filenames}
|
rm "${test_stdout_filenames}"
|
||||||
fi
|
fi
|
||||||
kube::log::status "Saved JUnit XML test report to ${junit_xml_filename}"
|
kube::log::status "Saved JUnit XML test report to ${junit_xml_filename}"
|
||||||
}
|
}
|
||||||
@ -297,7 +304,7 @@ runTests() {
|
|||||||
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
|
if [[ ! ${KUBE_COVER} =~ ^[yY]$ ]]; then
|
||||||
kube::log::status "Running tests without code coverage"
|
kube::log::status "Running tests without code coverage"
|
||||||
go test "${goflags[@]:+${goflags[@]}}" \
|
go test "${goflags[@]:+${goflags[@]}}" \
|
||||||
${KUBE_RACE} ${KUBE_TIMEOUT} "${@}" \
|
"${KUBE_TIMEOUT}" "${@}" \
|
||||||
"${testargs[@]:+${testargs[@]}}" \
|
"${testargs[@]:+${testargs[@]}}" \
|
||||||
| tee ${junit_filename_prefix:+"${junit_filename_prefix}.stdout"} \
|
| tee ${junit_filename_prefix:+"${junit_filename_prefix}.stdout"} \
|
||||||
| grep --binary-files=text "${go_test_grep_pattern}" && rc=$? || rc=$?
|
| grep --binary-files=text "${go_test_grep_pattern}" && rc=$? || rc=$?
|
||||||
@ -328,21 +335,20 @@ runTests() {
|
|||||||
# vendor/k8s.io/client-go/1.4/rest: causes cover internal errors
|
# vendor/k8s.io/client-go/1.4/rest: causes cover internal errors
|
||||||
# https://github.com/golang/go/issues/16540
|
# https://github.com/golang/go/issues/16540
|
||||||
cover_ignore_dirs="vendor/k8s.io/code-generator/cmd/generator|vendor/k8s.io/client-go/1.4/rest"
|
cover_ignore_dirs="vendor/k8s.io/code-generator/cmd/generator|vendor/k8s.io/client-go/1.4/rest"
|
||||||
for path in $(echo ${cover_ignore_dirs} | sed 's/|/ /g'); do
|
for path in ${cover_ignore_dirs//|/ }; do
|
||||||
echo -e "skipped\tk8s.io/kubernetes/${path}"
|
echo -e "skipped\tk8s.io/kubernetes/${path}"
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "%s\n" "${@}" \
|
printf "%s\n" "${@}" \
|
||||||
| grep -Ev ${cover_ignore_dirs} \
|
| grep -Ev ${cover_ignore_dirs} \
|
||||||
| xargs -I{} -n 1 -P ${KUBE_COVERPROCS} \
|
| xargs -I{} -n 1 -P "${KUBE_COVERPROCS}" \
|
||||||
bash -c "set -o pipefail; _pkg=\"\$0\"; _pkg_out=\${_pkg//\//_}; \
|
bash -c "set -o pipefail; _pkg=\"\$0\"; _pkg_out=\${_pkg//\//_}; \
|
||||||
go test ${goflags[@]:+${goflags[@]}} \
|
go test ${goflags[*]:+${goflags[*]}} \
|
||||||
${KUBE_RACE} \
|
|
||||||
${KUBE_TIMEOUT} \
|
${KUBE_TIMEOUT} \
|
||||||
-cover -covermode=\"${KUBE_COVERMODE}\" \
|
-cover -covermode=\"${KUBE_COVERMODE}\" \
|
||||||
-coverprofile=\"${cover_report_dir}/\${_pkg}/${cover_profile}\" \
|
-coverprofile=\"${cover_report_dir}/\${_pkg}/${cover_profile}\" \
|
||||||
\"\${_pkg}\" \
|
\"\${_pkg}\" \
|
||||||
${testargs[@]:+${testargs[@]}} \
|
${testargs[*]:+${testargs[*]}} \
|
||||||
| tee ${junit_filename_prefix:+\"${junit_filename_prefix}-\$_pkg_out.stdout\"} \
|
| tee ${junit_filename_prefix:+\"${junit_filename_prefix}-\$_pkg_out.stdout\"} \
|
||||||
| grep \"${go_test_grep_pattern}\"" \
|
| grep \"${go_test_grep_pattern}\"" \
|
||||||
{} \
|
{} \
|
||||||
@ -360,9 +366,9 @@ runTests() {
|
|||||||
|
|
||||||
# Include all coverage reach data in the combined profile, but exclude the
|
# Include all coverage reach data in the combined profile, but exclude the
|
||||||
# 'mode' lines, as there should be only one.
|
# 'mode' lines, as there should be only one.
|
||||||
for x in `find "${cover_report_dir}" -name "${cover_profile}"`; do
|
while IFS='' read -r x; do
|
||||||
cat ${x} | grep -h -v "^mode:" || true
|
grep -h -v "^mode:" < "${x}" || true
|
||||||
done
|
done < <(find "${cover_report_dir}" -name "${cover_profile}")
|
||||||
} >"${COMBINED_COVER_PROFILE}"
|
} >"${COMBINED_COVER_PROFILE}"
|
||||||
|
|
||||||
coverage_html_file="${cover_report_dir}/combined-coverage.html"
|
coverage_html_file="${cover_report_dir}/combined-coverage.html"
|
||||||
@ -385,7 +391,8 @@ reportCoverageToCoveralls() {
|
|||||||
checkFDs() {
|
checkFDs() {
|
||||||
# several unittests panic when httptest cannot open more sockets
|
# several unittests panic when httptest cannot open more sockets
|
||||||
# due to the low default files limit on OS X. Warn about low limit.
|
# due to the low default files limit on OS X. Warn about low limit.
|
||||||
local fileslimit="$(ulimit -n)"
|
local fileslimit
|
||||||
|
fileslimit="$(ulimit -n)"
|
||||||
if [[ ${fileslimit} -lt 1000 ]]; then
|
if [[ ${fileslimit} -lt 1000 ]]; then
|
||||||
echo "WARNING: ulimit -n (files) should be at least 1000, is ${fileslimit}, may cause test failure";
|
echo "WARNING: ulimit -n (files) should be at least 1000, is ${fileslimit}, may cause test failure";
|
||||||
fi
|
fi
|
||||||
@ -395,9 +402,9 @@ checkFDs
|
|||||||
|
|
||||||
|
|
||||||
# Convert the CSVs to arrays.
|
# Convert the CSVs to arrays.
|
||||||
IFS=';' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
|
IFS=';' read -r -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
|
||||||
apiVersionsCount=${#apiVersions[@]}
|
apiVersionsCount=${#apiVersions[@]}
|
||||||
for (( i=0; i<${apiVersionsCount}; i++ )); do
|
for (( i=0; i<apiVersionsCount; i++ )); do
|
||||||
apiVersion=${apiVersions[i]}
|
apiVersion=${apiVersions[i]}
|
||||||
echo "Running tests for APIVersion: ${apiVersion}"
|
echo "Running tests for APIVersion: ${apiVersion}"
|
||||||
# KUBE_TEST_API sets the version of each group to be tested.
|
# KUBE_TEST_API sets the version of each group to be tested.
|
||||||
|
@ -33,7 +33,7 @@ run_kubeadm_tests() {
|
|||||||
make -C "${KUBE_ROOT}" test \
|
make -C "${KUBE_ROOT}" test \
|
||||||
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd \
|
WHAT=k8s.io/kubernetes/cmd/kubeadm/test/cmd \
|
||||||
KUBE_TEST_ARGS="--kubeadm-path '${KUBEADM_PATH}'" \
|
KUBE_TEST_ARGS="--kubeadm-path '${KUBEADM_PATH}'" \
|
||||||
KUBE_TIMEOUT="--timeout 600s"
|
KUBE_TIMEOUT="--timeout=600s"
|
||||||
set +o nounset
|
set +o nounset
|
||||||
set +o errexit
|
set +o errexit
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user