@@ -21,14 +21,17 @@ package shared
21
21
22
22
import (
23
23
"context"
24
+ "encoding/base64"
24
25
"fmt"
25
26
"os"
26
27
"path"
27
28
"path/filepath"
29
+ "strings"
28
30
"time"
29
31
30
32
. "github.com/onsi/ginkgo/v2"
31
33
. "github.com/onsi/gomega"
34
+ "github.com/pkg/errors"
32
35
corev1 "k8s.io/api/core/v1"
33
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
37
crclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -203,8 +206,18 @@ func DumpMachine(ctx context.Context, e2eCtx *E2EContext, machine infrav1.AWSMac
203
206
title : "containerd" ,
204
207
cmd : "journalctl --no-pager -u containerd.service" ,
205
208
},
209
+ {
210
+ title : "pod-logs" ,
211
+ cmd : "sudo tar -czf - -C /var/log pods | base64 -w0" ,
212
+ },
206
213
},
207
214
)
215
+
216
+ // Post-process pod-logs to have a tar.gz file instead of base64 date encoded in the log file.
217
+ // Note: It is not possible to directly output the raw tar.gz data because something truncates it.
218
+ if err := postProcessBase64LogData (filepath .Dir (f .Name ()), "pod-logs.log" , "pod-logs.tar.gz" ); err != nil {
219
+ fmt .Fprintf (GinkgoWriter , "Failed to post-process pod-logs: %v\n " , err )
220
+ }
208
221
}
209
222
210
223
func DumpSpecResources (ctx context.Context , e2eCtx * E2EContext , namespace * corev1.Namespace ) {
@@ -287,3 +300,39 @@ func CreateAWSClusterControllerIdentity(k8sclient crclient.Client) {
287
300
func Byf (format string , a ... interface {}) {
288
301
By (fmt .Sprintf (format , a ... ))
289
302
}
303
+
304
+ func postProcessBase64LogData (dir , src , dst string ) error {
305
+ sourceFile := filepath .Clean (path .Join (dir , src ))
306
+ destinationFile := filepath .Clean (path .Join (dir , dst ))
307
+
308
+ // Read input data
309
+ inputData , err := os .ReadFile (sourceFile )
310
+ if err != nil {
311
+ return errors .Wrapf (err , "unable to read source file %q" , sourceFile )
312
+ }
313
+
314
+ // Extract second line which contains the data (first line contains the command)
315
+ inputStringData := strings .Split (string (inputData ), "\n " )[1 ]
316
+
317
+ // Trim spaces and the $ suffix.
318
+ inputStringData = strings .TrimSpace (inputStringData )
319
+ inputStringData = strings .TrimSuffix (inputStringData , "$" )
320
+
321
+ // Base64 decode the data
322
+ outputData , err := base64 .StdEncoding .DecodeString (inputStringData )
323
+ if err != nil {
324
+ return errors .Wrapf (err , "unable to base64 decode input data" )
325
+ }
326
+
327
+ // Write the destination file
328
+ if err := os .WriteFile (destinationFile , outputData , 0600 ); err != nil {
329
+ return errors .Wrapf (err , "unable to write destination file at %q" , destinationFile )
330
+ }
331
+
332
+ // Delete the source file.
333
+ if err := os .Remove (sourceFile ); err != nil {
334
+ return errors .Wrapf (err , "unable to delete source file at %q" , sourceFile )
335
+ }
336
+
337
+ return nil
338
+ }
0 commit comments