Skip to content

Commit fc93307

Browse files
authored
Merge pull request #309 from lizhuqi/convert-name-to-ip
resolve name to ip before passing to csi-proxy
2 parents 4833296 + 19be772 commit fc93307

File tree

4 files changed

+18
-33
lines changed

4 files changed

+18
-33
lines changed

deploy/example/smb-provisioner/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ kubectl create secret generic smbcreds --from-literal username=USERNAME --from-l
1515
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/example/smb-provisioner/smb-server.yaml
1616
```
1717
- Access by Windows node
18-
> Since `smb-server.default.svc.cluster.local` could not be recognized by CSI proxy on Windows node, above `smb-server-lb.yaml` configures `LoadBalancer` as `Service.type`, and then configure public IP address for `source` in storage class
1918
```console
2019
kubectl create -f https://raw.githubusercontent.com/kubernetes-csi/csi-driver-smb/master/deploy/example/smb-provisioner/smb-server-lb.yaml
2120
```

pkg/mounter/safe_mounter_windows.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package mounter
2121
import (
2222
"context"
2323
"fmt"
24+
"net"
2425
"os"
2526
filepath "path/filepath"
2627
"strings"
@@ -71,6 +72,19 @@ func (mounter *CSIProxyMounter) SMBMount(source, target, fsType string, mountOpt
7172
}
7273
}
7374

75+
parts := strings.FieldsFunc(source, Split)
76+
if len(parts) > 0 && strings.HasSuffix(parts[0], "svc.cluster.local") {
77+
// replace hostname with IP in the source
78+
domainName := parts[0]
79+
ip, err := net.ResolveIPAddr("ip4", domainName)
80+
if err != nil {
81+
klog.Warningf("could not resolve name to IPv4 address for host %s, failed with error: %v", domainName, err)
82+
} else {
83+
klog.V(2).Infof("resolve the name of host %s to IPv4 address: %s", domainName, ip.String())
84+
source = strings.Replace(source, domainName, ip.String(), 1)
85+
}
86+
}
87+
7488
source = strings.Replace(source, "/", "\\", -1)
7589
smbMountRequest := &smb.NewSmbGlobalMappingRequest{
7690
LocalPath: normalizeWindowsPath(target),
@@ -107,6 +121,10 @@ func (mounter *CSIProxyMounter) Mount(source string, target string, fstype strin
107121
return nil
108122
}
109123

124+
func Split(r rune) bool {
125+
return r == ' ' || r == '/'
126+
}
127+
110128
// Rmdir - delete the given directory
111129
// TODO: Call separate rmdir for pod context and plugin context. v1alpha1 for CSI
112130
// proxy does a relaxed check for prefix as c:\var\lib\kubelet, so we can do

test/e2e/suite_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,6 @@ var _ = ginkgo.BeforeSuite(func() {
113113
err := os.Chdir("test/e2e")
114114
gomega.Expect(err).NotTo(gomega.HaveOccurred())
115115
}()
116-
117-
getSMBPublicIPScript := "test/utils/get_smb_svc_public_ip.sh"
118-
log.Printf("run script: %s\n", getSMBPublicIPScript)
119-
120-
cmd := exec.Command("bash", getSMBPublicIPScript)
121-
output, err := cmd.CombinedOutput()
122-
log.Printf("got output: %v, error: %v\n", string(output), err)
123-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
124-
125-
smbPublicIP := strings.TrimSuffix(string(output), "\n")
126-
source := `//` + smbPublicIP + `/share`
127-
128-
log.Printf("use source on Windows: %v\n", source)
129-
defaultStorageClassParameters["source"] = source
130116
}
131117
})
132118

test/utils/get_smb_svc_public_ip.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)