Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 838e88b

Browse files
author
Jeremy Tang
committed
Merge pull request #16 in DEV/k8s-argus from DEV-49046-fix-the-internal-ip-cannot-found to develop
* commit '30932b003b72fb8667d88c9436346f829c8bdc88': DEV-49046 Fix the internal IP cannot found bug in argus
2 parents 746c3d9 + 30932b0 commit 838e88b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pkg/watch/node/node.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,17 @@ func (w *Watcher) args(node *v1.Node, category string) []types.DeviceOption {
151151

152152
// getInternalAddress finds the node's internal address.
153153
func getInternalAddress(addresses []v1.NodeAddress) *v1.NodeAddress {
154+
var hostname v1.NodeAddress
154155
for _, address := range addresses {
155156
if address.Type == v1.NodeInternalIP {
156157
return &address
157158
}
159+
if address.Type == v1.NodeHostName {
160+
hostname = address
161+
}
158162
}
159-
160-
return nil
163+
//if there is no internal IP for this node, the host name will be used
164+
return &hostname
161165
}
162166

163167
func (w *Watcher) createRoleDeviceGroup(labels map[string]string) {
@@ -201,7 +205,11 @@ func GetNodesMap(k8sClient *kubernetes.Clientset) (map[string]string, error) {
201205
return nil, err
202206
}
203207
for _, nodeInfo := range nodeList.Items {
204-
nodesMap[nodeInfo.Name] = getInternalAddress(nodeInfo.Status.Addresses).Address
208+
address := getInternalAddress(nodeInfo.Status.Addresses)
209+
if address == nil {
210+
continue
211+
}
212+
nodesMap[nodeInfo.Name] = address.Address
205213
}
206214

207215
return nodesMap, nil

0 commit comments

Comments
 (0)