Skip to content

Commit 63adba4

Browse files
committed
post-process tarball
1 parent dabfe36 commit 63adba4

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

test/e2e/shared/common.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package shared
2121

2222
import (
2323
"context"
24+
"encoding/base64"
2425
"fmt"
2526
"os"
2627
"path"
@@ -204,12 +205,27 @@ func DumpMachine(ctx context.Context, e2eCtx *E2EContext, machine infrav1.AWSMac
204205
cmd: "journalctl --no-pager -u containerd.service",
205206
},
206207
{
207-
title: "pod-logs",
208-
cmd: "sudo tar -czf - -C /var/log pods | base64 -w0",
209-
suffix: ".tar.gz",
208+
title: "pod-logs",
209+
cmd: "sudo tar -czf - -C /var/log pods | base64",
210210
},
211211
},
212212
)
213+
214+
// post-process pod-logs to have a tar.gz file instead of a base64 txt.
215+
sourcePodLogsFile := path.Join(filepath.Dir(f.Name()), "pod-logs.txt")
216+
targetPodLogsFile := path.Join(filepath.Dir(f.Name()), "pod-logs.tar.gz")
217+
inputData, err := os.ReadFile(sourcePodLogsFile)
218+
if err != nil {
219+
fmt.Fprintf(GinkgoWriter, "Couldn't read pod-logs command output: path=%q, err=%s\n", sourcePodLogsFile, err)
220+
return
221+
}
222+
outputData := []byte{}
223+
if _, err := base64.RawStdEncoding.Decode(outputData, inputData); err != nil {
224+
fmt.Fprintf(GinkgoWriter, "Couldn't base64 decode pod-logs: path=%q, err=%s\n", sourcePodLogsFile, err)
225+
return
226+
}
227+
os.WriteFile(targetPodLogsFile, outputData, 0600)
228+
os.Remove(sourcePodLogsFile)
213229
}
214230

215231
func DumpSpecResources(ctx context.Context, e2eCtx *E2EContext, namespace *corev1.Namespace) {

test/e2e/shared/exec.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ func allMachines(ctx context.Context, e2eCtx *E2EContext) ([]instance, error) {
7575
}
7676

7777
type command struct {
78-
title string
79-
suffix string
80-
cmd string
78+
title string
79+
cmd string
8180
}
8281

8382
// commandsForMachine opens a terminal connection using AWS SSM Session Manager
@@ -114,11 +113,7 @@ func commandsForMachine(ctx context.Context, e2eCtx *E2EContext, f *os.File, ins
114113
return
115114
}
116115
for _, c := range commands {
117-
suffix := ".log"
118-
if c.suffix != "" {
119-
suffix = c.suffix
120-
}
121-
logFile := path.Join(filepath.Dir(f.Name()), c.title+suffix)
116+
logFile := path.Join(filepath.Dir(f.Name()), c.title+".log")
122117
if err := e.Send("sudo " + c.cmd + "\n"); err != nil {
123118
fmt.Fprintf(f, "unable to send command: err=%s", err)
124119
return

0 commit comments

Comments
 (0)