diff --git a/test/framework/log/collector.go b/test/framework/log/collector.go index 1f66e8d74b..224c5430b6 100644 --- a/test/framework/log/collector.go +++ b/test/framework/log/collector.go @@ -26,6 +26,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/pkg/errors" "github.com/vmware/govmomi" @@ -37,7 +38,6 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1" "sigs.k8s.io/controller-runtime/pkg/client" - kinderrors "sigs.k8s.io/kind/pkg/errors" ) const ( @@ -84,7 +84,7 @@ func (c *MachineLogCollector) CollectMachineLog(ctx context.Context, _ client.Cl } } - return kinderrors.AggregateConcurrent([]func() error{ + return aggregateConcurrent( captureLogs("kubelet.log", "sudo journalctl", "--no-pager", "--output=short-precise", "-u", "kubelet.service"), captureLogs("containerd.log", @@ -93,7 +93,7 @@ func (c *MachineLogCollector) CollectMachineLog(ctx context.Context, _ client.Cl "sudo", "cat", "/var/log/cloud-init.log"), captureLogs("cloud-init-output.log", "sudo", "cat", "/var/log/cloud-init-output.log"), - }) + ) } func (c *MachineLogCollector) CollectInfrastructureLogs(_ context.Context, _ client.Client, _ *clusterv1.Cluster, _ string) error { @@ -216,3 +216,28 @@ func readPrivateKey() ([]byte, error) { return os.ReadFile(filepath.Clean(privateKeyFilePath)) } + +// aggregateConcurrent runs fns concurrently, returning aggregated errors. +func aggregateConcurrent(funcs ...func() error) error { + // run all fns concurrently + ch := make(chan error, len(funcs)) + var wg sync.WaitGroup + for _, f := range funcs { + f := f + wg.Add(1) + go func() { + defer wg.Done() + ch <- f() + }() + } + wg.Wait() + close(ch) + // collect up and return errors + errs := []error{} + for err := range ch { + if err != nil { + errs = append(errs, err) + } + } + return kerrors.NewAggregate(errs) +} diff --git a/test/go.mod b/test/go.mod index 92fb3635e3..06bbe88cd0 100644 --- a/test/go.mod +++ b/test/go.mod @@ -32,7 +32,6 @@ require ( sigs.k8s.io/cluster-api-provider-vsphere v0.0.0-00010101000000-000000000000 sigs.k8s.io/cluster-api/test v0.0.0-00010101000000-000000000000 sigs.k8s.io/controller-runtime v0.17.5 - sigs.k8s.io/kind v0.22.0 sigs.k8s.io/yaml v1.4.0 ) @@ -168,5 +167,6 @@ require ( k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect + sigs.k8s.io/kind v0.22.0 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect )