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

Commit 2cc8d13

Browse files
author
jeremy
committed
DEV-49046 Fix the internal IP cannot found bug in argus
1 parent 30932b0 commit 2cc8d13

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

pkg/watch/node/node.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +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
154+
var hostname *v1.NodeAddress
155155
for _, address := range addresses {
156156
if address.Type == v1.NodeInternalIP {
157157
return &address
158158
}
159159
if address.Type == v1.NodeHostName {
160-
hostname = address
160+
hostname = &address
161161
}
162162
}
163163
//if there is no internal IP for this node, the host name will be used
164-
return &hostname
164+
return hostname
165165
}
166166

167167
func (w *Watcher) createRoleDeviceGroup(labels map[string]string) {

pkg/watch/node/node_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package node
2+
3+
import (
4+
"k8s.io/api/core/v1"
5+
"testing"
6+
)
7+
8+
func TestGetInternalAddress(t *testing.T) {
9+
var addresses []v1.NodeAddress
10+
address := getInternalAddress(addresses)
11+
if address != nil {
12+
t.Errorf("invalid address: %v", address)
13+
}
14+
addresses = append(addresses, v1.NodeAddress{
15+
Type: v1.NodeHostName,
16+
Address: "test",
17+
})
18+
19+
address = getInternalAddress(addresses)
20+
if address == nil || address.Address != "test" {
21+
t.Errorf("invalid address: %v", address)
22+
}
23+
24+
addresses = append(addresses, v1.NodeAddress{
25+
Type: v1.NodeInternalIP,
26+
Address: "127.0.0.1",
27+
})
28+
29+
address = getInternalAddress(addresses)
30+
if address == nil || address.Address != "127.0.0.1" {
31+
t.Errorf("invalid address: %v", address)
32+
}
33+
}

0 commit comments

Comments
 (0)