diff --git a/pkg/controllers/provisioning/scheduling/existingnode.go b/pkg/controllers/provisioning/scheduling/existingnode.go index 98ce95cdcf..bdf05b3975 100644 --- a/pkg/controllers/provisioning/scheduling/existingnode.go +++ b/pkg/controllers/provisioning/scheduling/existingnode.go @@ -30,6 +30,7 @@ import ( type ExistingNode struct { *state.StateNode + cachedAvailable v1.ResourceList // Cache so we don't have to re-subtract resources on the StateNode every time Pods []*v1.Pod topology *Topology @@ -51,10 +52,11 @@ func NewExistingNode(n *state.StateNode, topology *Topology, daemonResources v1. } } node := &ExistingNode{ - StateNode: n, - topology: topology, - requests: remainingDaemonResources, - requirements: scheduling.NewLabelRequirements(n.Labels()), + StateNode: n, + cachedAvailable: n.Available(), + topology: topology, + requests: remainingDaemonResources, + requirements: scheduling.NewLabelRequirements(n.Labels()), } node.requirements.Add(scheduling.NewRequirement(v1.LabelHostname, v1.NodeSelectorOpIn, n.HostName())) topology.Register(v1.LabelHostname, n.HostName()) @@ -84,7 +86,7 @@ func (n *ExistingNode) Add(ctx context.Context, kubeClient client.Client, pod *v // node, which at this point can't be increased in size requests := resources.Merge(n.requests, resources.RequestsForPods(pod)) - if !resources.Fits(requests, n.Available()) { + if !resources.Fits(requests, n.cachedAvailable) { return fmt.Errorf("exceeds node resources") } diff --git a/pkg/utils/resources/resources.go b/pkg/utils/resources/resources.go index 9080194938..b3388a587c 100644 --- a/pkg/utils/resources/resources.go +++ b/pkg/utils/resources/resources.go @@ -183,19 +183,18 @@ func MaxResources(resources ...v1.ResourceList) v1.ResourceList { // MergeResourceLimitsIntoRequests merges resource limits into requests if no request exists for the given resource func MergeResourceLimitsIntoRequests(container v1.Container) v1.ResourceList { - resources := container.Resources.DeepCopy() - if resources.Requests == nil { - resources.Requests = v1.ResourceList{} - } - - if resources.Limits != nil { - for resourceName, quantity := range resources.Limits { - if _, ok := resources.Requests[resourceName]; !ok { - resources.Requests[resourceName] = quantity + ret := v1.ResourceList{} + for resourceName, quantity := range container.Resources.Requests { + ret[resourceName] = quantity + } + if container.Resources.Limits != nil { + for resourceName, quantity := range container.Resources.Limits { + if _, ok := container.Resources.Requests[resourceName]; !ok { + ret[resourceName] = quantity } } } - return resources.Requests + return ret } // Quantity parses the string value into a *Quantity