Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #96092: Honor disabled LocalStorageCapacityIsolation in scheduling #96181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/scheduler/framework/plugins/noderesources/BUILD
Expand Up @@ -67,6 +67,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/component-base/featuregate:go_default_library",
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
Expand Down
21 changes: 19 additions & 2 deletions pkg/scheduler/framework/plugins/noderesources/fit_test.go
Expand Up @@ -19,13 +19,17 @@ package noderesources
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"reflect"
"testing"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/featuregate"
featuregatetesting "k8s.io/component-base/featuregate/testing"
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/features"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
)
Expand Down Expand Up @@ -63,7 +67,7 @@ func makeAllocatableResources(milliCPU, memory, pods, extendedA, storage, hugePa
}

func newResourcePod(usage ...schedulernodeinfo.Resource) *v1.Pod {
containers := []v1.Container{}
var containers []v1.Container
for _, req := range usage {
containers = append(containers, v1.Container{
Resources: v1.ResourceRequirements{Requests: req.ResourceList()},
Expand Down Expand Up @@ -466,6 +470,7 @@ func TestStorageRequests(t *testing.T) {
pod *v1.Pod
nodeInfo *schedulernodeinfo.NodeInfo
name string
features map[featuregate.Feature]bool
wantStatus *framework.Status
}{
{
Expand All @@ -488,6 +493,15 @@ func TestStorageRequests(t *testing.T) {
name: "storage ephemeral local storage request exceeds allocatable",
wantStatus: framework.NewStatus(framework.Unschedulable, getErrReason(v1.ResourceEphemeralStorage)),
},
{
pod: newResourceInitPod(newResourcePod(schedulernodeinfo.Resource{EphemeralStorage: 25}), schedulernodeinfo.Resource{EphemeralStorage: 25}),
nodeInfo: schedulernodeinfo.NewNodeInfo(
newResourcePod(schedulernodeinfo.Resource{MilliCPU: 2, Memory: 2})),
name: "ephemeral local storage request is ignored due to disabled feature gate",
features: map[featuregate.Feature]bool{
features.LocalStorageCapacityIsolation: false,
},
},
{
pod: newResourcePod(schedulernodeinfo.Resource{EphemeralStorage: 10}),
nodeInfo: schedulernodeinfo.NewNodeInfo(
Expand All @@ -498,6 +512,9 @@ func TestStorageRequests(t *testing.T) {

for _, test := range storagePodsTests {
t.Run(test.name, func(t *testing.T) {
for k, v := range test.features {
defer featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)()
}
node := v1.Node{Status: v1.NodeStatus{Capacity: makeResources(10, 20, 32, 5, 20, 5).Capacity, Allocatable: makeAllocatableResources(10, 20, 32, 5, 20, 5)}}
test.nodeInfo.SetNode(&node)

Expand Down
6 changes: 4 additions & 2 deletions pkg/scheduler/nodeinfo/node_info.go
Expand Up @@ -252,8 +252,10 @@ func (r *Resource) SetMaxResource(rl v1.ResourceList) {
r.MilliCPU = cpu
}
case v1.ResourceEphemeralStorage:
if ephemeralStorage := rQuantity.Value(); ephemeralStorage > r.EphemeralStorage {
r.EphemeralStorage = ephemeralStorage
if utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) {
if ephemeralStorage := rQuantity.Value(); ephemeralStorage > r.EphemeralStorage {
r.EphemeralStorage = ephemeralStorage
}
}
default:
if v1helper.IsScalarResourceName(rName) {
Expand Down