Skip to content

Commit f5f02f5

Browse files
authored
fix: [sc-107456] exec collector is running in all pods matched the selector (#1571)
only exec in 1 pod
1 parent e882f44 commit f5f02f5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pkg/collect/exec.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,20 @@ func execWithoutTimeout(clientConfig *rest.Config, bundlePath string, execCollec
8383
}
8484

8585
if len(pods) > 0 {
86-
for _, pod := range pods {
87-
stdout, stderr, execErrors := getExecOutputs(ctx, clientConfig, client, pod, execCollector)
88-
89-
path := filepath.Join(execCollector.Name, pod.Namespace, pod.Name)
90-
if len(stdout) > 0 {
91-
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stdout.txt"), bytes.NewBuffer(stdout))
92-
}
93-
if len(stderr) > 0 {
94-
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stderr.txt"), bytes.NewBuffer(stderr))
95-
}
96-
97-
if len(execErrors) > 0 {
98-
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-errors.json"), marshalErrors(execErrors))
99-
continue
100-
}
86+
// When the selector refers to more than one replica of a pod, the exec collector will execute in only one of the pods
87+
pod := pods[0]
88+
stdout, stderr, execErrors := getExecOutputs(ctx, clientConfig, client, pod, execCollector)
89+
90+
path := filepath.Join(execCollector.Name, pod.Namespace, pod.Name)
91+
if len(stdout) > 0 {
92+
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stdout.txt"), bytes.NewBuffer(stdout))
93+
}
94+
if len(stderr) > 0 {
95+
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-stderr.txt"), bytes.NewBuffer(stderr))
96+
}
97+
98+
if len(execErrors) > 0 {
99+
output.SaveResult(bundlePath, filepath.Join(path, execCollector.CollectorName+"-errors.json"), marshalErrors(execErrors))
101100
}
102101
}
103102

0 commit comments

Comments
 (0)