From cc5977aaa00811cbeb796408cdfa742757e38219 Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Mon, 29 May 2017 12:42:08 +0200 Subject: [PATCH] avoiding unnecessary loop to copy pods listed see #46433 adding comments stating that returned pods should be used as read-only objects fixing typo avoiding unnecessary loop to copy pods listed see #46433 fixing fmt avoiding unnecessary loop to copy pods listed see #46433 --- pkg/controller/disruption/disruption.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/controller/disruption/disruption.go b/pkg/controller/disruption/disruption.go index eed47823626..d5a3038cd71 100644 --- a/pkg/controller/disruption/disruption.go +++ b/pkg/controller/disruption/disruption.go @@ -421,6 +421,8 @@ func (dc *DisruptionController) getPdbForPod(pod *v1.Pod) *policy.PodDisruptionB return pdbs[0] } +// This function returns pods using the PodDisruptionBudget object. +// IMPORTANT NOTE : the returned pods should NOT be modified. func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) ([]*v1.Pod, error) { sel, err := metav1.LabelSelectorAsSelector(pdb.Spec.Selector) if sel.Empty() { @@ -433,12 +435,7 @@ func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) ( if err != nil { return []*v1.Pod{}, err } - // TODO: Do we need to copy here? - result := make([]*v1.Pod, 0, len(pods)) - for i := range pods { - result = append(result, &(*pods[i])) - } - return result, nil + return pods, nil } func (dc *DisruptionController) worker() {