From e98c40a6f9ccf7d4cf143063858af489145bee40 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 2 Mar 2021 11:01:00 +0100 Subject: [PATCH] volume binder: test different CSIStorageCapacity/CSIDriver combinations When the feature is disabled either in the scheduler or the CSIDriver, the scheduler is expected to schedule pods without considering whether storage capacity is available. --- .../scheduling/scheduler_binder_test.go | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/pkg/controller/volume/scheduling/scheduler_binder_test.go b/pkg/controller/volume/scheduling/scheduler_binder_test.go index 8f89a3681a6..86773129059 100644 --- a/pkg/controller/volume/scheduling/scheduler_binder_test.go +++ b/pkg/controller/volume/scheduling/scheduler_binder_test.go @@ -2201,14 +2201,14 @@ func TestCapacity(t *testing.T) { }, } - run := func(t *testing.T, scenario scenarioType) { + run := func(t *testing.T, scenario scenarioType, featureEnabled, optIn bool) { + defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, featureEnabled)() ctx, cancel := context.WithCancel(context.Background()) defer cancel() - // Setup - withCSIStorageCapacity := true - testEnv := newTestBinder(t, ctx.Done(), withCSIStorageCapacity) - testEnv.addCSIDriver(makeCSIDriver(provisioner, withCSIStorageCapacity)) + // Setup: the driver has the feature enabled, but the scheduler might not. + testEnv := newTestBinder(t, ctx.Done(), featureEnabled) + testEnv.addCSIDriver(makeCSIDriver(provisioner, optIn)) testEnv.addCSIStorageCapacities(scenario.capacities) // a. Init pvc cache @@ -2221,13 +2221,19 @@ func TestCapacity(t *testing.T) { podVolumes, reasons, err := findPodVolumes(testEnv.binder, pod, testNode) // Validate - if !scenario.shouldFail && err != nil { + shouldFail := scenario.shouldFail + expectedReasons := scenario.reasons + if !featureEnabled || !optIn { + shouldFail = false + expectedReasons = nil + } + if !shouldFail && err != nil { t.Errorf("returned error: %v", err) } - if scenario.shouldFail && err == nil { + if shouldFail && err == nil { t.Error("returned success but expected error") } - checkReasons(t, reasons, scenario.reasons) + checkReasons(t, reasons, expectedReasons) provisions := scenario.pvcs if len(reasons) > 0 { provisions = nil @@ -2235,7 +2241,18 @@ func TestCapacity(t *testing.T) { testEnv.validatePodCache(t, pod.Spec.NodeName, pod, podVolumes, nil, provisions) } - for name, scenario := range scenarios { - t.Run(name, func(t *testing.T) { run(t, scenario) }) + yesNo := []bool{true, false} + for _, featureEnabled := range yesNo { + name := fmt.Sprintf("CSIStorageCapacity=%v", featureEnabled) + t.Run(name, func(t *testing.T) { + for _, optIn := range yesNo { + name := fmt.Sprintf("CSIDriver.StorageCapacity=%v", optIn) + t.Run(name, func(t *testing.T) { + for name, scenario := range scenarios { + t.Run(name, func(t *testing.T) { run(t, scenario, featureEnabled, optIn) }) + } + }) + } + }) } }