Skip to content

Commit 9d0cbb7

Browse files
authored
Merge pull request kubernetes#88673 from jsafrane/block-feature-ga
Promote block volumes to GA
2 parents b969613 + 3af6710 commit 9d0cbb7

File tree

46 files changed

+125
-878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+125
-878
lines changed

api/openapi-spec/swagger.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/api/persistentvolume/util.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import (
2525
// DropDisabledFields removes disabled fields from the pv spec.
2626
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
2727
func DropDisabledFields(pvSpec *api.PersistentVolumeSpec, oldPVSpec *api.PersistentVolumeSpec) {
28-
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && !volumeModeInUse(oldPVSpec) {
29-
pvSpec.VolumeMode = nil
30-
}
31-
3228
if !utilfeature.DefaultFeatureGate.Enabled(features.ExpandCSIVolumes) && !hasExpansionSecrets(oldPVSpec) {
3329
if pvSpec.CSI != nil {
3430
pvSpec.CSI.ControllerExpandSecretRef = nil
@@ -46,13 +42,3 @@ func hasExpansionSecrets(oldPVSpec *api.PersistentVolumeSpec) bool {
4642
}
4743
return false
4844
}
49-
50-
func volumeModeInUse(oldPVSpec *api.PersistentVolumeSpec) bool {
51-
if oldPVSpec == nil {
52-
return false
53-
}
54-
if oldPVSpec.VolumeMode != nil {
55-
return true
56-
}
57-
return false
58-
}

pkg/api/persistentvolume/util_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,68 +28,18 @@ import (
2828
)
2929

3030
func TestDropDisabledFields(t *testing.T) {
31-
specWithMode := func(mode *api.PersistentVolumeMode) *api.PersistentVolumeSpec {
32-
return &api.PersistentVolumeSpec{VolumeMode: mode}
33-
}
34-
3531
secretRef := &api.SecretReference{
3632
Name: "expansion-secret",
3733
Namespace: "default",
3834
}
3935

40-
modeBlock := api.PersistentVolumeBlock
41-
4236
tests := map[string]struct {
4337
oldSpec *api.PersistentVolumeSpec
4438
newSpec *api.PersistentVolumeSpec
4539
expectOldSpec *api.PersistentVolumeSpec
4640
expectNewSpec *api.PersistentVolumeSpec
47-
blockEnabled bool
4841
csiExpansionEnabled bool
4942
}{
50-
"disabled block clears new": {
51-
blockEnabled: false,
52-
newSpec: specWithMode(&modeBlock),
53-
expectNewSpec: specWithMode(nil),
54-
oldSpec: nil,
55-
expectOldSpec: nil,
56-
},
57-
"disabled block clears update when old pv did not use block": {
58-
blockEnabled: false,
59-
newSpec: specWithMode(&modeBlock),
60-
expectNewSpec: specWithMode(nil),
61-
oldSpec: specWithMode(nil),
62-
expectOldSpec: specWithMode(nil),
63-
},
64-
"disabled block does not clear new on update when old pv did use block": {
65-
blockEnabled: false,
66-
newSpec: specWithMode(&modeBlock),
67-
expectNewSpec: specWithMode(&modeBlock),
68-
oldSpec: specWithMode(&modeBlock),
69-
expectOldSpec: specWithMode(&modeBlock),
70-
},
71-
72-
"enabled block preserves new": {
73-
blockEnabled: true,
74-
newSpec: specWithMode(&modeBlock),
75-
expectNewSpec: specWithMode(&modeBlock),
76-
oldSpec: nil,
77-
expectOldSpec: nil,
78-
},
79-
"enabled block preserves update when old pv did not use block": {
80-
blockEnabled: true,
81-
newSpec: specWithMode(&modeBlock),
82-
expectNewSpec: specWithMode(&modeBlock),
83-
oldSpec: specWithMode(nil),
84-
expectOldSpec: specWithMode(nil),
85-
},
86-
"enabled block preserves update when old pv did use block": {
87-
blockEnabled: true,
88-
newSpec: specWithMode(&modeBlock),
89-
expectNewSpec: specWithMode(&modeBlock),
90-
oldSpec: specWithMode(&modeBlock),
91-
expectOldSpec: specWithMode(&modeBlock),
92-
},
9343
"disabled csi expansion clears secrets": {
9444
csiExpansionEnabled: false,
9545
newSpec: specWithCSISecrets(secretRef),
@@ -129,7 +79,6 @@ func TestDropDisabledFields(t *testing.T) {
12979

13080
for name, tc := range tests {
13181
t.Run(name, func(t *testing.T) {
132-
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, tc.blockEnabled)()
13382
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ExpandCSIVolumes, tc.csiExpansionEnabled)()
13483

13584
DropDisabledFields(tc.newSpec, tc.oldSpec)

pkg/api/persistentvolumeclaim/util.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,11 @@ const (
3030
// DropDisabledFields removes disabled fields from the pvc spec.
3131
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pvc spec.
3232
func DropDisabledFields(pvcSpec, oldPVCSpec *core.PersistentVolumeClaimSpec) {
33-
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && !volumeModeInUse(oldPVCSpec) {
34-
pvcSpec.VolumeMode = nil
35-
}
3633
if !dataSourceIsEnabled(pvcSpec) && !dataSourceInUse(oldPVCSpec) {
3734
pvcSpec.DataSource = nil
3835
}
3936
}
4037

41-
func volumeModeInUse(oldPVCSpec *core.PersistentVolumeClaimSpec) bool {
42-
if oldPVCSpec == nil {
43-
return false
44-
}
45-
if oldPVCSpec.VolumeMode != nil {
46-
return true
47-
}
48-
return false
49-
}
50-
5138
func dataSourceInUse(oldPVCSpec *core.PersistentVolumeClaimSpec) bool {
5239
if oldPVCSpec == nil {
5340
return false

pkg/api/persistentvolumeclaim/util_test.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -28,96 +28,6 @@ import (
2828
"k8s.io/kubernetes/pkg/features"
2929
)
3030

31-
func TestDropAlphaPVCVolumeMode(t *testing.T) {
32-
vmode := core.PersistentVolumeFilesystem
33-
34-
pvcWithoutVolumeMode := func() *core.PersistentVolumeClaim {
35-
return &core.PersistentVolumeClaim{
36-
Spec: core.PersistentVolumeClaimSpec{
37-
VolumeMode: nil,
38-
},
39-
}
40-
}
41-
pvcWithVolumeMode := func() *core.PersistentVolumeClaim {
42-
return &core.PersistentVolumeClaim{
43-
Spec: core.PersistentVolumeClaimSpec{
44-
VolumeMode: &vmode,
45-
},
46-
}
47-
}
48-
49-
pvcInfo := []struct {
50-
description string
51-
hasVolumeMode bool
52-
pvc func() *core.PersistentVolumeClaim
53-
}{
54-
{
55-
description: "pvc without VolumeMode",
56-
hasVolumeMode: false,
57-
pvc: pvcWithoutVolumeMode,
58-
},
59-
{
60-
description: "pvc with Filesystem VolumeMode",
61-
hasVolumeMode: true,
62-
pvc: pvcWithVolumeMode,
63-
},
64-
{
65-
description: "is nil",
66-
hasVolumeMode: false,
67-
pvc: func() *core.PersistentVolumeClaim { return nil },
68-
},
69-
}
70-
71-
for _, enabled := range []bool{true, false} {
72-
for _, oldpvcInfo := range pvcInfo {
73-
for _, newpvcInfo := range pvcInfo {
74-
oldpvcHasVolumeMode, oldpvc := oldpvcInfo.hasVolumeMode, oldpvcInfo.pvc()
75-
newpvcHasVolumeMode, newpvc := newpvcInfo.hasVolumeMode, newpvcInfo.pvc()
76-
if newpvc == nil {
77-
continue
78-
}
79-
80-
t.Run(fmt.Sprintf("feature enabled=%v, old pvc %v, new pvc %v", enabled, oldpvcInfo.description, newpvcInfo.description), func(t *testing.T) {
81-
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, enabled)()
82-
83-
var oldpvcSpec *core.PersistentVolumeClaimSpec
84-
if oldpvc != nil {
85-
oldpvcSpec = &oldpvc.Spec
86-
}
87-
DropDisabledFields(&newpvc.Spec, oldpvcSpec)
88-
89-
// old pvc should never be changed
90-
if !reflect.DeepEqual(oldpvc, oldpvcInfo.pvc()) {
91-
t.Errorf("old pvc changed: %v", diff.ObjectReflectDiff(oldpvc, oldpvcInfo.pvc()))
92-
}
93-
94-
switch {
95-
case enabled || oldpvcHasVolumeMode:
96-
// new pvc should not be changed if the feature is enabled, or if the old pvc had BlockVolume
97-
if !reflect.DeepEqual(newpvc, newpvcInfo.pvc()) {
98-
t.Errorf("new pvc changed: %v", diff.ObjectReflectDiff(newpvc, newpvcInfo.pvc()))
99-
}
100-
case newpvcHasVolumeMode:
101-
// new pvc should be changed
102-
if reflect.DeepEqual(newpvc, newpvcInfo.pvc()) {
103-
t.Errorf("new pvc was not changed")
104-
}
105-
// new pvc should not have BlockVolume
106-
if !reflect.DeepEqual(newpvc, pvcWithoutVolumeMode()) {
107-
t.Errorf("new pvc had pvcBlockVolume: %v", diff.ObjectReflectDiff(newpvc, pvcWithoutVolumeMode()))
108-
}
109-
default:
110-
// new pvc should not need to be changed
111-
if !reflect.DeepEqual(newpvc, newpvcInfo.pvc()) {
112-
t.Errorf("new pvc changed: %v", diff.ObjectReflectDiff(newpvc, newpvcInfo.pvc()))
113-
}
114-
}
115-
})
116-
}
117-
}
118-
}
119-
}
120-
12131
func TestDropDisabledSnapshotDataSource(t *testing.T) {
12232
pvcWithoutDataSource := func() *core.PersistentVolumeClaim {
12333
return &core.PersistentVolumeClaim{

pkg/api/pod/util.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,6 @@ func dropDisabledFields(
385385
})
386386
}
387387

388-
dropDisabledVolumeDevicesFields(podSpec, oldPodSpec)
389-
390388
dropDisabledRunAsGroupField(podSpec, oldPodSpec)
391389

392390
dropDisabledGMSAFields(podSpec, oldPodSpec)
@@ -484,17 +482,6 @@ func dropDisabledProcMountField(podSpec, oldPodSpec *api.PodSpec) {
484482
}
485483
}
486484

487-
// dropDisabledVolumeDevicesFields removes disabled fields from []VolumeDevice if it has not been already populated.
488-
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a VolumeDevice
489-
func dropDisabledVolumeDevicesFields(podSpec, oldPodSpec *api.PodSpec) {
490-
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) && !volumeDevicesInUse(oldPodSpec) {
491-
VisitContainers(podSpec, func(c *api.Container) bool {
492-
c.VolumeDevices = nil
493-
return true
494-
})
495-
}
496-
}
497-
498485
// dropDisabledCSIVolumeSourceAlphaFields removes disabled alpha fields from []CSIVolumeSource.
499486
// This should be called from PrepareForCreate/PrepareForUpdate for all pod specs resources containing a CSIVolumeSource
500487
func dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec *api.PodSpec) {
@@ -646,24 +633,6 @@ func emptyDirSizeLimitInUse(podSpec *api.PodSpec) bool {
646633
return false
647634
}
648635

649-
// volumeDevicesInUse returns true if the pod spec is non-nil and has VolumeDevices set.
650-
func volumeDevicesInUse(podSpec *api.PodSpec) bool {
651-
if podSpec == nil {
652-
return false
653-
}
654-
655-
var inUse bool
656-
VisitContainers(podSpec, func(c *api.Container) bool {
657-
if c.VolumeDevices != nil {
658-
inUse = true
659-
return false
660-
}
661-
return true
662-
})
663-
664-
return inUse
665-
}
666-
667636
// runAsGroupInUse returns true if the pod spec is non-nil and has a SecurityContext's RunAsGroup field set
668637
func runAsGroupInUse(podSpec *api.PodSpec) bool {
669638
if podSpec == nil {

0 commit comments

Comments
 (0)