Skip to content

Commit 38e95b1

Browse files
authored
Merge pull request kubernetes#79317 from BenTheElder/yikeshell
fix test/e2e_node/gubernator.sh shellcheck failures
2 parents dac0bd9 + 21d1d27 commit 38e95b1

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

hack/.shellcheck_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@
2828
./test/cmd/discovery.sh
2929
./test/cmd/legacy-script.sh
3030
./test/e2e_node/conformance/run_test.sh
31-
./test/e2e_node/gubernator.sh
3231
./test/images/image-util.sh

test/e2e_node/gubernator.sh

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ set -o errexit
2222
set -o nounset
2323
set -o pipefail
2424

25-
source hack/lib/logging.sh
25+
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
26+
source "${KUBE_ROOT}/hack/lib/logging.sh"
2627

2728

2829
if [[ $# -eq 0 || ! $1 =~ ^[Yy]$ ]]; then
29-
read -p "Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
30+
read -r -p "Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
3031
echo
3132
if [[ ! $yn =~ ^[Yy]$ ]]; then
3233
exit 1
@@ -59,9 +60,9 @@ V=2 kube::log::status "Using bucket ${bucket_name}"
5960
# Check if the bucket exists
6061
if ! gsutil ls gs:// | grep -q "gs://${bucket_name}/"; then
6162
V=2 kube::log::status "Creating public bucket ${bucket_name}"
62-
gsutil mb gs://${bucket_name}/
63+
gsutil mb "gs://${bucket_name}/"
6364
# Make all files in the bucket publicly readable
64-
gsutil acl ch -u AllUsers:R gs://${bucket_name}
65+
gsutil acl ch -u AllUsers:R "gs://${bucket_name}"
6566
else
6667
V=2 kube::log::status "Bucket already exists"
6768
fi
@@ -79,24 +80,24 @@ fi
7980

8081
# Get start and end timestamps based on build-log.txt file contents
8182
# Line where the actual tests start
82-
start_line=$(grep -n -m 1 "^=" ${BUILD_LOG_PATH} | sed 's/\([0-9]*\).*/\1/')
83+
start_line=$(grep -n -m 1 "^=" "${BUILD_LOG_PATH}" | sed 's/\([0-9]*\).*/\1/')
8384
# Create text file starting where the tests start
84-
after_start=$(tail -n +${start_line} ${BUILD_LOG_PATH})
85+
after_start=$(tail -n "+${start_line}" "${BUILD_LOG_PATH}")
8586
echo "${after_start}" >> build-log-cut.txt
8687
# Match the first timestamp
8788
start_time_raw=$(grep -m 1 -o '[0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' build-log-cut.txt)
8889
rm build-log-cut.txt
8990
# Make the date readable by date command (ex: 0101 00:00:00.000 -> 01/01 00:00:00.000)
90-
start_time=$(echo ${start_time_raw} | sed 's/^.\{2\}/&\//')
91+
start_time=$(echo "${start_time_raw}" | sed 's/^.\{2\}/&\//')
9192
V=2 kube::log::status "Started at ${start_time}"
9293
# Match the last timestamp in the build-log file
93-
end_time=$(grep -o '[0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' ${BUILD_LOG_PATH} | tail -1 | sed 's/^.\{2\}/&\//')
94+
end_time=$(grep -o '[0-9][0-9][0-9][0-9][[:blank:]][0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]*' "${BUILD_LOG_PATH}" | tail -1 | sed 's/^.\{2\}/&\//')
9495
# Convert to epoch time for Gubernator
9596
start_time_epoch=$(date -d "${start_time}" +%s)
9697
end_time_epoch=$(date -d "${end_time}" +%s)
9798

9899
# Make folder name for build from timestamp
99-
BUILD_STAMP=$(echo $start_time | sed 's/\///' | sed 's/ /_/')
100+
BUILD_STAMP=$(echo "${start_time}" | sed 's/\///' | sed 's/ /_/')
100101

101102
GCS_LOGS_PATH="${GCS_JOBS_PATH}/${BUILD_STAMP}"
102103

@@ -108,11 +109,11 @@ if gsutil ls "${GCS_JOBS_PATH}" | grep -q "${BUILD_STAMP}"; then
108109
exit
109110
fi
110111

111-
for result in $(find ${ARTIFACTS} -type d -name "results"); do
112-
if [[ $result != "" && $result != "${ARTIFACTS}/results" && $result != $ARTIFACTS ]]; then
113-
mv $result/* $ARTIFACTS
112+
while IFS= read -r result; do
113+
if [[ $result != "" && $result != "${ARTIFACTS}/results" && $result != "${ARTIFACTS}" ]]; then
114+
mv "${result}/"* "${ARTIFACTS}"
114115
fi
115-
done
116+
done < <(find "${ARTIFACTS}" -type d -name "results")
116117

117118
# Upload log files
118119
for upload_attempt in $(seq 3); do
@@ -137,7 +138,6 @@ version=""
137138
if [[ -e "version" ]]; then
138139
version=$(cat "version")
139140
elif [[ -e "hack/lib/version.sh" ]]; then
140-
export KUBE_ROOT="."
141141
source "hack/lib/version.sh"
142142
kube::version::get_version_vars
143143
version="${KUBE_GIT_VERSION-}"
@@ -167,16 +167,21 @@ if [[ -e "${ARTIFACTS}/finished.json" ]]; then
167167
fi
168168

169169
V=2 kube::log::status "Constructing started.json and finished.json files"
170-
echo "{" >> "${ARTIFACTS}/started.json"
171-
echo " \"version\": \"${version}\"," >> "${ARTIFACTS}/started.json"
172-
echo " \"timestamp\": ${start_time_epoch}," >> "${ARTIFACTS}/started.json"
173-
echo " \"jenkins-node\": \"${NODE_NAME:-}\"" >> "${ARTIFACTS}/started.json"
174-
echo "}" >> "${ARTIFACTS}/started.json"
175-
176-
echo "{" >> "${ARTIFACTS}/finished.json"
177-
echo " \"result\": \"${build_result}\"," >> "${ARTIFACTS}/finished.json"
178-
echo " \"timestamp\": ${end_time_epoch}" >> "${ARTIFACTS}/finished.json"
179-
echo "}" >> "${ARTIFACTS}/finished.json"
170+
cat <<EOF >"${ARTIFACTS}/started.json"
171+
{
172+
"version": "${version}",
173+
"timestamp": ${start_time_epoch},
174+
"jenkins-node": "${NODE_NAME:-}"
175+
}
176+
EOF
177+
178+
179+
cat <<EOF >"${ARTIFACTS}/finished.json"
180+
{
181+
"result": "${build_result}",
182+
"timestamp": ${end_time_epoch}
183+
}
184+
EOF
180185

181186

182187
# Upload started.json

0 commit comments

Comments
 (0)