Merge pull request #124273 from panoswoo/fix/124255

Remove missing extended resources from init containers
This commit is contained in:
Kubernetes Prow Robot 2024-07-19 15:29:53 -07:00 committed by GitHub
commit ec8015daac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 11 deletions

View File

@ -215,21 +215,26 @@ func rejectPodAdmissionBasedOnOSField(pod *v1.Pod) bool {
}
func removeMissingExtendedResources(pod *v1.Pod, nodeInfo *schedulerframework.NodeInfo) *v1.Pod {
podCopy := pod.DeepCopy()
for i, c := range pod.Spec.Containers {
// We only handle requests in Requests but not Limits because the
// PodFitsResources predicate, to which the result pod will be passed,
// does not use Limits.
podCopy.Spec.Containers[i].Resources.Requests = make(v1.ResourceList)
for rName, rQuant := range c.Resources.Requests {
if v1helper.IsExtendedResourceName(rName) {
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
continue
filterExtendedResources := func(containers []v1.Container) {
for i, c := range containers {
// We only handle requests in Requests but not Limits because the
// PodFitsResources predicate, to which the result pod will be passed,
// does not use Limits.
filteredResources := make(v1.ResourceList)
for rName, rQuant := range c.Resources.Requests {
if v1helper.IsExtendedResourceName(rName) {
if _, found := nodeInfo.Allocatable.ScalarResources[rName]; !found {
continue
}
}
filteredResources[rName] = rQuant
}
podCopy.Spec.Containers[i].Resources.Requests[rName] = rQuant
containers[i].Resources.Requests = filteredResources
}
}
podCopy := pod.DeepCopy()
filterExtendedResources(podCopy.Spec.Containers)
filterExtendedResources(podCopy.Spec.InitContainers)
return podCopy
}

View File

@ -106,6 +106,14 @@ func makeTestPod(requests, limits v1.ResourceList) *v1.Pod {
},
},
},
InitContainers: []v1.Container{
{
Resources: v1.ResourceRequirements{
Requests: requests,
Limits: limits,
},
},
},
},
}
}