mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-27 05:04:52 +00:00
Promote block volume features to GA
This commit is contained in:
@@ -25,10 +25,6 @@ import (
|
||||
// DropDisabledFields removes disabled fields from the pv spec.
|
||||
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
|
||||
func DropDisabledFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && !volumeModeInUse(oldPVSpec) {
|
||||
pvSpec.VolumeMode = nil
|
||||
}
|
||||
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.ExpandCSIVolumes) && !hasExpansionSecrets(oldPVSpec) {
|
||||
if pvSpec.CSI != nil {
|
||||
pvSpec.CSI.ControllerExpandSecretRef = nil
|
||||
@@ -46,13 +42,3 @@ func hasExpansionSecrets(oldPVSpec *api.PersistentVolumeSpec) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func volumeModeInUse(oldPVSpec *api.PersistentVolumeSpec) bool {
|
||||
if oldPVSpec == nil {
|
||||
return false
|
||||
}
|
||||
if oldPVSpec.VolumeMode != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@@ -28,68 +28,18 @@ import (
|
||||
)
|
||||
|
||||
func TestDropDisabledFields(t *testing.T) {
|
||||
specWithMode := func(mode *api.PersistentVolumeMode) *api.PersistentVolumeSpec {
|
||||
return &api.PersistentVolumeSpec{VolumeMode: mode}
|
||||
}
|
||||
|
||||
secretRef := &api.SecretReference{
|
||||
Name: "expansion-secret",
|
||||
Namespace: "default",
|
||||
}
|
||||
|
||||
modeBlock := api.PersistentVolumeBlock
|
||||
|
||||
tests := map[string]struct {
|
||||
oldSpec *api.PersistentVolumeSpec
|
||||
newSpec *api.PersistentVolumeSpec
|
||||
expectOldSpec *api.PersistentVolumeSpec
|
||||
expectNewSpec *api.PersistentVolumeSpec
|
||||
blockEnabled bool
|
||||
csiExpansionEnabled bool
|
||||
}{
|
||||
"disabled block clears new": {
|
||||
blockEnabled: false,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(nil),
|
||||
oldSpec: nil,
|
||||
expectOldSpec: nil,
|
||||
},
|
||||
"disabled block clears update when old pv did not use block": {
|
||||
blockEnabled: false,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(nil),
|
||||
oldSpec: specWithMode(nil),
|
||||
expectOldSpec: specWithMode(nil),
|
||||
},
|
||||
"disabled block does not clear new on update when old pv did use block": {
|
||||
blockEnabled: false,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(&modeBlock),
|
||||
oldSpec: specWithMode(&modeBlock),
|
||||
expectOldSpec: specWithMode(&modeBlock),
|
||||
},
|
||||
|
||||
"enabled block preserves new": {
|
||||
blockEnabled: true,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(&modeBlock),
|
||||
oldSpec: nil,
|
||||
expectOldSpec: nil,
|
||||
},
|
||||
"enabled block preserves update when old pv did not use block": {
|
||||
blockEnabled: true,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(&modeBlock),
|
||||
oldSpec: specWithMode(nil),
|
||||
expectOldSpec: specWithMode(nil),
|
||||
},
|
||||
"enabled block preserves update when old pv did use block": {
|
||||
blockEnabled: true,
|
||||
newSpec: specWithMode(&modeBlock),
|
||||
expectNewSpec: specWithMode(&modeBlock),
|
||||
oldSpec: specWithMode(&modeBlock),
|
||||
expectOldSpec: specWithMode(&modeBlock),
|
||||
},
|
||||
"disabled csi expansion clears secrets": {
|
||||
csiExpansionEnabled: false,
|
||||
newSpec: specWithCSISecrets(secretRef),
|
||||
@@ -129,7 +79,6 @@ func TestDropDisabledFields(t *testing.T) {
|
||||
|
||||
for name, tc := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, tc.blockEnabled)()
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandCSIVolumes, tc.csiExpansionEnabled)()
|
||||
|
||||
DropDisabledFields(tc.newSpec, tc.oldSpec)
|
||||
|
Reference in New Issue
Block a user