Skip to content

Commit 9b7acec

Browse files
Collect additional logs with CAPD log collector
Signed-off-by: Alexandr Demicev <[email protected]>
1 parent c62c864 commit 9b7acec

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/framework/docker_logcollector.go

Lines changed: 19 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,8 @@ 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+
162+
collectFuncs := []func() error{
153163
execToPathFn(
154164
"journal.log",
155165
"journalctl", "--no-pager", "--output=short-precise",
@@ -175,7 +185,13 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath
175185
"journalctl", "--no-pager", "--output=short-precise", "-u", "containerd.service",
176186
),
177187
copyDirFn("/var/log/pods", "pods"),
178-
})
188+
}
189+
190+
for _, additionalLogs := range k.AdditionalLogs {
191+
collectFuncs = append(collectFuncs, execToPathFn(additionalLogs.OutputFileName, additionalLogs.Command, additionalLogs.Args...))
192+
}
193+
194+
return errors.AggregateConcurrent(collectFuncs)
179195
}
180196

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

0 commit comments

Comments
 (0)