@@ -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
@@ -466,46 +510,3 @@ func parseVolumeInfo(volume MountPointInfo) (*hostPathVolume, error) {
466
510
467
511
return & hp , nil
468
512
}
469
-
470
- func initialExistingVolumes () error {
471
- cmdPath := locateCommandPath ("findmnt" )
472
- out , err := exec .Command (cmdPath , "--json" ).CombinedOutput ()
473
- if err != nil {
474
- glog .V (3 ).Infof ("failed to execute command: %+v" , cmdPath )
475
- return err
476
- }
477
-
478
- if len (out ) < 1 {
479
- return fmt .Errorf ("mount point info is nil" )
480
- }
481
-
482
- mountInfos , err := parseMountInfo ([]byte (out ))
483
- if err != nil {
484
- return fmt .Errorf ("failed to parse the mount infos: %+v" , err )
485
- }
486
-
487
- mountInfosOfPod := MountPointInfo {}
488
- for _ , mountInfo := range mountInfos {
489
- if mountInfo .Target == podVolumeTargetPath {
490
- mountInfosOfPod = mountInfo
491
- break
492
- }
493
- }
494
-
495
- // getting existing volumes based on the mount point infos.
496
- // It's a temporary solution to recall volumes.
497
- for _ , pv := range mountInfosOfPod .ContainerFileSystem {
498
- if ! strings .Contains (pv .Target , csiSignOfVolumeTargetPath ) {
499
- continue
500
- }
501
-
502
- hp , err := parseVolumeInfo (pv )
503
- if err != nil {
504
- return err
505
- }
506
-
507
- hostPathVolumes [hp .VolID ] = * hp
508
- }
509
-
510
- return nil
511
- }
0 commit comments