Skip to content

Commit cc9f727

Browse files
committed
health check: clean up variable naming
The "sourcePath" name is not quite right: it is a "volume path" which just happens to be used as source in some places.
1 parent eefb2c5 commit cc9f727

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/hostpath/healthcheck.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ type FileSystems struct {
4848
Filsystem []ContainerFileSystem `json:"filesystems"`
4949
}
5050

51-
func checkSourcePathExist(sourcePath string) (bool, error) {
52-
_, err := os.Stat(sourcePath)
51+
func checkPathExist(path string) (bool, error) {
52+
_, err := os.Stat(path)
5353
if err != nil {
5454
if os.IsNotExist(err) {
5555
return false, nil
@@ -77,7 +77,7 @@ func parseMountInfo(originalMountInfo []byte) ([]MountPointInfo, error) {
7777
return fs.Filsystem[0].Children, nil
7878
}
7979

80-
func checkMountPointExist(sourcePath string) (bool, error) {
80+
func checkMountPointExist(volumePath string) (bool, error) {
8181
cmdPath, err := exec.LookPath("findmnt")
8282
if err != nil {
8383
return false, fmt.Errorf("findmnt not found: %w", err)
@@ -107,7 +107,7 @@ func checkMountPointExist(sourcePath string) (bool, error) {
107107
}
108108

109109
for _, mountInfo := range mountInfosOfPod.ContainerFileSystem {
110-
if !strings.Contains(mountInfo.Source, sourcePath) {
110+
if !strings.Contains(mountInfo.Source, volumePath) {
111111
continue
112112
}
113113

@@ -127,8 +127,8 @@ func checkMountPointExist(sourcePath string) (bool, error) {
127127
}
128128

129129
func (hp *hostPath) checkPVCapacityValid(volID string) (bool, error) {
130-
sourcePath := hp.getVolumePath(volID)
131-
_, fscapacity, _, _, _, _, err := fs.FsInfo(sourcePath)
130+
volumePath := hp.getVolumePath(volID)
131+
_, fscapacity, _, _, _, _, err := fs.FsInfo(volumePath)
132132
if err != nil {
133133
return false, fmt.Errorf("failed to get capacity info: %+v", err)
134134
}
@@ -147,8 +147,8 @@ func getPVStats(volumePath string) (available int64, capacity int64, used int64,
147147
}
148148

149149
func (hp *hostPath) checkPVUsage(volID string) (bool, error) {
150-
sourcePath := hp.getVolumePath(volID)
151-
fsavailable, _, _, _, _, _, err := fs.FsInfo(sourcePath)
150+
volumePath := hp.getVolumePath(volID)
151+
fsavailable, _, _, _, _, _, err := fs.FsInfo(volumePath)
152152
if err != nil {
153153
return false, err
154154
}
@@ -158,9 +158,9 @@ func (hp *hostPath) checkPVUsage(volID string) (bool, error) {
158158
}
159159

160160
func (hp *hostPath) doHealthCheckInControllerSide(volID string) (bool, string) {
161-
sourcePath := hp.getVolumePath(volID)
162-
glog.V(3).Infof("Volume: %s Source path is: %s", volID, sourcePath)
163-
spExist, err := checkSourcePathExist(sourcePath)
161+
volumePath := hp.getVolumePath(volID)
162+
glog.V(3).Infof("Volume with ID %s has path %s.", volID, volumePath)
163+
spExist, err := checkPathExist(volumePath)
164164
if err != nil {
165165
return false, err.Error()
166166
}
@@ -191,8 +191,8 @@ func (hp *hostPath) doHealthCheckInControllerSide(volID string) (bool, string) {
191191
}
192192

193193
func (hp *hostPath) doHealthCheckInNodeSide(volID string) (bool, string) {
194-
sourcePath := hp.getVolumePath(volID)
195-
mpExist, err := checkMountPointExist(sourcePath)
194+
volumePath := hp.getVolumePath(volID)
195+
mpExist, err := checkMountPointExist(volumePath)
196196
if err != nil {
197197
return false, err.Error()
198198
}

0 commit comments

Comments
 (0)