Skip to content

Commit fe7cfce

Browse files
authored
tests: define /tmp/k8s-service-logs in a single place only. (#17184)
1 parent 5e43242 commit fe7cfce

File tree

6 files changed

+41
-36
lines changed

6 files changed

+41
-36
lines changed

scripts/ci/collect-collector-metrics.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -eu
44
# Gather collector metrics script
55

66
usage() {
7-
echo "$0 <namespace> <output-dir> <pod-port> <path>"
7+
echo "$0 <namespace> <output-dir> [<pod-port> [<path>]]"
88
echo "e.g. $0 stackrox /logs 9090 metrics"
99
}
1010

@@ -16,16 +16,18 @@ die() {
1616
main() {
1717
service="collector"
1818

19-
if [ $# -gt 0 ]; then
20-
namespace="$1"
19+
if [ $# -eq 0 ]; then
20+
usage
21+
die "Please specify the namespace argument."
2122
else
22-
namespace="stackrox"
23+
namespace="$1"
2324
fi
2425

25-
if [ $# -gt 1 ]; then
26-
metrics_dir="$2"
26+
if [ $# -lt 2 ]; then
27+
usage
28+
die "Please specify the metrics dir argument."
2729
else
28-
metrics_dir="/tmp/k8s-service-logs/$namespace/metrics"
30+
metrics_dir="$2"
2931
fi
3032
mkdir -p "${metrics_dir}"
3133

scripts/ci/collect-infrastructure-logs.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ set -eu
77
# future examination.
88
#
99
# Usage:
10-
# collect-infrastructure-logs.sh [<output-dir>]
10+
# collect-infrastructure-logs.sh <output-dir>
1111
#
1212
# Example:
13-
# $ ./scripts/ci/collect-infrastructure-logs.sh
13+
# $ ./scripts/ci/collect-infrastructure-logs.sh /tmp/logs-dir
1414
#
1515
# Assumptions:
1616
# - Must be called from the root of the Apollo git repository.
17-
# - Logs are saved under /tmp/k8s-service-logs/ by default
17+
# - Requires a single argument: path to save logs to.
1818

1919

2020
SCRIPTS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)"
2121
# shellcheck source=../../scripts/ci/lib.sh
2222
source "$SCRIPTS_ROOT/scripts/lib.sh"
2323

24-
if [ $# -gt 0 ]; then
25-
log_dir="$1"
24+
if [ $# -eq 0 ]; then
25+
die "Usage: $0 <path-to-collect-logs-to>"
2626
else
27-
log_dir="/tmp/k8s-service-logs"
27+
log_dir="$1"
2828
fi
2929

3030
# This will attempt to collect kube API server audit logs on OpenShift.

scripts/ci/collect-qa-service-logs.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ set -eu
77
# future examination.
88
#
99
# Usage:
10-
# collect-qa-service-logs.sh [DIR]
10+
# collect-qa-service-logs.sh DIR
1111
#
1212
# Example:
13-
# $ ./scripts/ci/collect-qa-service-logs.sh
13+
# $ ./scripts/ci/collect-qa-service-logs.sh /tmp/some-directory
1414
#
1515
# Assumptions:
1616
# - Must be called from the root of the Apollo git repository.
17-
# - Logs are saved under /tmp/k8s-service-logs/ or DIR if passed
17+
# - Requires a single argument: path to save logs to.
1818

1919
main() {
2020
set +e
2121
for ns in $(kubectl get ns -o json | jq -r '.items[].metadata.name' | grep -E '^qa'); do
2222
echo "Collecting from namespace: ${ns}"
23-
./scripts/ci/collect-service-logs.sh "${ns}" $@
23+
./scripts/ci/collect-service-logs.sh "${ns}" "$@"
2424
done
2525
}
2626

scripts/ci/collect-service-logs.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ set -euo pipefail
88
# future examination.
99
#
1010
# Usage:
11-
# collect-service-logs.sh NAMESPACE [DIR]
11+
# collect-service-logs.sh NAMESPACE DIR
1212
#
1313
# Example:
14-
# $ ./scripts/ci/collect-service-logs.sh stackrox
14+
# $ ./scripts/ci/collect-service-logs.sh stackrox /tmp/some-directory
1515
#
1616
# Assumptions:
1717
# - Must be called from the root of the Apollo git repository.
18-
# - Logs are saved under /tmp/k8s-service-logs/ or DIR if passed
18+
# - Requires a two arguments: namespace name, and path to save logs to.
19+
# - Creates the path if missing.
1920

2021
SCRIPTS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)"
2122
# shellcheck source=../../scripts/ci/lib.sh
2223
source "$SCRIPTS_ROOT/scripts/ci/lib.sh"
2324

2425
usage() {
25-
echo "./scripts/ci/collect-service-logs.sh <namespace> [<output-dir>]"
26-
echo "e.g. ./scripts/ci/collect-service-logs.sh stackrox"
26+
echo "./scripts/ci/collect-service-logs.sh <namespace> <output-dir>"
27+
echo "e.g. ./scripts/ci/collect-service-logs.sh stackrox /tmp/some-directory"
2728
}
2829

2930
dump_logs() {
@@ -56,10 +57,10 @@ main() {
5657
exit 0
5758
fi
5859

59-
if [ $# -gt 1 ]; then
60-
log_dir="$2"
60+
if [ $# -lt 2 ]; then
61+
die "Usage: $0 <namespace> <path-to-collect-logs-to>"
6162
else
62-
log_dir="/tmp/k8s-service-logs"
63+
log_dir="$2"
6364
fi
6465
log_dir="${log_dir}/${namespace}"
6566
mkdir -p "${log_dir}"

scripts/secured-cluster-diagnostics.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,18 @@ save_collector_diagnostics() {
227227
}
228228
229229
main() {
230-
if [ $# -gt 0 ]; then
231-
namespace="$1"
230+
if [ $# -eq 0 ]; then
231+
usage
232+
die "Please specify the namespace argument."
232233
else
233-
namespace="stackrox"
234+
namespace="$1"
234235
fi
235236
236-
if [ $# -gt 1 ]; then
237-
output_dir="$2"
237+
if [ $# -lt 2 ]; then
238+
usage
239+
die "Please specify the output dir argument."
238240
else
239-
output_dir="/tmp/k8s-service-logs/$namespace/metrics"
241+
output_dir="$2"
240242
fi
241243
mkdir -p "${output_dir}"
242244

tests/e2e/lib.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ check_stackrox_logs() {
684684
local dir="$1"
685685

686686
if [[ ! -d "$dir/stackrox/pods" ]]; then
687-
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox)"
687+
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox $dir)"
688688
fi
689689

690690
check_for_stackrox_OOMs "$dir"
@@ -700,7 +700,7 @@ check_for_stackrox_OOMs() {
700700
local dir="$1"
701701

702702
if [[ ! -d "$dir/stackrox/pods" ]]; then
703-
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox)"
703+
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox $dir)"
704704
fi
705705

706706
local objects
@@ -787,7 +787,7 @@ check_for_stackrox_restarts() {
787787
local dir="$1"
788788

789789
if [[ ! -d "$dir/stackrox/pods" ]]; then
790-
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox)"
790+
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox $dir)"
791791
fi
792792

793793
local previous_logs
@@ -819,7 +819,7 @@ check_for_errors_in_stackrox_logs() {
819819
local dir="$1/stackrox/pods"
820820

821821
if [[ ! -d "${dir}" ]]; then
822-
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox)"
822+
die "StackRox logs were not collected. (Use ./scripts/ci/collect-service-logs.sh stackrox $dir)"
823823
fi
824824

825825
local pod_objects=()
@@ -878,7 +878,7 @@ _verify_item_count() {
878878
# used by ./scripts/ci/collect-service-logs.sh
879879

880880
if [[ ! -f "${dir}/ITEM_COUNT.txt" ]]; then
881-
die "ITEM_COUNT.txt is missing. (Check output from ./scripts/ci/collect-service-logs.sh"
881+
die "ITEM_COUNT.txt is missing. (Check output from ./scripts/ci/collect-service-logs.sh)"
882882
fi
883883

884884
local item_count

0 commit comments

Comments
 (0)