Skip to content

Commit 7eb6182

Browse files
committed
Revert "Fix shellcheck failure in log-dump/log-dump.sh"
This reverts commit e99a325.
1 parent 4629da2 commit 7eb6182

File tree

2 files changed

+45
-46
lines changed

2 files changed

+45
-46
lines changed

cluster/log-dump/log-dump.sh

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ readonly max_dump_processes=25
6565
function setup() {
6666
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
6767
if [[ -z "${use_custom_instance_list}" ]]; then
68-
: "${KUBE_CONFIG_FILE:="config-test.sh"}"
68+
: ${KUBE_CONFIG_FILE:="config-test.sh"}
6969
echo "Sourcing kube-util.sh"
7070
source "${KUBE_ROOT}/cluster/kube-util.sh"
7171
echo "Detecting project"
@@ -87,7 +87,7 @@ function setup() {
8787
}
8888

8989
function log-dump-ssh() {
90-
if [[ "${gcloud_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
90+
if [[ "${gcloud_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
9191
ssh-to-node "$@"
9292
return
9393
fi
@@ -104,7 +104,7 @@ function log-dump-ssh() {
104104
function copy-logs-from-node() {
105105
local -r node="${1}"
106106
local -r dir="${2}"
107-
read -r -a files <<< "${3}"
107+
local files=( ${3} )
108108
# Append "*"
109109
# The * at the end is needed to also copy rotated logs (which happens
110110
# in large clusters and long runs).
@@ -114,13 +114,12 @@ function copy-logs-from-node() {
114114
# Comma delimit (even the singleton, or scp does the wrong thing), surround by braces.
115115
local -r scp_files="{$(printf "%s," "${files[@]}")}"
116116

117-
if [[ "${gcloud_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
117+
if [[ "${gcloud_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
118118
# get-serial-port-output lets you ask for ports 1-4, but currently (11/21/2016) only port 1 contains useful information
119119
gcloud compute instances get-serial-port-output --project "${PROJECT}" --zone "${ZONE}" --port 1 "${node}" > "${dir}/serial-1.log" || true
120120
gcloud compute scp --recurse --project "${PROJECT}" --zone "${ZONE}" "${node}:${scp_files}" "${dir}" > /dev/null || true
121121
elif [[ "${KUBERNETES_PROVIDER}" == "aws" ]]; then
122-
local ip
123-
ip=$(get_ssh_hostname "${node}")
122+
local ip=$(get_ssh_hostname "${node}")
124123
scp -oLogLevel=quiet -oConnectTimeout=30 -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" "${SSH_USER}@${ip}:${scp_files}" "${dir}" > /dev/null || true
125124
elif [[ -n "${use_custom_instance_list}" ]]; then
126125
scp -oLogLevel=quiet -oConnectTimeout=30 -oStrictHostKeyChecking=no -i "${LOG_DUMP_SSH_KEY}" "${LOG_DUMP_SSH_USER}@${node}:${scp_files}" "${dir}" > /dev/null || true
@@ -137,25 +136,25 @@ function copy-logs-from-node() {
137136
function save-logs() {
138137
local -r node_name="${1}"
139138
local -r dir="${2}"
140-
local save_files="${3}"
139+
local files="${3}"
141140
local opt_systemd_services="${4:-""}"
142141
local on_master="${5:-"false"}"
143142

144143
if [[ -n "${use_custom_instance_list}" ]]; then
145144
if [[ -n "${LOG_DUMP_SAVE_LOGS:-}" ]]; then
146-
save_files="${save_files} ${LOG_DUMP_SAVE_LOGS:-}"
145+
files="${files} ${LOG_DUMP_SAVE_LOGS:-}"
147146
fi
148147
else
149148
case "${KUBERNETES_PROVIDER}" in
150149
gce|gke|kubernetes-anywhere)
151-
save_files="${save_files} ${gce_logfiles}"
150+
files="${files} ${gce_logfiles}"
152151
;;
153152
aws)
154-
save_files="${save_files} ${aws_logfiles}"
153+
files="${files} ${aws_logfiles}"
155154
;;
156155
esac
157156
fi
158-
read -r -a services <<< "${systemd_services} ${opt_systemd_services} ${LOG_DUMP_SAVE_SERVICES:-}"
157+
local -r services=( ${systemd_services} ${opt_systemd_services} ${LOG_DUMP_SAVE_SERVICES:-} )
159158

160159
if log-dump-ssh "${node_name}" "command -v journalctl" &> /dev/null; then
161160
if [[ "${on_master}" == "true" ]]; then
@@ -175,7 +174,7 @@ function save-logs() {
175174
log-dump-ssh "${node_name}" "sudo journalctl --output=short-precise" > "${dir}/systemd.log" || true
176175
fi
177176
else
178-
save_files="${kern_logfile} ${save_files} ${initd_logfiles} ${supervisord_logfiles}"
177+
files="${kern_logfile} ${files} ${initd_logfiles} ${supervisord_logfiles}"
179178
fi
180179

181180
# Try dumping coverage profiles, if it looks like coverage is enabled in the first place.
@@ -196,8 +195,8 @@ function save-logs() {
196195
echo "Changing logfiles to be world-readable for download"
197196
log-dump-ssh "${node_name}" "sudo chmod -R a+r /var/log" || true
198197

199-
echo "Copying '${save_files}' from ${node_name}"
200-
copy-logs-from-node "${node_name}" "${dir}" "${save_files}"
198+
echo "Copying '${files}' from ${node_name}"
199+
copy-logs-from-node "${node_name}" "${dir}" "${files}"
201200
}
202201

203202
# Saves a copy of the Windows Docker event log to ${WINDOWS_LOGS_DIR}\docker.log
@@ -224,9 +223,8 @@ function save-windows-logs-via-diagnostics-tool() {
224223
local node="${1}"
225224
local dest_dir="${2}"
226225

227-
gcloud compute instances add-metadata "${node}" --metadata enable-diagnostics=true --project="${PROJECT}" --zone="${ZONE}"
228-
local logs_archive_in_gcs
229-
logs_archive_in_gcs=$(gcloud alpha compute diagnose export-logs "${node}" --zone="${ZONE}" --project="${PROJECT}" | tail -n 1)
226+
gcloud compute instances add-metadata ${node} --metadata enable-diagnostics=true --project=${PROJECT} --zone=${ZONE}
227+
local logs_archive_in_gcs=$(gcloud alpha compute diagnose export-logs ${node} --zone=${ZONE} --project=${PROJECT} | tail -n 1)
230228
local temp_local_path="${node}.zip"
231229
for retry in {1..20}; do
232230
if gsutil mv "${logs_archive_in_gcs}" "${temp_local_path}" > /dev/null 2>&1; then
@@ -238,8 +236,8 @@ function save-windows-logs-via-diagnostics-tool() {
238236
done
239237

240238
if [[ -f "${temp_local_path}" ]]; then
241-
unzip "${temp_local_path}" -d "${dest_dir}" > /dev/null
242-
rm -f "${temp_local_path}"
239+
unzip ${temp_local_path} -d "${dest_dir}" > /dev/null
240+
rm -f ${temp_local_path}
243241
fi
244242
}
245243

@@ -251,14 +249,14 @@ function save-windows-logs-via-ssh() {
251249
export-windows-docker-event-log "${node}"
252250

253251
local remote_files=()
254-
for file in ${windows_node_logfiles}; do
252+
for file in ${windows_node_logfiles[@]}; do
255253
remote_files+=( "${WINDOWS_LOGS_DIR}\\${file}" )
256254
done
257255
remote_files+=( "${windows_node_otherfiles[@]}" )
258256

259257
# TODO(pjh, yujuhong): handle rotated logs and copying multiple files at the
260258
# same time.
261-
for remote_file in "${remote_files[@]}"; do
259+
for remote_file in ${remote_files[@]}; do
262260
# Retry up to 3 times to allow ssh keys to be properly propagated and
263261
# stored.
264262
for retry in {1..3}; do
@@ -280,7 +278,7 @@ function save-logs-windows() {
280278
local -r node="${1}"
281279
local -r dest_dir="${2}"
282280

283-
if [[ ! "${gcloud_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
281+
if [[ ! "${gcloud_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
284282
echo "Not saving logs for ${node}, Windows log dumping requires gcloud support"
285283
return
286284
fi
@@ -302,14 +300,14 @@ function run-in-docker-container() {
302300
local node_name="$1"
303301
local container="$2"
304302
shift 2
305-
log-dump-ssh "${node_name}" "docker exec \"\$(docker ps -f label=io.kubernetes.container.name=${container} --format \"{{.ID}}\")\" $*"
303+
log-dump-ssh "${node_name}" "docker exec \"\$(docker ps -f label=io.kubernetes.container.name=${container} --format \"{{.ID}}\")\" $@"
306304
}
307305

308306
function dump_masters() {
309307
local master_names
310308
if [[ -n "${use_custom_instance_list}" ]]; then
311-
while IFS='' read -r line; do master_names+=("$line"); done < <(log_dump_custom_get_instances master)
312-
elif [[ ! "${master_ssh_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
309+
master_names=( $(log_dump_custom_get_instances master) )
310+
elif [[ ! "${master_ssh_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
313311
echo "Master SSH not supported for ${KUBERNETES_PROVIDER}"
314312
return
315313
elif [[ -n "${KUBEMARK_MASTER_NAME:-}" ]]; then
@@ -360,8 +358,8 @@ function dump_nodes() {
360358
node_names=( "$@" )
361359
elif [[ -n "${use_custom_instance_list}" ]]; then
362360
echo "Dumping logs for nodes provided by log_dump_custom_get_instances() function"
363-
while IFS='' read -r line; do node_names+=("$line"); done < <(log_dump_custom_get_instances node)
364-
elif [[ ! "${node_ssh_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
361+
node_names=( $(log_dump_custom_get_instances node) )
362+
elif [[ ! "${node_ssh_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
365363
echo "Node SSH not supported for ${KUBERNETES_PROVIDER}"
366364
return
367365
else
@@ -388,7 +386,7 @@ function dump_nodes() {
388386
linux_nodes_selected_for_logs=()
389387
if [[ -n "${LOGDUMP_ONLY_N_RANDOM_NODES:-}" ]]; then
390388
# We randomly choose 'LOGDUMP_ONLY_N_RANDOM_NODES' many nodes for fetching logs.
391-
for index in $(shuf -i 0-$(( ${#node_names[*]} - 1 )) -n "${LOGDUMP_ONLY_N_RANDOM_NODES}")
389+
for index in `shuf -i 0-$(( ${#node_names[*]} - 1 )) -n ${LOGDUMP_ONLY_N_RANDOM_NODES}`
392390
do
393391
linux_nodes_selected_for_logs+=("${node_names[$index]}")
394392
done
@@ -437,11 +435,11 @@ function dump_nodes() {
437435
# Sets:
438436
# NON_LOGEXPORTED_NODES
439437
function find_non_logexported_nodes() {
440-
succeeded_nodes=$(gsutil ls "${gcs_artifacts_dir}/logexported-nodes-registry") || return 1
438+
succeeded_nodes=$(gsutil ls ${gcs_artifacts_dir}/logexported-nodes-registry) || return 1
441439
echo "Successfully listed marker files for successful nodes"
442440
NON_LOGEXPORTED_NODES=()
443441
for node in "${NODE_NAMES[@]}"; do
444-
if [[ ! "${succeeded_nodes}" =~ ${node} ]]; then
442+
if [[ ! "${succeeded_nodes}" =~ "${node}" ]]; then
445443
NON_LOGEXPORTED_NODES+=("${node}")
446444
fi
447445
done
@@ -452,7 +450,7 @@ function find_non_logexported_nodes() {
452450
function dump_nodes_with_logexporter() {
453451
if [[ -n "${use_custom_instance_list}" ]]; then
454452
echo "Dumping logs for nodes provided by log_dump_custom_get_instances() function"
455-
while IFS='' read -r line; do NODE_NAMES+=("$line"); done < <(log_dump_custom_get_instances node)
453+
NODE_NAMES=( $(log_dump_custom_get_instances node) )
456454
else
457455
echo "Detecting nodes in the cluster"
458456
detect-node-names &> /dev/null
@@ -464,7 +462,7 @@ function dump_nodes_with_logexporter() {
464462
fi
465463

466464
# Obtain parameters required by logexporter.
467-
local -r service_account_credentials="$(base64 "${GOOGLE_APPLICATION_CREDENTIALS}" | tr -d '\n')"
465+
local -r service_account_credentials="$(cat ${GOOGLE_APPLICATION_CREDENTIALS} | base64 | tr -d '\n')"
468466
local -r cloud_provider="${KUBERNETES_PROVIDER}"
469467
local -r enable_hollow_node_logs="${ENABLE_HOLLOW_NODE_LOGS:-false}"
470468
local -r logexport_sleep_seconds="$(( 90 + NUM_NODES / 3 ))"
@@ -506,10 +504,10 @@ function dump_nodes_with_logexporter() {
506504
# Store logs from logexporter pods to allow debugging log exporting process
507505
# itself.
508506
proc=${max_dump_processes}
509-
while read -r pod node; do
507+
"${KUBECTL}" get pods -n "${logexporter_namespace}" -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}' | while read pod node; do
510508
echo "Fetching logs from ${pod} running on ${node}"
511-
mkdir -p "${report_dir}/${node}"
512-
"${KUBECTL}" logs -n "${logexporter_namespace}" "${pod}" > "${report_dir}/${node}/${pod}.log" &
509+
mkdir -p ${report_dir}/${node}
510+
"${KUBECTL}" logs -n "${logexporter_namespace}" ${pod} > ${report_dir}/${node}/${pod}.log &
513511

514512
# We don't want to run more than ${max_dump_processes} at a time, so
515513
# wait once we hit that many nodes. This isn't ideal, since one might
@@ -519,13 +517,14 @@ function dump_nodes_with_logexporter() {
519517
proc=${max_dump_processes}
520518
wait
521519
fi
522-
done < <("${KUBECTL}" get pods -n "${logexporter_namespace}" -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.nodeName}{"\n"}{end}')
520+
done
523521
# Wait for any remaining processes.
524522
if [[ proc -gt 0 && proc -lt ${max_dump_processes} ]]; then
525523
wait
526524
fi
527525

528526
# List registry of marker files (of nodes whose logexporter succeeded) from GCS.
527+
local nodes_succeeded
529528
for retry in {1..10}; do
530529
if find_non_logexported_nodes; then
531530
break
@@ -555,33 +554,32 @@ function dump_nodes_with_logexporter() {
555554
"${KUBECTL}" get pods --namespace "${logexporter_namespace}" || true
556555
"${KUBECTL}" delete namespace "${logexporter_namespace}" || true
557556
if [[ "${#failed_nodes[@]}" != 0 ]]; then
558-
echo -e "Dumping logs through SSH for the following nodes:\n${failed_nodes[*]}"
557+
echo -e "Dumping logs through SSH for the following nodes:\n${failed_nodes[@]}"
559558
dump_nodes "${failed_nodes[@]}"
560559
fi
561560
}
562561

563562
function detect_node_failures() {
564-
if ! [[ "${gcloud_supported_providers}" =~ ${KUBERNETES_PROVIDER} ]]; then
563+
if ! [[ "${gcloud_supported_providers}" =~ "${KUBERNETES_PROVIDER}" ]]; then
565564
return
566565
fi
567566

568567
detect-node-names
569568
if [[ "${KUBERNETES_PROVIDER}" == "gce" ]]; then
570-
local all_instance_groups=("${INSTANCE_GROUPS[@]}" "${WINDOWS_INSTANCE_GROUPS[@]}")
569+
local all_instance_groups=(${INSTANCE_GROUPS[@]} ${WINDOWS_INSTANCE_GROUPS[@]})
571570
else
572-
local all_instance_groups=("${INSTANCE_GROUPS[@]}")
571+
local all_instance_groups=(${INSTANCE_GROUPS[@]})
573572
fi
574573

575574
if [ -z "${all_instance_groups:-}" ]; then
576575
return
577576
fi
578577
for group in "${all_instance_groups[@]}"; do
579-
local creation_timestamp
580-
creation_timestamp=$(gcloud compute instance-groups managed describe \
581-
"${group}" \
582-
--project "${PROJECT}" \
583-
--zone "${ZONE}" \
584-
--format='value(creationTimestamp)')
578+
local creation_timestamp=$(gcloud compute instance-groups managed describe \
579+
"${group}" \
580+
--project "${PROJECT}" \
581+
--zone "${ZONE}" \
582+
--format='value(creationTimestamp)')
585583
echo "Failures for ${group} (if any):"
586584
gcloud logging read --order=asc \
587585
--format='table(timestamp,jsonPayload.resource.name,jsonPayload.event_subtype)' \

hack/.shellcheck_failures

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
./cluster/gce/gci/master-helper.sh
99
./cluster/gce/upgrade.sh
1010
./cluster/gce/util.sh
11+
./cluster/log-dump/log-dump.sh
1112
./cluster/pre-existing/util.sh

0 commit comments

Comments
 (0)