Skip to content

Commit

Permalink
test: parallelize log gathering
Browse files Browse the repository at this point in the history
We are running multiple kubectl commands to gather logs. This change
makes the gathering commands run in parallel.

Signed-off-by: Maciej Kwiek <maciej@isovalent.com>
  • Loading branch information
nebril authored and aanm committed May 29, 2020
1 parent 31a622e commit 9ea244f
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3793,21 +3793,27 @@ func (kub *Kubectl) reportMapContext(ctx context.Context, path string, reportCmd

// reportMapHost saves executed commands to files based on provided map
func (kub *Kubectl) reportMapHost(ctx context.Context, path string, reportCmds map[string]string) {
wg := sync.WaitGroup{}
for cmd, logfile := range reportCmds {
res := kub.ExecContext(ctx, cmd)
wg.Add(1)
go func(cmd, logfile string) {
defer wg.Done()
res := kub.ExecContext(ctx, cmd)

if !res.WasSuccessful() {
log.WithError(res.GetErr("reportMapHost")).Errorf("command %s failed", cmd)
}
if !res.WasSuccessful() {
log.WithError(res.GetErr("reportMapHost")).Errorf("command %s failed", cmd)
}

err := ioutil.WriteFile(
fmt.Sprintf("%s/%s", path, logfile),
res.CombineOutput().Bytes(),
LogPerm)
if err != nil {
log.WithError(err).Errorf("cannot create test results for command '%s'", cmd)
}
err := ioutil.WriteFile(
fmt.Sprintf("%s/%s", path, logfile),
res.CombineOutput().Bytes(),
LogPerm)
if err != nil {
log.WithError(err).Errorf("cannot create test results for command '%s'", cmd)
}
}(cmd, logfile)
}
wg.Wait()
}

// HelmAddCiliumRepo installs the repository that contain Cilium helm charts.
Expand Down

0 comments on commit 9ea244f

Please sign in to comment.