Skip to content

Commit ec8015d

Browse files
authored
Merge pull request kubernetes#124273 from panoswoo/fix/124255
Remove missing extended resources from init containers
2 parents fa15f12 + fbb975b commit ec8015d

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

pkg/kubelet/lifecycle/predicate.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,26 @@ func rejectPodAdmissionBasedOnOSField(pod *v1.Pod) bool {
215215
}
216216

217217
func removeMissingExtendedResources(pod *v1.Pod, nodeInfo *schedulerframework.NodeInfo) *v1.Pod {
218-
podCopy := pod.DeepCopy()
219-
for i, c := range pod.Spec.Containers {
220-
// We only handle requests in Requests but not Limits because the
221-
// PodFitsResources predicate, to which the result pod will be passed,
222-
// does not use Limits.
223-
podCopy.Spec.Containers[i].Resources.Requests = make(v1.ResourceList)
224-
for rName, rQuant := range c.Resources.Requests {
225-
if v1helper.IsExtendedResourceName(rName) {
226-
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
227-
continue
218+
filterExtendedResources := func(containers []v1.Container) {
219+
for i, c := range containers {
220+
// We only handle requests in Requests but not Limits because the
221+
// PodFitsResources predicate, to which the result pod will be passed,
222+
// does not use Limits.
223+
filteredResources := make(v1.ResourceList)
224+
for rName, rQuant := range c.Resources.Requests {
225+
if v1helper.IsExtendedResourceName(rName) {
226+
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
227+
continue
228+
}
228229
}
230+
filteredResources[rName] = rQuant
229231
}
230-
podCopy.Spec.Containers[i].Resources.Requests[rName] = rQuant
232+
containers[i].Resources.Requests = filteredResources
231233
}
232234
}
235+
podCopy := pod.DeepCopy()
236+
filterExtendedResources(podCopy.Spec.Containers)
237+
filterExtendedResources(podCopy.Spec.InitContainers)
233238
return podCopy
234239
}
235240

pkg/kubelet/lifecycle/predicate_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ func makeTestPod(requests, limits v1.ResourceList) *v1.Pod {
106106
},
107107
},
108108
},
109+
InitContainers: []v1.Container{
110+
{
111+
Resources: v1.ResourceRequirements{
112+
Requests: requests,
113+
Limits: limits,
114+
},
115+
},
116+
},
109117
},
110118
}
111119
}

0 commit comments

Comments
 (0)