@@ -28,96 +28,6 @@ import (
28
28
"k8s.io/kubernetes/pkg/features"
29
29
)
30
30
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
-
121
31
func TestDropDisabledSnapshotDataSource (t * testing.T ) {
122
32
pvcWithoutDataSource := func () * core.PersistentVolumeClaim {
123
33
return & core.PersistentVolumeClaim {
0 commit comments