Skip to content

Commit fd96151

Browse files
committed
fix
1 parent e7effcb commit fd96151

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

@@ -458,46 +502,3 @@ func parseVolumeInfo(volume MountPointInfo) (*hostPathVolume, error) {
458502

459503
return &hp, nil
460504
}
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

Comments
 (0)