Skip to content

Commit 6e36eab

Browse files
Collect additional logs with CAPD log collector
1 parent 688af4a commit 6e36eab

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

test/framework/docker_logcollector.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,16 @@ import (
3535
)
3636

3737
// DockerLogCollector collect logs from a CAPD workload cluster.
38-
type DockerLogCollector struct{}
38+
type DockerLogCollector struct {
39+
AdditionalLogs []AdditionalLogs
40+
}
41+
42+
// AdditionalLogs is a struct to hold instruction for additional logs that need to be collected.
43+
type AdditionalLogs struct {
44+
OutputFileName string
45+
Command string
46+
Args []string
47+
}
3948

4049
// machineContainerName return a container name using the same rule used in CAPD.
4150
// NOTE: if the cluster name is already included in the machine name, the cluster name is not add thus
@@ -149,7 +158,7 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
149158
return osExec.Command("tar", "--extract", "--file", tempfileName, "--directory", outputDir).Run() //nolint:gosec // We don't care about command injection here.
150159
}
151160
}
152-
return errors.AggregateConcurrent([]func() error{
161+
logs := []func() error{
153162
execToPathFn(
154163
"journal.log",
155164
"journalctl", "--no-pager", "--output=short-precise",
@@ -175,7 +184,13 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
175184
"journalctl", "--no-pager", "--output=short-precise", "-u", "containerd.service",
176185
),
177186
copyDirFn("/var/log/pods", "pods"),
178-
})
187+
}
188+
189+
for _, additionalLogs := range k.AdditionalLogs {
190+
logs = append(logs, execToPathFn(additionalLogs.OutputFileName, additionalLogs.Command, additionalLogs.Args...))
191+
}
192+
193+
return errors.AggregateConcurrent(logs)
179194
}
180195

181196
// fileOnHost is a helper to create a file at path

0 commit comments

Comments
 (0)