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
pull/6/head
Yassine TIJANI 2017-05-29 12:42:08 +02:00
parent a673d99731
commit cc5977aaa0
1 changed files with 3 additions and 6 deletions

View File

@ -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() {