Merge pull request #46590 from yastij/disruption-getPodsForPdb

Automatic merge from submit-queue

avoiding unnecessary loop to copy pods listed

**What this PR does / why we need it**: avoids unnecessary loop to copy pods listed

**Which issue this PR fixes** : fixes #46433 

**Release note**:

```release-note
```
/assign @wojtek-t
This commit is contained in:
Kubernetes Submit Queue 2017-05-30 00:49:50 -07:00 committed by GitHub
commit 4e3bd25a55

View File

@ -421,6 +421,8 @@ func (dc *DisruptionController) getPdbForPod(pod *v1.Pod) *policy.PodDisruptionB
return pdbs[0] 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) { func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) ([]*v1.Pod, error) {
sel, err := metav1.LabelSelectorAsSelector(pdb.Spec.Selector) sel, err := metav1.LabelSelectorAsSelector(pdb.Spec.Selector)
if sel.Empty() { if sel.Empty() {
@ -433,12 +435,7 @@ func (dc *DisruptionController) getPodsForPdb(pdb *policy.PodDisruptionBudget) (
if err != nil { if err != nil {
return []*v1.Pod{}, err return []*v1.Pod{}, err
} }
// TODO: Do we need to copy here? return pods, nil
result := make([]*v1.Pod, 0, len(pods))
for i := range pods {
result = append(result, &(*pods[i]))
}
return result, nil
} }
func (dc *DisruptionController) worker() { func (dc *DisruptionController) worker() {