diff --git a/test/framework/docker_logcollector.go b/test/framework/docker_logcollector.go index 6655685cb2a2..6b63062d1f5b 100644 --- a/test/framework/docker_logcollector.go +++ b/test/framework/docker_logcollector.go @@ -35,7 +35,16 @@ import ( ) // DockerLogCollector collect logs from a CAPD workload cluster. -type DockerLogCollector struct{} +type DockerLogCollector struct { + AdditionalLogs []AdditionalLogs +} + +// AdditionalLogs is a struct to hold instruction for additional logs that need to be collected. +type AdditionalLogs struct { + OutputFileName string + Command string + Args []string +} // machineContainerName return a container name using the same rule used in CAPD. // 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 return osExec.Command("tar", "--extract", "--file", tempfileName, "--directory", outputDir).Run() //nolint:gosec // We don't care about command injection here. } } - return errors.AggregateConcurrent([]func() error{ + + collectFuncs := []func() error{ execToPathFn( "journal.log", "journalctl", "--no-pager", "--output=short-precise", @@ -175,7 +185,13 @@ func (k DockerLogCollector) collectLogsFromNode(ctx context.Context, outputPath "journalctl", "--no-pager", "--output=short-precise", "-u", "containerd.service", ), copyDirFn("/var/log/pods", "pods"), - }) + } + + for _, additionalLogs := range k.AdditionalLogs { + collectFuncs = append(collectFuncs, execToPathFn(additionalLogs.OutputFileName, additionalLogs.Command, additionalLogs.Args...)) + } + + return errors.AggregateConcurrent(collectFuncs) } // fileOnHost is a helper to create a file at path