Skip to content

Commit

Permalink
Revert "fix: register worker nodes on the Unity array" (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamginna-dell authored Mar 12, 2024
1 parent 0280db1 commit cc95c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ func (s *service) addNodeInformationIntoArray(ctx context.Context, array *Storag
log.Infof("Node %s does not have FC or iSCSI initiators and can only be used for NFS exports", s.opts.NodeName)
}

nodeIps, err := utils.GetHostIP(ctx)
nodeIps, err := utils.GetHostIP()
if err != nil {
return status.Error(codes.Unknown, utils.GetMessageWithRunID(rid, "Unable to get node IP. Error: %v", err))
}
Expand Down
21 changes: 5 additions & 16 deletions service/utils/emcutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ func GetFCInitiators(ctx context.Context) ([]string, error) {
}

// GetHostIP - Utility method to extract Host IP
func GetHostIP(ctx context.Context) ([]string, error) {
log := GetRunidLogger(ctx)
func GetHostIP() ([]string, error) {
cmd := exec.Command("hostname", "-I")
cmdOutput := &bytes.Buffer{}
cmd.Stdout = cmdOutput
Expand All @@ -162,31 +161,21 @@ func GetHostIP(ctx context.Context) ([]string, error) {
}
output := string(cmdOutput.Bytes())
ips := strings.Split(strings.TrimSpace(output), " ")
log.Debugf("Host IPs: %v", ips)

hostname, err := os.Hostname()
log.Debugf("Hostname: %v", hostname)
if err != nil {
return nil, err
}

var lookupIps []string
for _, ip := range ips {
if !strings.Contains(ip, ":") {
lookupResp, err := net.LookupAddr(ip)
log.Debugf("lookupResp: %v for ip: %v", lookupResp, ip)
if err == nil {
for _, resp := range lookupResp {
log.Debugf("resp: %v, hostname: %v", resp, hostname)
if strings.Contains(resp, hostname) {
lookupIps = append(lookupIps, ip)
}
}
}
lookupResp, err := net.LookupAddr(ip)
if err == nil && strings.Contains(lookupResp[0], hostname) {
lookupIps = append(lookupIps, ip)
}
}
if len(lookupIps) == 0 {
return nil, errors.New("host ip not found")
lookupIps = append(lookupIps, ips[0])
}
return lookupIps, nil
}
Expand Down

0 comments on commit cc95c96

Please sign in to comment.