|
2 | 2 |
|
3 | 3 | set -euo pipefail |
4 | 4 |
|
5 | | -tmpdir="$(mktemp -d)" |
| 5 | +readonly PRJ_ROOT=$(dirname $(dirname -- "$( readlink -f -- $0)")) |
| 6 | +tmpdir="" |
| 7 | +function cleanup() { |
| 8 | + test -d "$tmpdir" && rm -r "$tmpdir" || : |
| 9 | +} |
| 10 | + |
| 11 | +function recreate_tmpdir() { |
| 12 | + cleanup |
| 13 | + tmpdir="$(mktemp -d)" |
| 14 | +} |
| 15 | +# Cleanup on exit |
| 16 | +trap cleanup EXIT |
| 17 | + |
6 | 18 | bundle_archive_name="support-bundle.tar.gz" |
7 | 19 | bundle_directory_name="support-bundle" |
8 | 20 |
|
9 | 21 | echo "====== Generating support bundle from k8s cluster ======" |
| 22 | +recreate_tmpdir |
10 | 23 | ./bin/support-bundle --debug --interactive=false examples/support-bundle/e2e.yaml --output=$tmpdir/$bundle_archive_name |
11 | 24 | if [ $? -ne 0 ]; then |
12 | 25 | echo "support-bundle command failed" |
@@ -43,23 +56,46 @@ if [ $EXIT_STATUS -ne 0 ]; then |
43 | 56 | fi |
44 | 57 |
|
45 | 58 | echo "======= Redact an existing support bundle ======" |
46 | | -redact_tmpdir="$(mktemp -d)" |
47 | | -redacted_archive_name="$redact_tmpdir/redacted-support-bundle.tar.gz" |
| 59 | +redacted_archive_name="$tmpdir/redacted-support-bundle.tar.gz" |
48 | 60 | ./bin/support-bundle redact examples/redact/e2e.yaml --bundle=$tmpdir/$bundle_archive_name --output=$redacted_archive_name |
49 | 61 | if [ $? -ne 0 ]; then |
50 | 62 | echo "support-bundle redact command failed" |
51 | 63 | exit $? |
52 | 64 | fi |
53 | 65 |
|
54 | | -if ! tar -xvzf $redacted_archive_name --directory $redact_tmpdir; then |
| 66 | +if ! tar -xvzf $redacted_archive_name --directory $tmpdir; then |
55 | 67 | echo "Failed to extract redacted support bundle archive" |
56 | 68 | exit 1 |
57 | 69 | fi |
58 | 70 |
|
59 | | -if ! grep "\*\*\*HIDDEN\*\*\*" "$redact_tmpdir/$bundle_directory_name/static-hi.log"; then |
60 | | - echo "$(cat $redact_tmpdir/$bundle_directory_name/static-hi.log)" |
| 71 | +if ! grep "\*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_directory_name/static-hi.log"; then |
| 72 | + echo "$(cat $tmpdir/$bundle_directory_name/static-hi.log)" |
61 | 73 | echo "Hidden content not found in redacted static-hi.log file" |
62 | 74 | exit 1 |
63 | 75 | fi |
64 | 76 |
|
65 | | -rm -rf "$tmpdir" "$redact_tmpdir" |
| 77 | +echo "======= Generating support bundle from k8s cluster using --load-cluster-specs ======" |
| 78 | +recreate_tmpdir |
| 79 | +kubectl apply -f "$PRJ_ROOT/testdata/supportbundle/labelled-specs" |
| 80 | +./bin/support-bundle -v1 --interactive=false --load-cluster-specs --output=$tmpdir/$bundle_archive_name |
| 81 | +if [ $? -ne 0 ]; then |
| 82 | + echo "support-bundle command failed" |
| 83 | + exit $? |
| 84 | +fi |
| 85 | + |
| 86 | +if ! tar -xvzf $tmpdir/$bundle_archive_name --directory $tmpdir; then |
| 87 | + echo "A valid support bundle archive was not generated" |
| 88 | + exit 1 |
| 89 | +fi |
| 90 | + |
| 91 | +if ! grep "labelled-support-bundle-1 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_directory_name/echo-hi-1"; then |
| 92 | + echo "$(cat $tmpdir/$bundle_directory_name/echo-hi-1)" |
| 93 | + echo "Hidden content not found in redacted echo-hi-1 file" |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | + |
| 97 | +if ! grep "labelled-support-bundle-2 \*\*\*HIDDEN\*\*\*" "$tmpdir/$bundle_directory_name/echo-hi-2"; then |
| 98 | + echo "$(cat $tmpdir/$bundle_directory_name/echo-hi-2)" |
| 99 | + echo "Hidden content not found in redacted echo-hi-2 file" |
| 100 | + exit 1 |
| 101 | +fi |
0 commit comments