Skip to content

Commit 80bf507

Browse files
authored
Merge pull request kubernetes#129368 from andyzhangx/adopt-go1.23-behavior-change-mount-utils
fix: adopt go1.23 behavior change in mount point parsing on Windows#1
2 parents e2b0cfa + bdd0f5d commit 80bf507

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

staging/src/k8s.io/mount-utils/mount_windows.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ func (mounter *Mounter) IsLikelyNotMountPoint(file string) (bool, error) {
242242
if stat.Mode()&os.ModeSymlink != 0 {
243243
return false, err
244244
}
245+
// go1.23 behavior change: https://github.com/golang/go/issues/63703#issuecomment-2535941458
246+
if stat.Mode()&os.ModeIrregular != 0 {
247+
return false, err
248+
}
245249
return true, nil
246250
}
247251

@@ -329,30 +333,3 @@ func ListVolumesOnDisk(diskID string) (volumeIDs []string, err error) {
329333
volumeIds := strings.Split(strings.TrimSpace(string(output)), "\r\n")
330334
return volumeIds, nil
331335
}
332-
333-
// getAllParentLinks walks all symbolic links and return all the parent targets recursively
334-
func getAllParentLinks(path string) ([]string, error) {
335-
const maxIter = 255
336-
links := []string{}
337-
for {
338-
links = append(links, path)
339-
if len(links) > maxIter {
340-
return links, fmt.Errorf("unexpected length of parent links: %v", links)
341-
}
342-
343-
fi, err := os.Lstat(path)
344-
if err != nil {
345-
return links, fmt.Errorf("Lstat: %v", err)
346-
}
347-
if fi.Mode()&os.ModeSymlink == 0 {
348-
break
349-
}
350-
351-
path, err = os.Readlink(path)
352-
if err != nil {
353-
return links, fmt.Errorf("Readlink error: %v", err)
354-
}
355-
}
356-
357-
return links, nil
358-
}

staging/src/k8s.io/mount-utils/mount_windows_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"testing"
2828

2929
"github.com/stretchr/testify/assert"
30-
"k8s.io/utils/exec/testing"
30+
testingexec "k8s.io/utils/exec/testing"
3131
)
3232

3333
func makeLink(link, target string) error {
@@ -193,7 +193,26 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
193193
}
194194
return removeLink(targeLinkPath)
195195
},
196-
true,
196+
false,
197+
false,
198+
},
199+
{
200+
"junction",
201+
"targetDir",
202+
func(base, fileName, targetLinkName string) error {
203+
target := filepath.Join(base, targetLinkName)
204+
if err := os.Mkdir(target, 0o750); err != nil {
205+
return err
206+
}
207+
208+
// create a Junction file type on Windows
209+
junction := filepath.Join(base, fileName)
210+
if output, err := exec.Command("cmd", "/c", "mklink", "/J", junction, target).CombinedOutput(); err != nil {
211+
return fmt.Errorf("mklink failed: %v, link(%q) target(%q) output: %q", err, junction, target, string(output))
212+
}
213+
return nil
214+
},
215+
false,
197216
false,
198217
},
199218
}
@@ -207,7 +226,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) {
207226

208227
filePath := filepath.Join(base, test.fileName)
209228
result, err := mounter.IsLikelyNotMountPoint(filePath)
210-
assert.Equal(t, result, test.expectedResult, "Expect result not equal with IsLikelyNotMountPoint(%s) return: %q, expected: %q",
229+
assert.Equal(t, test.expectedResult, result, "Expect result not equal with IsLikelyNotMountPoint(%s) return: %q, expected: %q",
211230
filePath, result, test.expectedResult)
212231

213232
if test.expectError {

0 commit comments

Comments
 (0)