Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#11083 from alexander-demicev/colle…
Browse files Browse the repository at this point in the history
…dctadditionallogs

✨ Collect additional logs with CAPD log collector
  • Loading branch information
k8s-ci-robot authored Aug 26, 2024
2 parents d4d7753 + 9b7acec commit 87884a1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/framework/docker_logcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down

0 comments on commit 87884a1

Please sign in to comment.