Merge pull request #99632 from pohly/storage-capacity-enablement

volume binder: storage capacity enablement
This commit is contained in:
Kubernetes Prow Robot 2021-03-04 02:08:20 -08:00 committed by GitHub
commit 180d9cfa8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2215,14 +2215,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()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
// Setup // Setup: the driver has the feature enabled, but the scheduler might not.
withCSIStorageCapacity := true testEnv := newTestBinder(t, ctx.Done(), featureEnabled)
testEnv := newTestBinder(t, ctx.Done(), withCSIStorageCapacity) testEnv.addCSIDriver(makeCSIDriver(provisioner, optIn))
testEnv.addCSIDriver(makeCSIDriver(provisioner, withCSIStorageCapacity))
testEnv.addCSIStorageCapacities(scenario.capacities) testEnv.addCSIStorageCapacities(scenario.capacities)
// a. Init pvc cache // a. Init pvc cache
@ -2235,13 +2235,19 @@ func TestCapacity(t *testing.T) {
podVolumes, reasons, err := findPodVolumes(testEnv.binder, pod, testNode) podVolumes, reasons, err := findPodVolumes(testEnv.binder, pod, testNode)
// Validate // 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) t.Errorf("returned error: %v", err)
} }
if scenario.shouldFail && err == nil { if shouldFail && err == nil {
t.Error("returned success but expected error") t.Error("returned success but expected error")
} }
checkReasons(t, reasons, scenario.reasons) checkReasons(t, reasons, expectedReasons)
provisions := scenario.pvcs provisions := scenario.pvcs
if len(reasons) > 0 { if len(reasons) > 0 {
provisions = nil provisions = nil
@ -2249,7 +2255,18 @@ func TestCapacity(t *testing.T) {
testEnv.validatePodCache(t, pod.Spec.NodeName, pod, podVolumes, nil, provisions) testEnv.validatePodCache(t, pod.Spec.NodeName, pod, podVolumes, nil, provisions)
} }
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 { for name, scenario := range scenarios {
t.Run(name, func(t *testing.T) { run(t, scenario) }) t.Run(name, func(t *testing.T) { run(t, scenario, featureEnabled, optIn) })
}
})
}
})
} }
} }