Skip to content

Commit 6cb301a

Browse files
committed
Don't consider allocated resources for limitranger constraints
1 parent 99dcf07 commit 6cb301a

File tree

1 file changed

+4
-33
lines changed

1 file changed

+4
-33
lines changed

plugin/pkg/admission/limitranger/admission.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ import (
3434
utilerrors "k8s.io/apimachinery/pkg/util/errors"
3535
"k8s.io/apiserver/pkg/admission"
3636
genericadmissioninitailizer "k8s.io/apiserver/pkg/admission/initializer"
37-
"k8s.io/apiserver/pkg/util/feature"
3837
"k8s.io/client-go/informers"
3938
"k8s.io/client-go/kubernetes"
4039
corev1listers "k8s.io/client-go/listers/core/v1"
4140
"k8s.io/utils/lru"
4241

4342
api "k8s.io/kubernetes/pkg/apis/core"
44-
"k8s.io/kubernetes/pkg/features"
4543
)
4644

4745
const (
@@ -523,11 +521,8 @@ func PodValidateLimitFunc(limitRange *corev1.LimitRange, pod *api.Pod) error {
523521

524522
// enforce pod limits on init containers
525523
if limitType == corev1.LimitTypePod {
526-
opts := podResourcesOptions{
527-
InPlacePodVerticalScalingEnabled: feature.DefaultFeatureGate.Enabled(features.InPlacePodVerticalScaling),
528-
}
529-
podRequests := podRequests(pod, opts)
530-
podLimits := podLimits(pod, opts)
524+
podRequests := podRequests(pod)
525+
podLimits := podLimits(pod)
531526
for k, v := range limit.Min {
532527
if err := minConstraint(string(limitType), string(k), v, podRequests, podLimits); err != nil {
533528
errs = append(errs, err)
@@ -548,39 +543,15 @@ func PodValidateLimitFunc(limitRange *corev1.LimitRange, pod *api.Pod) error {
548543
return utilerrors.NewAggregate(errs)
549544
}
550545

551-
type podResourcesOptions struct {
552-
// InPlacePodVerticalScalingEnabled indicates that the in-place pod vertical scaling feature gate is enabled.
553-
InPlacePodVerticalScalingEnabled bool
554-
}
555-
556546
// podRequests is a simplified version of pkg/api/v1/resource/PodRequests that operates against the core version of
557547
// pod. Any changes to that calculation should be reflected here.
558548
// TODO: Maybe we can consider doing a partial conversion of the pod to a v1
559549
// type and then using the pkg/api/v1/resource/PodRequests.
560-
func podRequests(pod *api.Pod, opts podResourcesOptions) api.ResourceList {
550+
func podRequests(pod *api.Pod) api.ResourceList {
561551
reqs := api.ResourceList{}
562552

563-
var containerStatuses map[string]*api.ContainerStatus
564-
if opts.InPlacePodVerticalScalingEnabled {
565-
containerStatuses = map[string]*api.ContainerStatus{}
566-
for i := range pod.Status.ContainerStatuses {
567-
containerStatuses[pod.Status.ContainerStatuses[i].Name] = &pod.Status.ContainerStatuses[i]
568-
}
569-
}
570-
571553
for _, container := range pod.Spec.Containers {
572554
containerReqs := container.Resources.Requests
573-
if opts.InPlacePodVerticalScalingEnabled {
574-
cs, found := containerStatuses[container.Name]
575-
if found {
576-
if pod.Status.Resize == api.PodResizeStatusInfeasible {
577-
containerReqs = cs.AllocatedResources
578-
} else {
579-
containerReqs = max(container.Resources.Requests, cs.AllocatedResources)
580-
}
581-
}
582-
}
583-
584555
addResourceList(reqs, containerReqs)
585556
}
586557

@@ -616,7 +587,7 @@ func podRequests(pod *api.Pod, opts podResourcesOptions) api.ResourceList {
616587
// pod. Any changes to that calculation should be reflected here.
617588
// TODO: Maybe we can consider doing a partial conversion of the pod to a v1
618589
// type and then using the pkg/api/v1/resource/PodLimits.
619-
func podLimits(pod *api.Pod, opts podResourcesOptions) api.ResourceList {
590+
func podLimits(pod *api.Pod) api.ResourceList {
620591
limits := api.ResourceList{}
621592

622593
for _, container := range pod.Spec.Containers {

0 commit comments

Comments
 (0)