storage capacity: GA, always enabled, remove feature check

The code and tests for scenarios where the feature is disabled are no longer
needed because the feature is graduating to GA.
This commit is contained in:
Patrick Ohly
2022-03-01 20:28:13 +01:00
parent faa027ca2b
commit 3a7deaa141
22 changed files with 74 additions and 222 deletions

View File

@@ -357,9 +357,6 @@ type CSIDriverSpec struct {
//
// This field was immutable in Kubernetes <= 1.22 and now is mutable.
//
// This is a beta field and only available when the CSIStorageCapacity
// feature is enabled. The default is false.
//
// +optional
StorageCapacity *bool

View File

@@ -49,7 +49,7 @@ func SetDefaults_CSIDriver(obj *storagev1.CSIDriver) {
obj.Spec.PodInfoOnMount = new(bool)
*(obj.Spec.PodInfoOnMount) = false
}
if obj.Spec.StorageCapacity == nil && utilfeature.DefaultFeatureGate.Enabled(features.CSIStorageCapacity) {
if obj.Spec.StorageCapacity == nil {
obj.Spec.StorageCapacity = new(bool)
*(obj.Spec.StorageCapacity) = false
}

View File

@@ -52,7 +52,6 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
}
func TestSetDefaultStorageCapacityEnabled(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, true)()
driver := &storagev1.CSIDriver{}
// field should be defaulted
@@ -66,18 +65,6 @@ func TestSetDefaultStorageCapacityEnabled(t *testing.T) {
}
}
func TestSetDefaultStorageCapacityDisabled(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, false)()
driver := &storagev1.CSIDriver{}
// field should not be defaulted
output := roundTrip(t, runtime.Object(driver)).(*storagev1.CSIDriver)
outStorageCapacity := output.Spec.StorageCapacity
if outStorageCapacity != nil {
t.Errorf("Expected StorageCapacity to remain nil, got: %+v", outStorageCapacity)
}
}
func TestSetDefaultVolumeBindingMode(t *testing.T) {
class := &storagev1.StorageClass{}

View File

@@ -49,7 +49,7 @@ func SetDefaults_CSIDriver(obj *storagev1beta1.CSIDriver) {
obj.Spec.PodInfoOnMount = new(bool)
*(obj.Spec.PodInfoOnMount) = false
}
if obj.Spec.StorageCapacity == nil && utilfeature.DefaultFeatureGate.Enabled(features.CSIStorageCapacity) {
if obj.Spec.StorageCapacity == nil {
obj.Spec.StorageCapacity = new(bool)
*(obj.Spec.StorageCapacity) = false
}

View File

@@ -87,7 +87,6 @@ func TestSetDefaultAttachRequired(t *testing.T) {
}
func TestSetDefaultStorageCapacityEnabled(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, true)()
driver := &storagev1beta1.CSIDriver{}
// field should be defaulted
@@ -101,18 +100,6 @@ func TestSetDefaultStorageCapacityEnabled(t *testing.T) {
}
}
func TestSetDefaultStorageCapacityDisabled(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, false)()
driver := &storagev1beta1.CSIDriver{}
// field should not be defaulted
output := roundTrip(t, runtime.Object(driver)).(*storagev1beta1.CSIDriver)
outStorageCapacity := output.Spec.StorageCapacity
if outStorageCapacity != nil {
t.Errorf("Expected StorageCapacity to remain nil, got: %+v", outStorageCapacity)
}
}
func TestSetDefaultVolumeLifecycleModesEnabled(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIInlineVolume, true)()
driver := &storagev1beta1.CSIDriver{}

View File

@@ -469,7 +469,7 @@ func validatePodInfoOnMount(podInfoOnMount *bool, fldPath *field.Path) field.Err
// validateStorageCapacity tests if storageCapacity is set for CSIDriver.
func validateStorageCapacity(storageCapacity *bool, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{}
if storageCapacity == nil && utilfeature.DefaultFeatureGate.Enabled(features.CSIStorageCapacity) {
if storageCapacity == nil {
allErrs = append(allErrs, field.Required(fldPath, ""))
}

View File

@@ -2093,9 +2093,7 @@ func TestCSIDriverValidationUpdate(t *testing.T) {
}
func TestCSIDriverStorageCapacityEnablement(t *testing.T) {
run := func(t *testing.T, enabled, withField bool) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIStorageCapacity, enabled)()
run := func(t *testing.T, withField bool) {
driverName := "test-driver"
attachRequired := true
podInfoOnMount := true
@@ -2113,7 +2111,7 @@ func TestCSIDriverStorageCapacityEnablement(t *testing.T) {
csiDriver.Spec.StorageCapacity = &storageCapacity
}
errs := ValidateCSIDriver(&csiDriver)
success := !enabled || withField
success := withField
if success && len(errs) != 0 {
t.Errorf("expected success, got: %v", errs)
}
@@ -2123,13 +2121,9 @@ func TestCSIDriverStorageCapacityEnablement(t *testing.T) {
}
yesNo := []bool{true, false}
for _, enabled := range yesNo {
t.Run(fmt.Sprintf("CSIStorageCapacity=%v", enabled), func(t *testing.T) {
for _, withField := range yesNo {
t.Run(fmt.Sprintf("with-field=%v", withField), func(t *testing.T) {
run(t, enabled, withField)
})
}
for _, withField := range yesNo {
t.Run(fmt.Sprintf("with-field=%v", withField), func(t *testing.T) {
run(t, withField)
})
}
}