@@ -167,9 +167,53 @@ func discoverExistingSnapshots() {
167
167
}
168
168
}
169
169
170
+ func discoveryExistingVolumes () error {
171
+ cmdPath := locateCommandPath ("findmnt" )
172
+ out , err := exec .Command (cmdPath , "--json" ).CombinedOutput ()
173
+ if err != nil {
174
+ glog .V (3 ).Infof ("failed to execute command: %+v" , cmdPath )
175
+ return err
176
+ }
177
+
178
+ if len (out ) < 1 {
179
+ return fmt .Errorf ("mount point info is nil" )
180
+ }
181
+
182
+ mountInfos , err := parseMountInfo ([]byte (out ))
183
+ if err != nil {
184
+ return fmt .Errorf ("failed to parse the mount infos: %+v" , err )
185
+ }
186
+
187
+ mountInfosOfPod := MountPointInfo {}
188
+ for _ , mountInfo := range mountInfos {
189
+ if mountInfo .Target == podVolumeTargetPath {
190
+ mountInfosOfPod = mountInfo
191
+ break
192
+ }
193
+ }
194
+
195
+ // getting existing volumes based on the mount point infos.
196
+ // It's a temporary solution to recall volumes.
197
+ for _ , pv := range mountInfosOfPod .ContainerFileSystem {
198
+ if ! strings .Contains (pv .Target , csiSignOfVolumeTargetPath ) {
199
+ continue
200
+ }
201
+
202
+ hp , err := parseVolumeInfo (pv )
203
+ if err != nil {
204
+ return err
205
+ }
206
+
207
+ hostPathVolumes [hp .VolID ] = * hp
208
+ }
209
+
210
+ glog .V (4 ).Infof ("Existing Volumes: %+v" , hostPathVolumes )
211
+ return nil
212
+ }
213
+
170
214
func (hp * hostPath ) Run () error {
171
215
// Create GRPC servers
172
- if err := initialExistingVolumes (); err != nil {
216
+ if err := discoveryExistingVolumes (); err != nil {
173
217
return err
174
218
}
175
219
@@ -458,46 +502,3 @@ func parseVolumeInfo(volume MountPointInfo) (*hostPathVolume, error) {
458
502
459
503
return & hp , nil
460
504
}
461
-
462
- func initialExistingVolumes () error {
463
- cmdPath := locateCommandPath ("findmnt" )
464
- out , err := exec .Command (cmdPath , "--json" ).CombinedOutput ()
465
- if err != nil {
466
- glog .V (3 ).Infof ("failed to execute command: %+v" , cmdPath )
467
- return err
468
- }
469
-
470
- if len (out ) < 1 {
471
- return fmt .Errorf ("mount point info is nil" )
472
- }
473
-
474
- mountInfos , err := parseMountInfo ([]byte (out ))
475
- if err != nil {
476
- return fmt .Errorf ("failed to parse the mount infos: %+v" , err )
477
- }
478
-
479
- mountInfosOfPod := MountPointInfo {}
480
- for _ , mountInfo := range mountInfos {
481
- if mountInfo .Target == podVolumeTargetPath {
482
- mountInfosOfPod = mountInfo
483
- break
484
- }
485
- }
486
-
487
- // getting existing volumes based on the mount point infos.
488
- // It's a temporary solution to recall volumes.
489
- for _ , pv := range mountInfosOfPod .ContainerFileSystem {
490
- if ! strings .Contains (pv .Target , csiSignOfVolumeTargetPath ) {
491
- continue
492
- }
493
-
494
- hp , err := parseVolumeInfo (pv )
495
- if err != nil {
496
- return err
497
- }
498
-
499
- hostPathVolumes [hp .VolID ] = * hp
500
- }
501
-
502
- return nil
503
- }
0 commit comments