Use go 1.25 waitgroup Go method instead of Add/Wait (#3265)
* Use go 1.25 waitgroup Go method instead of Add/Wait Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Disable java builder test for now Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> --------- Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
@@ -128,11 +128,11 @@ func (opts *DumpSubCommand) do(input cli.Input) error {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(res resources.Resource, dir string) {
|
||||
defer wg.Done()
|
||||
res.Dump(input.Context(), dir)
|
||||
}(res, dir)
|
||||
wg.Go(func() {
|
||||
func(res resources.Resource, dir string) {
|
||||
res.Dump(input.Context(), dir)
|
||||
}(res, dir)
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
@@ -207,49 +207,48 @@ func (res KubernetesPodLogDumper) Dump(ctx context.Context, dumpDir string) {
|
||||
wg := &sync.WaitGroup{}
|
||||
|
||||
for _, p := range l.Items {
|
||||
wg.Add(1)
|
||||
wg.Go(func() {
|
||||
func(pod corev1.Pod) {
|
||||
// dump logs from each containers
|
||||
for _, container := range append(pod.Spec.Containers, pod.Spec.InitContainers...) {
|
||||
req := res.client.CoreV1().Pods(pod.Namespace).
|
||||
GetLogs(pod.Name, &corev1.PodLogOptions{Container: container.Name})
|
||||
|
||||
go func(pod corev1.Pod) {
|
||||
defer wg.Done()
|
||||
|
||||
// dump logs from each containers
|
||||
for _, container := range append(pod.Spec.Containers, pod.Spec.InitContainers...) {
|
||||
req := res.client.CoreV1().Pods(pod.Namespace).
|
||||
GetLogs(pod.Name, &corev1.PodLogOptions{Container: container.Name})
|
||||
|
||||
stream, err := req.Stream(ctx)
|
||||
if err != nil {
|
||||
console.Error(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
||||
return
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(stream)
|
||||
var buffer bytes.Buffer
|
||||
|
||||
for {
|
||||
line, _, err := reader.ReadLine()
|
||||
stream, err := req.Stream(ctx)
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
stream.Close()
|
||||
break
|
||||
console.Error(fmt.Sprintf("Error streaming logs for pod %v: %v", pod.Name, err))
|
||||
return
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(stream)
|
||||
var buffer bytes.Buffer
|
||||
|
||||
for {
|
||||
line, _, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
stream.Close()
|
||||
break
|
||||
}
|
||||
console.Error(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
_, err = buffer.WriteString(string(line) + "\n")
|
||||
if err != nil {
|
||||
console.Error(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
||||
return
|
||||
}
|
||||
console.Error(fmt.Sprintf("Error reading logs from buffer: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
_, err = buffer.WriteString(string(line) + "\n")
|
||||
if err != nil {
|
||||
console.Error(fmt.Sprintf("Error writing bytes to buffer: %v", err))
|
||||
return
|
||||
}
|
||||
f := getPodFileName(dumpDir, pod.ObjectMeta, container.Name)
|
||||
writeToFile(f, buffer.String())
|
||||
|
||||
stream.Close()
|
||||
}
|
||||
}(p)
|
||||
})
|
||||
|
||||
f := getPodFileName(dumpDir, pod.ObjectMeta, container.Name)
|
||||
writeToFile(f, buffer.String())
|
||||
|
||||
stream.Close()
|
||||
}
|
||||
}(p)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
Reference in New Issue
Block a user