Commit cc5977aa authored by Yassine TIJANI's avatar Yassine TIJANI

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
parent a673d997
...@@ -421,6 +421,8 @@ func (dc *DisruptionController) getPdbForPod(pod *v1.Pod) *policy.PodDisruptionB ...@@ -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) ( ...@@ -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() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment