@@ -73,64 +73,84 @@ func TestAdmit(t *testing.T) {
73
73
vacWithFinalizer .Finalizers = []string {volumeutil .VACProtectionFinalizer }
74
74
75
75
tests := []struct {
76
- name string
77
- resource schema.GroupVersionResource
78
- object runtime.Object
79
- expectedObject runtime.Object
80
- namespace string
76
+ name string
77
+ resource schema.GroupVersionResource
78
+ object runtime.Object
79
+ expectedObject runtime.Object
80
+ namespace string
81
+ enableVacFeatureGate bool
81
82
}{
82
83
{
83
84
"persistentvolumeclaims: create -> add finalizer" ,
84
85
api .SchemeGroupVersion .WithResource ("persistentvolumeclaims" ),
85
86
claim ,
86
87
claimWithFinalizer ,
87
88
claim .Namespace ,
89
+ false ,
88
90
},
89
91
{
90
92
"persistentvolumeclaims: finalizer already exists -> no new finalizer" ,
91
93
api .SchemeGroupVersion .WithResource ("persistentvolumeclaims" ),
92
94
claimWithFinalizer ,
93
95
claimWithFinalizer ,
94
96
claimWithFinalizer .Namespace ,
97
+ false ,
95
98
},
96
99
{
97
100
"persistentvolumes: create -> add finalizer" ,
98
101
api .SchemeGroupVersion .WithResource ("persistentvolumes" ),
99
102
pv ,
100
103
pvWithFinalizer ,
101
104
pv .Namespace ,
105
+ false ,
102
106
},
103
107
{
104
108
"persistentvolumes: finalizer already exists -> no new finalizer" ,
105
109
api .SchemeGroupVersion .WithResource ("persistentvolumes" ),
106
110
pvWithFinalizer ,
107
111
pvWithFinalizer ,
108
112
pvWithFinalizer .Namespace ,
113
+ false ,
109
114
},
110
115
{
111
- "volumeattributesclasses: create -> add finalizer" ,
116
+ "volumeattributesclasses VacFeatureGate disabled : create -> no finalizer added " ,
112
117
storageapi .SchemeGroupVersion .WithResource ("volumeattributesclasses" ),
113
118
vac ,
119
+ vac ,
120
+ vac .Namespace ,
121
+ false ,
122
+ },
123
+ {
124
+ "volumeattributesclasses VacFeatureGate disabled: finalizer already exists -> no new finalizer" ,
125
+ storageapi .SchemeGroupVersion .WithResource ("volumeattributesclasses" ),
126
+ vacWithFinalizer ,
114
127
vacWithFinalizer ,
115
128
vac .Namespace ,
129
+ false ,
116
130
},
117
131
{
118
- "volumeattributesclasses: finalizer already exists -> no new finalizer" ,
132
+ "volumeattributesclasses VacFeatureGate enabled: create -> add finalizer" ,
133
+ storageapi .SchemeGroupVersion .WithResource ("volumeattributesclasses" ),
134
+ vac ,
135
+ vacWithFinalizer ,
136
+ vac .Namespace ,
137
+ true ,
138
+ },
139
+ {
140
+ "volumeattributesclasses VacFeatureGate enabled: finalizer already exists -> no new finalizer" ,
119
141
storageapi .SchemeGroupVersion .WithResource ("volumeattributesclasses" ),
120
142
vacWithFinalizer ,
121
143
vacWithFinalizer ,
122
144
vac .Namespace ,
145
+ true ,
123
146
},
124
147
}
125
148
126
149
for _ , test := range tests {
127
150
t .Run (test .name , func (t * testing.T ) {
128
151
ctrl := newPlugin ()
129
152
130
- // Enable feature gate for tests with VolumeAttributesClass
131
- if test .object .GetObjectKind ().GroupVersionKind ().Kind == "VolumeAttributesClass" {
132
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .VolumeAttributesClass , true )
133
- }
153
+ featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .VolumeAttributesClass , test .enableVacFeatureGate )
134
154
135
155
obj := test .object .DeepCopyObject ()
136
156
attrs := admission .NewAttributesRecord (
0 commit comments