File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,9 @@ func GetVolumeMountPropagation(mount *corev1.VolumeMount) api.Volume_MountPropag
130
130
}
131
131
132
132
func GetVolumeHostPathType (vol * corev1.Volume ) api.Volume_HostPathType {
133
+ if vol .VolumeSource .HostPath .Type == nil {
134
+ return api .Volume_DIRECTORY
135
+ }
133
136
if * vol .VolumeSource .HostPath .Type == corev1 .HostPathFile {
134
137
return api .Volume_FILE
135
138
}
Original file line number Diff line number Diff line change @@ -199,3 +199,46 @@ func TestPopulateVolumes(t *testing.T) {
199
199
}
200
200
}
201
201
}
202
+
203
+ func TestGetVolumeHostPathType (t * testing.T ) {
204
+ vol1 := corev1.Volume {
205
+ VolumeSource : corev1.VolumeSource {
206
+ HostPath : & corev1.HostPathVolumeSource {
207
+ Path : "/tmp" ,
208
+ Type : nil ,
209
+ },
210
+ },
211
+ }
212
+ result1 := GetVolumeHostPathType (& vol1 )
213
+ if result1 != api .Volume_DIRECTORY {
214
+ t .Errorf ("Expected FILE type, got %v" , result1 )
215
+ }
216
+
217
+ typeFile := corev1 .HostPathFile
218
+ vol2 := corev1.Volume {
219
+ VolumeSource : corev1.VolumeSource {
220
+ HostPath : & corev1.HostPathVolumeSource {
221
+ Path : "/tmp" ,
222
+ Type : & typeFile ,
223
+ },
224
+ },
225
+ }
226
+ result2 := GetVolumeHostPathType (& vol2 )
227
+ if result2 != api .Volume_FILE {
228
+ t .Errorf ("Expected FILE type, got %v" , result2 )
229
+ }
230
+
231
+ typeDir := corev1 .HostPathDirectory
232
+ vol3 := corev1.Volume {
233
+ VolumeSource : corev1.VolumeSource {
234
+ HostPath : & corev1.HostPathVolumeSource {
235
+ Path : "/tmp" ,
236
+ Type : & typeDir ,
237
+ },
238
+ },
239
+ }
240
+ result3 := GetVolumeHostPathType (& vol3 )
241
+ if result3 != api .Volume_DIRECTORY {
242
+ t .Errorf ("Expected DIRECTORY type, got %v" , result3 )
243
+ }
244
+ }
You can’t perform that action at this time.
0 commit comments