Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pkg/obs/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package obs

import (
"fmt"
"net"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -202,6 +203,19 @@ func (ns *nodeServer) NodeUnpublishVolume(_ context.Context, req *csi.NodeUnpubl
func (ns *nodeServer) NodeGetInfo(_ context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
log.Infof("NodeGetInfo called with request %v", protosanitizer.StripSecrets(*req))

idc := ns.Driver.cloud.Global.Idc
if idc {
log.Info("IDC is %v. volume will be mounted directly \n", idc)
macAddress, err := getMACAddress()
if err != nil {
log.Errorf("failed to get mac address: %v", err)
return &csi.NodeGetInfoResponse{}, fmt.Errorf("failed to gen nodeID: %v", err)
}
return &csi.NodeGetInfoResponse{
NodeId: macAddress,
}, nil
}

nodeID, err := ns.Metadata.GetInstanceID()
if err != nil {
return nil, status.Errorf(codes.Internal, "Unable to retrieve instance id of node %s", err)
Expand Down Expand Up @@ -284,3 +298,18 @@ func nodeGetStatsValidation(volumeID, volumePath string) error {
}
return nil
}

func getMACAddress() (string, error) {
interfaces, err := net.Interfaces()
if err != nil {
return "", err
}

for _, v := range interfaces {
if v.Flags&net.FlagLoopback == 0 && len(v.HardwareAddr.String()) > 0 {
return strings.ReplaceAll(v.HardwareAddr.String(), ":", "_"), nil
}
}

return "", fmt.Errorf("MAC address not found")
}