Skip to content

Commit f96d35f

Browse files
committed
proxy utils: GetNodeAddresses should check if matching addresses were found
Signed-off-by: Andrew Sy Kim <[email protected]>
1 parent a99321c commit f96d35f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pkg/proxy/util/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ func GetNodeAddresses(cidrs []string, nw NetworkInterfacer) (sets.String, error)
221221
}
222222
}
223223
}
224+
225+
if uniqueAddressList.Len() == 0 {
226+
return nil, fmt.Errorf("no addresses found for cidrs %v", cidrs)
227+
}
228+
224229
return uniqueAddressList, nil
225230
}
226231

pkg/proxy/util/utils_test.go

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

1919
import (
2020
"context"
21+
"fmt"
2122
"net"
2223
"reflect"
2324
"testing"
@@ -260,6 +261,7 @@ func TestGetNodeAddressses(t *testing.T) {
260261
nw *fake.FakeNetwork
261262
itfAddrsPairs []InterfaceAddrsPair
262263
expected sets.String
264+
expectedErr error
263265
}{
264266
{ // case 0
265267
cidrs: []string{"10.20.30.0/24"},
@@ -375,7 +377,8 @@ func TestGetNodeAddressses(t *testing.T) {
375377
addrs: []net.Addr{fake.AddrStruct{Val: "127.0.0.1/8"}},
376378
},
377379
},
378-
expected: sets.NewString(),
380+
expected: nil,
381+
expectedErr: fmt.Errorf("no addresses found for cidrs %v", []string{"10.20.30.0/24", "100.200.201.0/24"}),
379382
},
380383
{ // case 8
381384
cidrs: []string{},
@@ -455,9 +458,10 @@ func TestGetNodeAddressses(t *testing.T) {
455458
testCases[i].nw.AddInterfaceAddr(&pair.itf, pair.addrs)
456459
}
457460
addrList, err := GetNodeAddresses(testCases[i].cidrs, testCases[i].nw)
458-
if err != nil {
461+
if !reflect.DeepEqual(err, testCases[i].expectedErr) {
459462
t.Errorf("case [%d], unexpected error: %v", i, err)
460463
}
464+
461465
if !addrList.Equal(testCases[i].expected) {
462466
t.Errorf("case [%d], unexpected mismatch, expected: %v, got: %v", i, testCases[i].expected, addrList)
463467
}

0 commit comments

Comments
 (0)