Skip to content

Commit e0618e1

Browse files
committed
fix
1 parent d876b17 commit e0618e1

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

pkg/hostpath/hostpath.go

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,53 @@ func discoverExistingSnapshots() {
167167
}
168168
}
169169

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+
170214
func (hp *hostPath) Run() error {
171215
// Create GRPC servers
172-
if err := initialExistingVolumes(); err != nil {
216+
if err := discoveryExistingVolumes(); err != nil {
173217
return err
174218
}
175219

@@ -466,46 +510,3 @@ func parseVolumeInfo(volume MountPointInfo) (*hostPathVolume, error) {
466510

467511
return &hp, nil
468512
}
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

Comments
 (0)