Skip to content

Commit 2fc94f4

Browse files
committed
Support Export Compression
This update changes the support export command to produce a compressed .tar.gz file instead of an uncompressed .tar file. Relevant tests are updated accordingly. Issue: [sc-18010]
1 parent 7298dc6 commit 2fc94f4

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

internal/cmd/export.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cmd
1717
import (
1818
"archive/tar"
1919
"bytes"
20+
"compress/gzip"
2021
"context"
2122
"fmt"
2223
"io"
@@ -226,18 +227,25 @@ kubectl pgo support export daisy --monitoring-namespace another-namespace --outp
226227
}
227228

228229
// Name file with year-month-day-HrMinSecTimezone suffix
229-
// Example: crunchy_k8s_support_export_2022-08-08-115726-0400.tar
230-
outputFile := "crunchy_k8s_support_export_" + time.Now().Format("2006-01-02-150405-0700") + ".tar"
230+
// Example: crunchy_k8s_support_export_2022-08-08-115726-0400.tar.gz
231+
outputFile := "crunchy_k8s_support_export_" + time.Now().Format("2006-01-02-150405-0700") + ".tar.gz"
231232
// #nosec G304 -- We intentionally write to the directory supplied by the user.
232233
tarFile, err := os.Create(outputDir + "/" + outputFile)
233234
if err != nil {
234235
return err
235236
}
236237

237-
tw := tar.NewWriter(tarFile)
238+
gw, err := gzip.NewWriterLevel(tarFile, gzip.BestCompression)
239+
if err != nil {
240+
return err
241+
}
242+
tw := tar.NewWriter(gw)
238243
defer func() {
239244
// ignore any errors from Close functions, the writers will be
240245
// closed when the program exits
246+
if gw != nil {
247+
_ = gw.Close()
248+
}
241249
if tw != nil {
242250
_ = tw.Close()
243251
}

testing/kuttl/e2e/support-export/01--support_export.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
55
- script: kubectl-pgo --namespace $NAMESPACE support export kuttl-support-cluster -o .
6-
- script: tar -xf ./crunchy_k8s_support_export_*.tar
6+
- script: tar -xf ./crunchy_k8s_support_export_*.tar.gz
77
- script: |
88
#!/bin/bash
99
1010
DIR="./kuttl-support-cluster/nodes/"
1111
LIST="${DIR}list"
1212
13-
CLEANUP="rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar"
13+
CLEANUP="rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar.gz"
14+
15+
# check for expected gzip compression level
16+
FILE_INFO=$(file ./crunchy_k8s_support_export_*.tar.gz)
17+
[[ "${FILE_INFO}" == *'gzip compressed data, max compression'* ]] || {
18+
echo "Expected gzip max compression message, got:"
19+
echo "${FILE_INFO}"
20+
eval "$CLEANUP"
21+
exit 1
22+
}
1423
1524
# check for expected table header in the list file
1625
KV=$(awk 'NR==1 {print $9}' $LIST)
@@ -50,4 +59,4 @@ commands:
5059
exit 1
5160
fi
5261
53-
- script: rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar
62+
- script: rm -r ./kuttl-support-cluster ./crunchy_k8s_support_export_*.tar.gz

testing/kuttl/e2e/support-export/21--support_export.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestStep
44
commands:
55
- script: kubectl-pgo --namespace $NAMESPACE support export kuttl-support-monitoring-cluster -o .
6-
- script: tar -xf ./crunchy_k8s_support_export_*.tar
6+
- script: tar -xf ./crunchy_k8s_support_export_*.tar.gz
77
- script: |
88
#!/bin/bash
99
10-
CLEANUP="rm -r ./kuttl-support-monitoring-cluster ./monitoring ./crunchy_k8s_support_export_*.tar"
10+
CLEANUP="rm -r ./kuttl-support-monitoring-cluster ./monitoring ./crunchy_k8s_support_export_*.tar.gz"
1111
CLUSTER_DIR="./kuttl-support-monitoring-cluster/logs/"
1212
MONITORING_DIR="./monitoring/logs/"
1313
@@ -40,4 +40,4 @@ commands:
4040
exit 1
4141
fi
4242
43-
- script: rm -r ./kuttl-support-monitoring-cluster ./monitoring ./crunchy_k8s_support_export_*.tar
43+
- script: rm -r ./kuttl-support-monitoring-cluster ./monitoring ./crunchy_k8s_support_export_*.tar.gz

0 commit comments

Comments
 (0)