mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	proxy utils: GetNodeAddresses should check if matching addresses were found
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
This commit is contained in:
		@@ -221,6 +221,11 @@ func GetNodeAddresses(cidrs []string, nw NetworkInterfacer) (sets.String, error)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if uniqueAddressList.Len() == 0 {
 | 
			
		||||
		return nil, fmt.Errorf("no addresses found for cidrs %v", cidrs)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return uniqueAddressList, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ package util
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"net"
 | 
			
		||||
	"reflect"
 | 
			
		||||
	"testing"
 | 
			
		||||
@@ -260,6 +261,7 @@ func TestGetNodeAddressses(t *testing.T) {
 | 
			
		||||
		nw            *fake.FakeNetwork
 | 
			
		||||
		itfAddrsPairs []InterfaceAddrsPair
 | 
			
		||||
		expected      sets.String
 | 
			
		||||
		expectedErr   error
 | 
			
		||||
	}{
 | 
			
		||||
		{ // case 0
 | 
			
		||||
			cidrs: []string{"10.20.30.0/24"},
 | 
			
		||||
@@ -375,7 +377,8 @@ func TestGetNodeAddressses(t *testing.T) {
 | 
			
		||||
					addrs: []net.Addr{fake.AddrStruct{Val: "127.0.0.1/8"}},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			expected: sets.NewString(),
 | 
			
		||||
			expected:    nil,
 | 
			
		||||
			expectedErr: fmt.Errorf("no addresses found for cidrs %v", []string{"10.20.30.0/24", "100.200.201.0/24"}),
 | 
			
		||||
		},
 | 
			
		||||
		{ // case 8
 | 
			
		||||
			cidrs: []string{},
 | 
			
		||||
@@ -455,9 +458,10 @@ func TestGetNodeAddressses(t *testing.T) {
 | 
			
		||||
			testCases[i].nw.AddInterfaceAddr(&pair.itf, pair.addrs)
 | 
			
		||||
		}
 | 
			
		||||
		addrList, err := GetNodeAddresses(testCases[i].cidrs, testCases[i].nw)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
		if !reflect.DeepEqual(err, testCases[i].expectedErr) {
 | 
			
		||||
			t.Errorf("case [%d], unexpected error: %v", i, err)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if !addrList.Equal(testCases[i].expected) {
 | 
			
		||||
			t.Errorf("case [%d], unexpected mismatch, expected: %v, got: %v", i, testCases[i].expected, addrList)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user