From 9b7acecc668885ec3f6950bf641e38bce7792061 Mon Sep 17 00:00:00 2001 From: Alexandr Demicev Date: Thu, 22 Aug 2024 11:19:28 +0200 Subject: [PATCH] Collect additional logs with CAPD log collector Signed-off-by: Alexandr Demicev --- test/framework/docker_logcollector.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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