Skip to content

Commit 9318ec8

Browse files
committed
obs-csi-driver supports IDC configuration
1 parent 92ae73a commit 9318ec8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/obs/nodeserver.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package obs
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"net/http"
2223
"os"
2324
"path"
@@ -202,6 +203,19 @@ func (ns *nodeServer) NodeUnpublishVolume(_ context.Context, req *csi.NodeUnpubl
202203
func (ns *nodeServer) NodeGetInfo(_ context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
203204
log.Infof("NodeGetInfo called with request %v", protosanitizer.StripSecrets(*req))
204205

206+
idc := ns.Driver.cloud.Global.Idc
207+
if idc{
208+
log.Info("IDC is %v. volume will be mounted directly \n", idc)
209+
macAddress, err := getMACAddress()
210+
if err != nil {
211+
log.Errorf("failed to get mac address: %v", err)
212+
return &csi.NodeGetInfoResponse{}, fmt.Errorf("failed to gen nodeID: %v", err)
213+
}
214+
return &csi.NodeGetInfoResponse{
215+
NodeId: macAddress,
216+
}, nil
217+
}
218+
205219
nodeID, err := ns.Metadata.GetInstanceID()
206220
if err != nil {
207221
return nil, status.Errorf(codes.Internal, "Unable to retrieve instance id of node %s", err)
@@ -284,3 +298,18 @@ func nodeGetStatsValidation(volumeID, volumePath string) error {
284298
}
285299
return nil
286300
}
301+
302+
func getMACAddress() (string, error) {
303+
interfaces, err := net.Interfaces()
304+
if err != nil {
305+
return "", err
306+
}
307+
308+
for _, v := range interfaces {
309+
if v.Flags&net.FlagLoopback == 0 && len(v.HardwareAddr.String()) > 0 {
310+
return strings.ReplaceAll(v.HardwareAddr.String(), ":", "_"), nil
311+
}
312+
}
313+
314+
return "", fmt.Errorf("MAC address not found")
315+
}

0 commit comments

Comments
 (0)