@@ -83,6 +83,37 @@ func getBlockPlugin(t *testing.T) (string, volume.BlockVolumePlugin) {
83
83
return tmpDir , plug
84
84
}
85
85
86
+ func getNodeExpandablePlugin (t * testing.T , isBlockDevice bool ) (string , volume.NodeExpandableVolumePlugin ) {
87
+ tmpDir , err := utiltesting .MkTmpdir ("localVolumeTest" )
88
+ if err != nil {
89
+ t .Fatalf ("can't make a temp dir: %v" , err )
90
+ }
91
+
92
+ plugMgr := volume.VolumePluginMgr {}
93
+ var pathToFSType map [string ]hostutil.FileType
94
+ if isBlockDevice {
95
+ pathToFSType = map [string ]hostutil.FileType {
96
+ tmpDir : hostutil .FileTypeBlockDev ,
97
+ }
98
+ } else {
99
+ pathToFSType = map [string ]hostutil.FileType {
100
+ tmpDir : hostutil .FileTypeDirectory ,
101
+ }
102
+ }
103
+
104
+ plugMgr .InitPlugins (ProbeVolumePlugins (), nil /* prober */ , volumetest .NewFakeKubeletVolumeHostWithMounterFSType (t , tmpDir , nil , nil , pathToFSType ))
105
+
106
+ plug , err := plugMgr .FindNodeExpandablePluginByName (localVolumePluginName )
107
+ if err != nil {
108
+ os .RemoveAll (tmpDir )
109
+ t .Fatalf ("Can't find the plugin by name" )
110
+ }
111
+ if plug .GetPluginName () != localVolumePluginName {
112
+ t .Errorf ("Wrong name: %s" , plug .GetPluginName ())
113
+ }
114
+ return tmpDir , plug
115
+ }
116
+
86
117
func getPersistentPlugin (t * testing.T ) (string , volume.PersistentVolumePlugin ) {
87
118
tmpDir , err := utiltesting .MkTmpdir ("localVolumeTest" )
88
119
if err != nil {
@@ -148,6 +179,9 @@ func getTestVolume(readOnly bool, path string, isBlock bool, mountOptions []stri
148
179
if isBlock {
149
180
blockMode := v1 .PersistentVolumeBlock
150
181
pv .Spec .VolumeMode = & blockMode
182
+ } else {
183
+ fsMode := v1 .PersistentVolumeFilesystem
184
+ pv .Spec .VolumeMode = & fsMode
151
185
}
152
186
return volume .NewSpecFromPersistentVolume (pv , readOnly )
153
187
}
@@ -289,6 +323,28 @@ func TestFSGlobalPathAndMountDevice(t *testing.T) {
289
323
}
290
324
}
291
325
326
+ func TestNodeExpand (t * testing.T ) {
327
+ // FS global path testing
328
+ tmpFSDir , plug := getNodeExpandablePlugin (t , false )
329
+ defer os .RemoveAll (tmpFSDir )
330
+
331
+ pvSpec := getTestVolume (false , tmpFSDir , false , nil )
332
+
333
+ resizeOptions := volume.NodeResizeOptions {
334
+ VolumeSpec : pvSpec ,
335
+ DevicePath : tmpFSDir ,
336
+ }
337
+
338
+ // Actually, we will do no volume expansion if volume is of type dir
339
+ resizeDone , err := plug .NodeExpand (resizeOptions )
340
+ if err != nil {
341
+ t .Fatal (err )
342
+ }
343
+ if ! resizeDone {
344
+ t .Errorf ("expected resize to be done" )
345
+ }
346
+ }
347
+
292
348
func TestMountUnmount (t * testing.T ) {
293
349
tmpDir , plug := getPlugin (t )
294
350
defer os .RemoveAll (tmpDir )
0 commit comments