Skip to content

Commit

Permalink
remove direct dependency on kind
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed May 21, 2024
1 parent 718cb44 commit 84beaf1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions test/framework/log/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/pkg/errors"
"github.com/vmware/govmomi"
Expand All @@ -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 (
Expand Down Expand Up @@ -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",
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
)

0 comments on commit 84beaf1

Please sign in to comment.