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 test/e2e_node/gubernator.sh shellcheck failures #79317

Merged
merged 1 commit into from
Jun 25, 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
1 change: 0 additions & 1 deletion hack/.shellcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
./test/cmd/discovery.sh
./test/cmd/legacy-script.sh
./test/e2e_node/conformance/run_test.sh
./test/e2e_node/gubernator.sh
./test/images/image-util.sh
53 changes: 29 additions & 24 deletions test/e2e_node/gubernator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ set -o errexit
set -o nounset
set -o pipefail

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


if [[ $# -eq 0 || ! $1 =~ ^[Yy]$ ]]; then
read -p "Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
read -r -p "Do you want to run gubernator.sh and upload logs publicly to GCS? [y/n]" yn
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own knowledge - why is -r necessary here?

Copy link
Member Author

Choose a reason for hiding this comment

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

without -r read will mangle escape sequences. technically it shouldn't matter in this context, but it's a good habit and a correctness fix unless you actually wanted that behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

the shellcheck wiki has a good entry on this https://github.com/koalaman/shellcheck/wiki/SC2162

echo
if [[ ! $yn =~ ^[Yy]$ ]]; then
exit 1
Expand Down Expand Up @@ -59,9 +60,9 @@ V=2 kube::log::status "Using bucket ${bucket_name}"
# Check if the bucket exists
if ! gsutil ls gs:// | grep -q "gs://${bucket_name}/"; then
V=2 kube::log::status "Creating public bucket ${bucket_name}"
gsutil mb gs://${bucket_name}/
gsutil mb "gs://${bucket_name}/"
# Make all files in the bucket publicly readable
gsutil acl ch -u AllUsers:R gs://${bucket_name}
gsutil acl ch -u AllUsers:R "gs://${bucket_name}"
else
V=2 kube::log::status "Bucket already exists"
fi
Expand All @@ -79,24 +80,24 @@ fi

# Get start and end timestamps based on build-log.txt file contents
# Line where the actual tests start
start_line=$(grep -n -m 1 "^=" ${BUILD_LOG_PATH} | sed 's/\([0-9]*\).*/\1/')
start_line=$(grep -n -m 1 "^=" "${BUILD_LOG_PATH}" | sed 's/\([0-9]*\).*/\1/')
# Create text file starting where the tests start
after_start=$(tail -n +${start_line} ${BUILD_LOG_PATH})
after_start=$(tail -n "+${start_line}" "${BUILD_LOG_PATH}")
echo "${after_start}" >> build-log-cut.txt
# Match the first timestamp
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)
rm build-log-cut.txt
# Make the date readable by date command (ex: 0101 00:00:00.000 -> 01/01 00:00:00.000)
start_time=$(echo ${start_time_raw} | sed 's/^.\{2\}/&\//')
start_time=$(echo "${start_time_raw}" | sed 's/^.\{2\}/&\//')
V=2 kube::log::status "Started at ${start_time}"
# Match the last timestamp in the build-log file
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\}/&\//')
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\}/&\//')
# Convert to epoch time for Gubernator
start_time_epoch=$(date -d "${start_time}" +%s)
end_time_epoch=$(date -d "${end_time}" +%s)

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

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

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

for result in $(find ${ARTIFACTS} -type d -name "results"); do
if [[ $result != "" && $result != "${ARTIFACTS}/results" && $result != $ARTIFACTS ]]; then
mv $result/* $ARTIFACTS
while IFS= read -r result; do
if [[ $result != "" && $result != "${ARTIFACTS}/results" && $result != "${ARTIFACTS}" ]]; then
mv "${result}/"* "${ARTIFACTS}"
fi
done
done < <(find "${ARTIFACTS}" -type d -name "results")

# Upload log files
for upload_attempt in $(seq 3); do
Expand All @@ -137,7 +138,6 @@ version=""
if [[ -e "version" ]]; then
version=$(cat "version")
elif [[ -e "hack/lib/version.sh" ]]; then
export KUBE_ROOT="."
source "hack/lib/version.sh"
kube::version::get_version_vars
version="${KUBE_GIT_VERSION-}"
Expand Down Expand Up @@ -167,16 +167,21 @@ if [[ -e "${ARTIFACTS}/finished.json" ]]; then
fi

V=2 kube::log::status "Constructing started.json and finished.json files"
echo "{" >> "${ARTIFACTS}/started.json"
echo " \"version\": \"${version}\"," >> "${ARTIFACTS}/started.json"
echo " \"timestamp\": ${start_time_epoch}," >> "${ARTIFACTS}/started.json"
echo " \"jenkins-node\": \"${NODE_NAME:-}\"" >> "${ARTIFACTS}/started.json"
echo "}" >> "${ARTIFACTS}/started.json"

echo "{" >> "${ARTIFACTS}/finished.json"
echo " \"result\": \"${build_result}\"," >> "${ARTIFACTS}/finished.json"
echo " \"timestamp\": ${end_time_epoch}" >> "${ARTIFACTS}/finished.json"
echo "}" >> "${ARTIFACTS}/finished.json"
cat <<EOF >"${ARTIFACTS}/started.json"
{
"version": "${version}",
"timestamp": ${start_time_epoch},
"jenkins-node": "${NODE_NAME:-}"
}
EOF


cat <<EOF >"${ARTIFACTS}/finished.json"
{
"result": "${build_result}",
"timestamp": ${end_time_epoch}
}
EOF


# Upload started.json
Expand Down