Skip to content

Commit fc6361b

Browse files
emirotpriyansh17nolanemirotLyndon-Lireasonerjt
authored
perf: better string concatenation (#9705)
* perf: better string concatenation Signed-off-by: emirot <emirot.nolan@gmail.com> Signed-off-by: nolanemirot <nolan.emirot@broadcom.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * fix: backup deletion silently succeeds when tarball download fails (#9693) * Enhance backup deletion logic to handle tarball download failures and clean up associated CSI VolumeSnapshotContents Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * added changelog Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * Refactor error handling in backup deletion Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * Refactor backup deletion logic to skip CSI snapshot cleanup on tarball download failure Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * prevent backup deletion when errors occur Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * added logger Signed-off-by: Priyansh Choudhary <im1706@gmail.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * perf: better string concatenation Signed-off-by: emirot <emirot.nolan@gmail.com> * Add delay to avoid race conditions during VolumeSnapshotContent deletion (#9700) * Add delay to avoid race conditions during VolumeSnapshotContent deletion Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * updated changelog Signed-off-by: Priyansh Choudhary <im1706@gmail.com> * Updated Changelog Signed-off-by: Priyansh Choudhary <im1706@gmail.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * block data mover design Signed-off-by: Lyndon-Li <lyonghui@vmware.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * block data mover design Signed-off-by: Lyndon-Li <lyonghui@vmware.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * irregular volume size Signed-off-by: Lyndon-Li <lyonghui@vmware.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * block data mover design Signed-off-by: Lyndon-Li <lyonghui@vmware.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * Update the "community" page of website (#9722) Update the community page to add the correct links to community meeting and meeting notes. I also removed the referece of google group as I confirmed the last message was sent 2 years ago. Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com> Signed-off-by: emirot <emirot.nolan@gmail.com> * perf: better string concatenation Signed-off-by: emirot <emirot.nolan@gmail.com> --------- Signed-off-by: emirot <emirot.nolan@gmail.com> Signed-off-by: nolanemirot <nolan.emirot@broadcom.com> Signed-off-by: Priyansh Choudhary <im1706@gmail.com> Signed-off-by: Lyndon-Li <lyonghui@vmware.com> Signed-off-by: Daniel Jiang <daniel.jiang@broadcom.com> Co-authored-by: Priyansh Choudhary <im1706@gmail.com> Co-authored-by: nolanemirot <nolan.emirot@broadcom.com> Co-authored-by: Lyndon-Li <lyonghui@vmware.com> Co-authored-by: Daniel Jiang <daniel.jiang@broadcom.com>
1 parent 4d9bd91 commit fc6361b

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

changelogs/unreleased/9705-emirot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
perf: better string concatenation

pkg/util/csi/volume_snapshot.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,17 +708,18 @@ func DiagnoseVS(vs *snapshotv1api.VolumeSnapshot, events *corev1api.EventList) s
708708
}
709709
}
710710

711-
diag := fmt.Sprintf("VS %s/%s, bind to %s, readyToUse %v, errMessage %s\n", vs.Namespace, vs.Name, vscName, readyToUse, errMessage)
711+
var diag strings.Builder
712+
_, _ = fmt.Fprintf(&diag, "VS %s/%s, bind to %s, readyToUse %v, errMessage %s\n", vs.Namespace, vs.Name, vscName, readyToUse, errMessage)
712713

713714
if events != nil {
714715
for _, e := range events.Items {
715716
if e.InvolvedObject.UID == vs.UID && e.Type == corev1api.EventTypeWarning {
716-
diag += fmt.Sprintf("VS event reason %s, message %s\n", e.Reason, e.Message)
717+
_, _ = fmt.Fprintf(&diag, "VS event reason %s, message %s\n", e.Reason, e.Message)
717718
}
718719
}
719720
}
720721

721-
return diag
722+
return diag.String()
722723
}
723724

724725
func DiagnoseVSC(vsc *snapshotv1api.VolumeSnapshotContent) string {

pkg/util/kube/pod.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
185186
func 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

198199
func 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

274275
func 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

292294
var funcExit = os.Exit

pkg/util/kube/pvc_pv.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,18 @@ func GetPVCForPodVolume(vol *corev1api.Volume, pod *corev1api.Pod, crClient crcl
464464
}
465465

466466
func DiagnosePVC(pvc *corev1api.PersistentVolumeClaim, events *corev1api.EventList) string {
467-
diag := fmt.Sprintf("PVC %s/%s, phase %s, binding to %s\n", pvc.Namespace, pvc.Name, pvc.Status.Phase, pvc.Spec.VolumeName)
467+
var diag strings.Builder
468+
_, _ = fmt.Fprintf(&diag, "PVC %s/%s, phase %s, binding to %s\n", pvc.Namespace, pvc.Name, pvc.Status.Phase, pvc.Spec.VolumeName)
468469

469470
if events != nil {
470471
for _, e := range events.Items {
471472
if e.InvolvedObject.UID == pvc.UID && e.Type == corev1api.EventTypeWarning {
472-
diag += fmt.Sprintf("PVC event reason %s, message %s\n", e.Reason, e.Message)
473+
_, _ = fmt.Fprintf(&diag, "PVC event reason %s, message %s\n", e.Reason, e.Message)
473474
}
474475
}
475476
}
476477

477-
return diag
478+
return diag.String()
478479
}
479480

480481
func DiagnosePV(pv *corev1api.PersistentVolume) string {

0 commit comments

Comments
 (0)