@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "io"
2222 "os"
23+ "strings"
2324 "time"
2425
2526 "github.com/pkg/errors"
@@ -183,16 +184,16 @@ func GetPodContainerTerminateMessage(pod *corev1api.Pod, container string) strin
183184
184185// GetPodTerminateMessage returns the terminate message for all containers of a pod
185186func GetPodTerminateMessage (pod * corev1api.Pod ) string {
186- message := ""
187+ var message strings. Builder
187188 for _ , containerStatus := range pod .Status .ContainerStatuses {
188189 if containerStatus .State .Terminated != nil {
189190 if containerStatus .State .Terminated .Message != "" {
190- message += containerStatus .State .Terminated .Message + "/"
191+ message . WriteString ( containerStatus .State .Terminated .Message + "/" )
191192 }
192193 }
193194 }
194195
195- return message
196+ return message . String ()
196197}
197198
198199func getPodLogReader (ctx context.Context , podGetter corev1client.CoreV1Interface , pod string , namespace string , logOptions * corev1api.PodLogOptions ) (io.ReadCloser , error ) {
@@ -272,21 +273,22 @@ func ToSystemAffinity(loadAffinity *LoadAffinity, volumeTopology *corev1api.Node
272273}
273274
274275func DiagnosePod (pod * corev1api.Pod , events * corev1api.EventList ) string {
275- diag := fmt .Sprintf ("Pod %s/%s, phase %s, node name %s, message %s\n " , pod .Namespace , pod .Name , pod .Status .Phase , pod .Spec .NodeName , pod .Status .Message )
276+ var diag strings.Builder
277+ _ , _ = fmt .Fprintf (& diag , "Pod %s/%s, phase %s, node name %s, message %s\n " , pod .Namespace , pod .Name , pod .Status .Phase , pod .Spec .NodeName , pod .Status .Message )
276278
277279 for _ , condition := range pod .Status .Conditions {
278- diag + = fmt .Sprintf ( "Pod condition %s, status %s, reason %s, message %s\n " , condition .Type , condition .Status , condition .Reason , condition .Message )
280+ _ , _ = fmt .Fprintf ( & diag , "Pod condition %s, status %s, reason %s, message %s\n " , condition .Type , condition .Status , condition .Reason , condition .Message )
279281 }
280282
281283 if events != nil {
282284 for _ , e := range events .Items {
283285 if e .InvolvedObject .UID == pod .UID && e .Type == corev1api .EventTypeWarning {
284- diag + = fmt .Sprintf ( "Pod event reason %s, message %s\n " , e .Reason , e .Message )
286+ _ , _ = fmt .Fprintf ( & diag , "Pod event reason %s, message %s\n " , e .Reason , e .Message )
285287 }
286288 }
287289 }
288290
289- return diag
291+ return diag . String ()
290292}
291293
292294var funcExit = os .Exit
0 commit comments