pkg/proxy: using generic sets

pkg/proxy: using generic sets

Signed-off-by: Daman <aroradaman@gmail.com>
This commit is contained in:
Daman 2023-04-15 22:59:21 +05:30
parent 940101e07e
commit c2c8b8d178
17 changed files with 244 additions and 244 deletions

View File

@ -181,7 +181,7 @@ func validateProxyMode(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) fiel
} }
func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList { func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
validModes := sets.NewString( validModes := sets.New[string](
string(kubeproxyconfig.ProxyModeIPTables), string(kubeproxyconfig.ProxyModeIPTables),
string(kubeproxyconfig.ProxyModeIPVS), string(kubeproxyconfig.ProxyModeIPVS),
) )
@ -190,12 +190,12 @@ func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path)
return nil return nil
} }
errMsg := fmt.Sprintf("must be %s or blank (blank means the best-available proxy [currently iptables])", strings.Join(validModes.List(), ",")) errMsg := fmt.Sprintf("must be %s or blank (blank means the best-available proxy [currently iptables])", strings.Join(sets.List(validModes), ","))
return field.ErrorList{field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg)} return field.ErrorList{field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg)}
} }
func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList { func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
validModes := sets.NewString( validModes := sets.New[string](
string(kubeproxyconfig.ProxyModeKernelspace), string(kubeproxyconfig.ProxyModeKernelspace),
) )
@ -203,7 +203,7 @@ func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Pat
return nil return nil
} }
errMsg := fmt.Sprintf("must be %s or blank (blank means the most-available proxy [currently 'kernelspace'])", strings.Join(validModes.List(), ",")) errMsg := fmt.Sprintf("must be %s or blank (blank means the most-available proxy [currently 'kernelspace'])", strings.Join(sets.List(validModes), ","))
return field.ErrorList{field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg)} return field.ErrorList{field.Invalid(fldPath.Child("ProxyMode"), string(mode), errMsg)}
} }

View File

@ -33,7 +33,7 @@ import (
utilproxy "k8s.io/kubernetes/pkg/proxy/util" utilproxy "k8s.io/kubernetes/pkg/proxy/util"
) )
var supportedEndpointSliceAddressTypes = sets.NewString( var supportedEndpointSliceAddressTypes = sets.New[string](
string(discovery.AddressTypeIPv4), string(discovery.AddressTypeIPv4),
string(discovery.AddressTypeIPv6), string(discovery.AddressTypeIPv6),
) )
@ -49,7 +49,7 @@ type BaseEndpointInfo struct {
// ZoneHints represent the zone hints for the endpoint. This is based on // ZoneHints represent the zone hints for the endpoint. This is based on
// endpoint.hints.forZones[*].name in the EndpointSlice API. // endpoint.hints.forZones[*].name in the EndpointSlice API.
ZoneHints sets.String ZoneHints sets.Set[string]
// Ready indicates whether this endpoint is ready and NOT terminating. // Ready indicates whether this endpoint is ready and NOT terminating.
// For pods, this is true if a pod has a ready status and a nil deletion timestamp. // For pods, this is true if a pod has a ready status and a nil deletion timestamp.
// This is only set when watching EndpointSlices. If using Endpoints, this is always // This is only set when watching EndpointSlices. If using Endpoints, this is always
@ -103,7 +103,7 @@ func (info *BaseEndpointInfo) IsTerminating() bool {
} }
// GetZoneHints returns the zone hint for the endpoint. // GetZoneHints returns the zone hint for the endpoint.
func (info *BaseEndpointInfo) GetZoneHints() sets.String { func (info *BaseEndpointInfo) GetZoneHints() sets.Set[string] {
return info.ZoneHints return info.ZoneHints
} }
@ -135,7 +135,7 @@ func (info *BaseEndpointInfo) GetZone() string {
} }
func newBaseEndpointInfo(IP, nodeName, zone string, port int, isLocal bool, func newBaseEndpointInfo(IP, nodeName, zone string, port int, isLocal bool,
ready, serving, terminating bool, zoneHints sets.String) *BaseEndpointInfo { ready, serving, terminating bool, zoneHints sets.Set[string]) *BaseEndpointInfo {
return &BaseEndpointInfo{ return &BaseEndpointInfo{
Endpoint: net.JoinHostPort(IP, strconv.Itoa(port)), Endpoint: net.JoinHostPort(IP, strconv.Itoa(port)),
IsLocal: isLocal, IsLocal: isLocal,
@ -232,7 +232,7 @@ func (ect *EndpointChangeTracker) EndpointSliceUpdate(endpointSlice *discovery.E
// PendingChanges returns a set whose keys are the names of the services whose endpoints // PendingChanges returns a set whose keys are the names of the services whose endpoints
// have changed since the last time ect was used to update an EndpointsMap. (You must call // have changed since the last time ect was used to update an EndpointsMap. (You must call
// this _before_ calling em.Update(ect).) // this _before_ calling em.Update(ect).)
func (ect *EndpointChangeTracker) PendingChanges() sets.String { func (ect *EndpointChangeTracker) PendingChanges() sets.Set[string] {
return ect.endpointSliceCache.pendingChanges() return ect.endpointSliceCache.pendingChanges()
} }
@ -361,8 +361,8 @@ func (em EndpointsMap) unmerge(other EndpointsMap) {
} }
// getLocalEndpointIPs returns endpoints IPs if given endpoint is local - local means the endpoint is running in same host as kube-proxy. // getLocalEndpointIPs returns endpoints IPs if given endpoint is local - local means the endpoint is running in same host as kube-proxy.
func (em EndpointsMap) getLocalReadyEndpointIPs() map[types.NamespacedName]sets.String { func (em EndpointsMap) getLocalReadyEndpointIPs() map[types.NamespacedName]sets.Set[string] {
localIPs := make(map[types.NamespacedName]sets.String) localIPs := make(map[types.NamespacedName]sets.Set[string])
for svcPortName, epList := range em { for svcPortName, epList := range em {
for _, ep := range epList { for _, ep := range epList {
// Only add ready endpoints for health checking. Terminating endpoints may still serve traffic // Only add ready endpoints for health checking. Terminating endpoints may still serve traffic
@ -374,7 +374,7 @@ func (em EndpointsMap) getLocalReadyEndpointIPs() map[types.NamespacedName]sets.
if ep.GetIsLocal() { if ep.GetIsLocal() {
nsn := svcPortName.NamespacedName nsn := svcPortName.NamespacedName
if localIPs[nsn] == nil { if localIPs[nsn] == nil {
localIPs[nsn] = sets.NewString() localIPs[nsn] = sets.New[string]()
} }
localIPs[nsn].Insert(ep.IP()) localIPs[nsn].Insert(ep.IP())
} }

View File

@ -45,11 +45,11 @@ func (proxier *FakeProxier) deleteEndpointSlice(slice *discovery.EndpointSlice)
func TestGetLocalEndpointIPs(t *testing.T) { func TestGetLocalEndpointIPs(t *testing.T) {
testCases := []struct { testCases := []struct {
endpointsMap EndpointsMap endpointsMap EndpointsMap
expected map[types.NamespacedName]sets.String expected map[types.NamespacedName]sets.Set[string]
}{{ }{{
// Case[0]: nothing // Case[0]: nothing
endpointsMap: EndpointsMap{}, endpointsMap: EndpointsMap{},
expected: map[types.NamespacedName]sets.String{}, expected: map[types.NamespacedName]sets.Set[string]{},
}, { }, {
// Case[1]: unnamed port // Case[1]: unnamed port
endpointsMap: EndpointsMap{ endpointsMap: EndpointsMap{
@ -57,7 +57,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expected: map[types.NamespacedName]sets.String{}, expected: map[types.NamespacedName]sets.Set[string]{},
}, { }, {
// Case[2]: unnamed port local // Case[2]: unnamed port local
endpointsMap: EndpointsMap{ endpointsMap: EndpointsMap{
@ -65,8 +65,8 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expected: map[types.NamespacedName]sets.String{ expected: map[types.NamespacedName]sets.Set[string]{
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.1"), {Namespace: "ns1", Name: "ep1"}: sets.New[string]("1.1.1.1"),
}, },
}, { }, {
// Case[3]: named local and non-local ports for the same IP. // Case[3]: named local and non-local ports for the same IP.
@ -80,8 +80,8 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expected: map[types.NamespacedName]sets.String{ expected: map[types.NamespacedName]sets.Set[string]{
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.2"), {Namespace: "ns1", Name: "ep1"}: sets.New[string]("1.1.1.2"),
}, },
}, { }, {
// Case[4]: named local and non-local ports for different IPs. // Case[4]: named local and non-local ports for different IPs.
@ -104,9 +104,9 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expected: map[types.NamespacedName]sets.String{ expected: map[types.NamespacedName]sets.Set[string]{
{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22", "2.2.2.3"), {Namespace: "ns2", Name: "ep2"}: sets.New[string]("2.2.2.2", "2.2.2.22", "2.2.2.3"),
{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"), {Namespace: "ns4", Name: "ep4"}: sets.New[string]("4.4.4.4", "4.4.4.6"),
}, },
}, { }, {
// Case[5]: named local and non-local ports for different IPs, some not ready. // Case[5]: named local and non-local ports for different IPs, some not ready.
@ -129,9 +129,9 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expected: map[types.NamespacedName]sets.String{ expected: map[types.NamespacedName]sets.Set[string]{
{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22"), {Namespace: "ns2", Name: "ep2"}: sets.New[string]("2.2.2.2", "2.2.2.22"),
{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"), {Namespace: "ns4", Name: "ep4"}: sets.New[string]("4.4.4.4", "4.4.4.6"),
}, },
}, { }, {
// Case[6]: all endpoints are terminating,, so getLocalReadyEndpointIPs should return 0 ready endpoints // Case[6]: all endpoints are terminating,, so getLocalReadyEndpointIPs should return 0 ready endpoints
@ -154,7 +154,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
&BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: false, Serving: true, Terminating: true}, &BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: false, Serving: true, Terminating: true},
}, },
}, },
expected: make(map[types.NamespacedName]sets.String, 0), expected: make(map[types.NamespacedName]sets.Set[string], 0),
}} }}
for tci, tc := range testCases { for tci, tc := range testCases {
@ -506,7 +506,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedDeletedUDPEndpoints []ServiceEndpoint expectedDeletedUDPEndpoints []ServiceEndpoint
expectedNewlyActiveUDPServices map[ServicePortName]bool expectedNewlyActiveUDPServices map[ServicePortName]bool
expectedLocalEndpoints map[types.NamespacedName]int expectedLocalEndpoints map[types.NamespacedName]int
expectedChangedEndpoints sets.String expectedChangedEndpoints sets.Set[string]
}{{ }{{
name: "empty", name: "empty",
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{}, oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{},
@ -514,7 +514,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedDeletedUDPEndpoints: []ServiceEndpoint{}, expectedDeletedUDPEndpoints: []ServiceEndpoint{},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "no change, unnamed port", name: "no change, unnamed port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -536,7 +536,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedDeletedUDPEndpoints: []ServiceEndpoint{}, expectedDeletedUDPEndpoints: []ServiceEndpoint{},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "no change, named port, local", name: "no change, named port, local",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -560,7 +560,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns1", "ep1"): 1, makeNSN("ns1", "ep1"): 1,
}, },
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "no change, multiple slices", name: "no change, multiple slices",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -590,7 +590,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedDeletedUDPEndpoints: []ServiceEndpoint{}, expectedDeletedUDPEndpoints: []ServiceEndpoint{},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "no change, multiple slices, multiple ports, local", name: "no change, multiple slices, multiple ports, local",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -628,7 +628,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns1", "ep1"): 1, makeNSN("ns1", "ep1"): 1,
}, },
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "no change, multiple services, slices, IPs, and ports", name: "no change, multiple services, slices, IPs, and ports",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -699,7 +699,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
makeNSN("ns1", "ep1"): 2, makeNSN("ns1", "ep1"): 2,
makeNSN("ns2", "ep2"): 1, makeNSN("ns2", "ep2"): 1,
}, },
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, { }, {
name: "add an EndpointSlice", name: "add an EndpointSlice",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -721,7 +721,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns1", "ep1"): 1, makeNSN("ns1", "ep1"): 1,
}, },
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "remove an EndpointSlice", name: "remove an EndpointSlice",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -742,7 +742,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "add an IP and port", name: "add an IP and port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -773,7 +773,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns1", "ep1"): 1, makeNSN("ns1", "ep1"): 1,
}, },
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "remove an IP and port", name: "remove an IP and port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -809,7 +809,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "add a slice to an endpoint", name: "add a slice to an endpoint",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -840,7 +840,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns1", "ep1"): 1, makeNSN("ns1", "ep1"): 1,
}, },
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "remove a slice from an endpoint", name: "remove a slice from an endpoint",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -870,7 +870,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "rename a port", name: "rename a port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -897,7 +897,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
makeServicePortName("ns1", "ep1", "p11-2", v1.ProtocolUDP): true, makeServicePortName("ns1", "ep1", "p11-2", v1.ProtocolUDP): true,
}, },
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "renumber a port", name: "renumber a port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -922,7 +922,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
}}, }},
expectedNewlyActiveUDPServices: map[ServicePortName]bool{}, expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, { }, {
name: "complex add and remove", name: "complex add and remove",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -1012,7 +1012,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
expectedLocalEndpoints: map[types.NamespacedName]int{ expectedLocalEndpoints: map[types.NamespacedName]int{
makeNSN("ns4", "ep4"): 1, makeNSN("ns4", "ep4"): 1,
}, },
expectedChangedEndpoints: sets.NewString("ns1/ep1", "ns2/ep2", "ns3/ep3", "ns4/ep4"), expectedChangedEndpoints: sets.New[string]("ns1/ep1", "ns2/ep2", "ns3/ep3", "ns4/ep4"),
}, { }, {
name: "change from 0 endpoint address to 1 unnamed port", name: "change from 0 endpoint address to 1 unnamed port",
previousEndpoints: []*discovery.EndpointSlice{ previousEndpoints: []*discovery.EndpointSlice{
@ -1032,7 +1032,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): true, makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): true,
}, },
expectedLocalEndpoints: map[types.NamespacedName]int{}, expectedLocalEndpoints: map[types.NamespacedName]int{},
expectedChangedEndpoints: sets.NewString("ns1/ep1"), expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
}, },
} }
@ -1073,7 +1073,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
pendingChanges := fp.endpointsChanges.PendingChanges() pendingChanges := fp.endpointsChanges.PendingChanges()
if !pendingChanges.Equal(tc.expectedChangedEndpoints) { if !pendingChanges.Equal(tc.expectedChangedEndpoints) {
t.Errorf("[%d] expected changed endpoints %q, got %q", tci, tc.expectedChangedEndpoints.List(), pendingChanges.List()) t.Errorf("[%d] expected changed endpoints %q, got %q", tci, tc.expectedChangedEndpoints.UnsortedList(), pendingChanges.UnsortedList())
} }
result := fp.endpointsMap.Update(fp.endpointsChanges) result := fp.endpointsMap.Update(fp.endpointsChanges)
@ -1273,7 +1273,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
paramRemoveSlice bool paramRemoveSlice bool
expectedReturnVal bool expectedReturnVal bool
expectedCurrentChange map[ServicePortName][]*BaseEndpointInfo expectedCurrentChange map[ServicePortName][]*BaseEndpointInfo
expectedChangedEndpoints sets.String expectedChangedEndpoints sets.Set[string]
}{ }{
// test starting from an empty state // test starting from an empty state
"add a simple slice that doesn't already exist": { "add a simple slice that doesn't already exist": {
@ -1295,7 +1295,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.1.3:443", IsLocal: false, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.1.3:443", IsLocal: false, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// test no modification to state - current change should be nil as nothing changes // test no modification to state - current change should be nil as nothing changes
"add the same slice that already exists": { "add the same slice that already exists": {
@ -1308,7 +1308,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: false, expectedReturnVal: false,
expectedCurrentChange: nil, expectedCurrentChange: nil,
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, },
// ensure that only valide address types are processed // ensure that only valide address types are processed
"add an FQDN slice (invalid address type)": { "add an FQDN slice (invalid address type)": {
@ -1321,7 +1321,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
paramRemoveSlice: false, paramRemoveSlice: false,
expectedReturnVal: false, expectedReturnVal: false,
expectedCurrentChange: nil, expectedCurrentChange: nil,
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, },
// test additions to existing state // test additions to existing state
"add a slice that overlaps with existing state": { "add a slice that overlaps with existing state": {
@ -1354,7 +1354,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// test additions to existing state with partially overlapping slices and ports // test additions to existing state with partially overlapping slices and ports
"add a slice that overlaps with existing state and partial ports": { "add a slice that overlaps with existing state and partial ports": {
@ -1385,7 +1385,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// test deletions from existing state with partially overlapping slices and ports // test deletions from existing state with partially overlapping slices and ports
"remove a slice that overlaps with existing state": { "remove a slice that overlaps with existing state": {
@ -1408,7 +1408,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// ensure a removal that has no effect turns into a no-op // ensure a removal that has no effect turns into a no-op
"remove a slice that doesn't even exist in current state": { "remove a slice that doesn't even exist in current state": {
@ -1422,7 +1422,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
paramRemoveSlice: true, paramRemoveSlice: true,
expectedReturnVal: false, expectedReturnVal: false,
expectedCurrentChange: nil, expectedCurrentChange: nil,
expectedChangedEndpoints: sets.NewString(), expectedChangedEndpoints: sets.New[string](),
}, },
// start with all endpoints ready, transition to no endpoints ready // start with all endpoints ready, transition to no endpoints ready
"transition all endpoints to unready state": { "transition all endpoints to unready state": {
@ -1446,7 +1446,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.1.3:443", IsLocal: true, Ready: false, Serving: false, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.1.3:443", IsLocal: true, Ready: false, Serving: false, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// start with no endpoints ready, transition to all endpoints ready // start with no endpoints ready, transition to all endpoints ready
"transition all endpoints to ready state": { "transition all endpoints to ready state": {
@ -1468,7 +1468,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.1.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.1.2:443", IsLocal: true, Ready: true, Serving: true, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// start with some endpoints ready, transition to more endpoints ready // start with some endpoints ready, transition to more endpoints ready
"transition some endpoints to ready state": { "transition some endpoints to ready state": {
@ -1497,7 +1497,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: false, Serving: false, Terminating: false}, &BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: false, Serving: false, Terminating: false},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
// start with some endpoints ready, transition to some terminating // start with some endpoints ready, transition to some terminating
"transition some endpoints to terminating state": { "transition some endpoints to terminating state": {
@ -1526,7 +1526,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: false, Serving: false, Terminating: true}, &BaseEndpointInfo{Endpoint: "10.0.2.2:443", IsLocal: true, Ready: false, Serving: false, Terminating: true},
}, },
}, },
expectedChangedEndpoints: sets.NewString("ns1/svc1"), expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
}, },
} }
@ -1541,7 +1541,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
pendingChanges := tc.endpointChangeTracker.PendingChanges() pendingChanges := tc.endpointChangeTracker.PendingChanges()
if !pendingChanges.Equal(tc.expectedChangedEndpoints) { if !pendingChanges.Equal(tc.expectedChangedEndpoints) {
t.Errorf("expected changed endpoints %q, got %q", tc.expectedChangedEndpoints.List(), pendingChanges.List()) t.Errorf("expected changed endpoints %q, got %q", tc.expectedChangedEndpoints.UnsortedList(), pendingChanges.UnsortedList())
} }
changes := tc.endpointChangeTracker.checkoutChanges() changes := tc.endpointChangeTracker.checkoutChanges()

View File

@ -81,7 +81,7 @@ type endpointInfo struct {
Addresses []string Addresses []string
NodeName *string NodeName *string
Zone *string Zone *string
ZoneHints sets.String ZoneHints sets.Set[string]
Ready bool Ready bool
Serving bool Serving bool
@ -141,7 +141,7 @@ func newEndpointSliceInfo(endpointSlice *discovery.EndpointSlice, remove bool) *
if utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints) { if utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints) {
if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 { if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 {
epInfo.ZoneHints = sets.String{} epInfo.ZoneHints = sets.New[string]()
for _, zone := range endpoint.Hints.ForZones { for _, zone := range endpoint.Hints.ForZones {
epInfo.ZoneHints.Insert(zone.Name) epInfo.ZoneHints.Insert(zone.Name)
} }
@ -190,11 +190,11 @@ func (cache *EndpointSliceCache) updatePending(endpointSlice *discovery.Endpoint
// pendingChanges returns a set whose keys are the names of the services whose endpoints // pendingChanges returns a set whose keys are the names of the services whose endpoints
// have changed since the last time checkoutChanges was called // have changed since the last time checkoutChanges was called
func (cache *EndpointSliceCache) pendingChanges() sets.String { func (cache *EndpointSliceCache) pendingChanges() sets.Set[string] {
cache.lock.Lock() cache.lock.Lock()
defer cache.lock.Unlock() defer cache.lock.Unlock()
changes := sets.NewString() changes := sets.New[string]()
for serviceNN, esTracker := range cache.trackerByServiceMap { for serviceNN, esTracker := range cache.trackerByServiceMap {
if len(esTracker.pending) > 0 { if len(esTracker.pending) > 0 {
changes.Insert(serviceNN.String()) changes.Insert(serviceNN.String())

View File

@ -32,12 +32,12 @@ import (
) )
type fakeListener struct { type fakeListener struct {
openPorts sets.String openPorts sets.Set[string]
} }
func newFakeListener() *fakeListener { func newFakeListener() *fakeListener {
return &fakeListener{ return &fakeListener{
openPorts: sets.String{}, openPorts: sets.Set[string]{},
} }
} }

View File

@ -63,15 +63,15 @@ func newServiceHealthServer(hostname string, recorder events.EventRecorder, list
nodeAddresses, err := nodePortAddresses.GetNodeAddresses(utilproxy.RealNetwork{}) nodeAddresses, err := nodePortAddresses.GetNodeAddresses(utilproxy.RealNetwork{})
if err != nil || nodeAddresses.Len() == 0 { if err != nil || nodeAddresses.Len() == 0 {
klog.ErrorS(err, "Failed to get node ip address matching node port addresses, health check port will listen to all node addresses", "nodePortAddresses", nodePortAddresses) klog.ErrorS(err, "Failed to get node ip address matching node port addresses, health check port will listen to all node addresses", "nodePortAddresses", nodePortAddresses)
nodeAddresses = sets.NewString() nodeAddresses = sets.New[string]()
nodeAddresses.Insert(utilproxy.IPv4ZeroCIDR) nodeAddresses.Insert(utilproxy.IPv4ZeroCIDR)
} }
// if any of the addresses is zero cidr then we listen // if any of the addresses is zero cidr then we listen
// to old style :<port> // to old style :<port>
for _, addr := range nodeAddresses.List() { for _, addr := range nodeAddresses.UnsortedList() {
if utilproxy.IsZeroCIDR(addr) { if utilproxy.IsZeroCIDR(addr) {
nodeAddresses = sets.NewString("") nodeAddresses = sets.New[string]("")
break break
} }
} }
@ -95,7 +95,7 @@ func NewServiceHealthServer(hostname string, recorder events.EventRecorder, node
type server struct { type server struct {
hostname string hostname string
// node addresses where health check port will listen on // node addresses where health check port will listen on
nodeAddresses sets.String nodeAddresses sets.Set[string]
recorder events.EventRecorder // can be nil recorder events.EventRecorder // can be nil
listener listener listener listener
httpFactory httpServerFactory httpFactory httpServerFactory
@ -169,7 +169,7 @@ func (hcI *hcInstance) listenAndServeAll(hcs *server) error {
var err error var err error
var listener net.Listener var listener net.Listener
addresses := hcs.nodeAddresses.List() addresses := hcs.nodeAddresses.UnsortedList()
hcI.httpServers = make([]httpServer, 0, len(addresses)) hcI.httpServers = make([]httpServer, 0, len(addresses))
// for each of the node addresses start listening and serving // for each of the node addresses start listening and serving

View File

@ -787,7 +787,7 @@ func (proxier *Proxier) syncProxyRules() {
}() }()
tryPartialSync := !proxier.needFullSync && utilfeature.DefaultFeatureGate.Enabled(features.MinimizeIPTablesRestore) tryPartialSync := !proxier.needFullSync && utilfeature.DefaultFeatureGate.Enabled(features.MinimizeIPTablesRestore)
var serviceChanged, endpointsChanged sets.String var serviceChanged, endpointsChanged sets.Set[string]
if tryPartialSync { if tryPartialSync {
serviceChanged = proxier.serviceChanges.PendingChanges() serviceChanged = proxier.serviceChanges.PendingChanges()
endpointsChanged = proxier.endpointsChanges.PendingChanges() endpointsChanged = proxier.endpointsChanges.PendingChanges()
@ -1419,7 +1419,7 @@ func (proxier *Proxier) syncProxyRules() {
for addr := range nodeAddresses { for addr := range nodeAddresses {
if utilproxy.IsZeroCIDR(addr) && isIPv6 == netutils.IsIPv6CIDRString(addr) { if utilproxy.IsZeroCIDR(addr) && isIPv6 == netutils.IsIPv6CIDRString(addr) {
// if any of the addresses is zero cidr of this IP family, non-zero IPs can be excluded. // if any of the addresses is zero cidr of this IP family, non-zero IPs can be excluded.
nodeAddresses = sets.NewString(addr) nodeAddresses = sets.New[string](addr)
break break
} }
} }

View File

@ -608,14 +608,14 @@ func countRules(tableName utiliptables.Table, ruleData string) int {
// returns a sorted array of all of the unique matches of the parenthesized group. // returns a sorted array of all of the unique matches of the parenthesized group.
func findAllMatches(lines []string, pattern string) []string { func findAllMatches(lines []string, pattern string) []string {
regex := regexp.MustCompile(pattern) regex := regexp.MustCompile(pattern)
allMatches := sets.NewString() allMatches := sets.New[string]()
for _, line := range lines { for _, line := range lines {
match := regex.FindStringSubmatch(line) match := regex.FindStringSubmatch(line)
if len(match) == 2 { if len(match) == 2 {
allMatches.Insert(match[1]) allMatches.Insert(match[1])
} }
} }
return allMatches.List() return sets.List(allMatches)
} }
// checkIPTablesRuleJumps checks that every `-j` in the given rules jumps to a chain // checkIPTablesRuleJumps checks that every `-j` in the given rules jumps to a chain
@ -629,7 +629,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
for tableName, lines := range tables { for tableName, lines := range tables {
// Find all of the lines like ":KUBE-SERVICES", indicating chains that // Find all of the lines like ":KUBE-SERVICES", indicating chains that
// iptables-restore would create when loading the data. // iptables-restore would create when loading the data.
createdChains := sets.NewString(findAllMatches(lines, `^:([^ ]*)`)...) createdChains := sets.New[string](findAllMatches(lines, `^:([^ ]*)`)...)
// Find all of the lines like "-X KUBE-SERVICES ..." indicating chains // Find all of the lines like "-X KUBE-SERVICES ..." indicating chains
// that we are deleting because they are no longer used, and remove // that we are deleting because they are no longer used, and remove
// those chains from createdChains. // those chains from createdChains.
@ -637,11 +637,11 @@ func checkIPTablesRuleJumps(ruleData string) error {
// Find all of the lines like "-A KUBE-SERVICES ..." indicating chains // Find all of the lines like "-A KUBE-SERVICES ..." indicating chains
// that we are adding at least one rule to. // that we are adding at least one rule to.
filledChains := sets.NewString(findAllMatches(lines, `-A ([^ ]*)`)...) filledChains := sets.New[string](findAllMatches(lines, `-A ([^ ]*)`)...)
// Find all of the chains that are jumped to by some rule so we can make // Find all of the chains that are jumped to by some rule so we can make
// sure we only jump to valid chains. // sure we only jump to valid chains.
jumpedChains := sets.NewString(findAllMatches(lines, `-j ([^ ]*)`)...) jumpedChains := sets.New[string](findAllMatches(lines, `-j ([^ ]*)`)...)
// Ignore jumps to chains that we expect to exist even if kube-proxy // Ignore jumps to chains that we expect to exist even if kube-proxy
// didn't create them itself. // didn't create them itself.
jumpedChains.Delete("ACCEPT", "REJECT", "DROP", "MARK", "RETURN", "DNAT", "SNAT", "MASQUERADE") jumpedChains.Delete("ACCEPT", "REJECT", "DROP", "MARK", "RETURN", "DNAT", "SNAT", "MASQUERADE")
@ -651,7 +651,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
missingChains := jumpedChains.Difference(createdChains) missingChains := jumpedChains.Difference(createdChains)
missingChains = missingChains.Union(filledChains.Difference(createdChains)) missingChains = missingChains.Union(filledChains.Difference(createdChains))
if len(missingChains) > 0 { if len(missingChains) > 0 {
return fmt.Errorf("some chains in %s are used but were not created: %v", tableName, missingChains.List()) return fmt.Errorf("some chains in %s are used but were not created: %v", tableName, missingChains.UnsortedList())
} }
// Find cases where we have "-A FOO ... -j BAR", but no "-A BAR ...", // Find cases where we have "-A FOO ... -j BAR", but no "-A BAR ...",
@ -661,7 +661,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
emptyChains := jumpedChains.Difference(filledChains) emptyChains := jumpedChains.Difference(filledChains)
emptyChains.Delete(string(kubeNodePortsChain)) emptyChains.Delete(string(kubeNodePortsChain))
if len(emptyChains) > 0 { if len(emptyChains) > 0 {
return fmt.Errorf("some chains in %s are jumped to but have no rules: %v", tableName, emptyChains.List()) return fmt.Errorf("some chains in %s are jumped to but have no rules: %v", tableName, emptyChains.UnsortedList())
} }
// Find cases where we have ":BAR" but no "-A FOO ... -j BAR", meaning // Find cases where we have ":BAR" but no "-A FOO ... -j BAR", meaning
@ -669,7 +669,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
extraChains := createdChains.Difference(jumpedChains) extraChains := createdChains.Difference(jumpedChains)
extraChains.Delete(string(kubeServicesChain), string(kubeExternalServicesChain), string(kubeNodePortsChain), string(kubePostroutingChain), string(kubeForwardChain), string(kubeMarkMasqChain), string(kubeProxyFirewallChain), string(kubeletFirewallChain)) extraChains.Delete(string(kubeServicesChain), string(kubeExternalServicesChain), string(kubeNodePortsChain), string(kubePostroutingChain), string(kubeForwardChain), string(kubeMarkMasqChain), string(kubeProxyFirewallChain), string(kubeletFirewallChain))
if len(extraChains) > 0 { if len(extraChains) > 0 {
return fmt.Errorf("some chains in %s are created but not used: %v", tableName, extraChains.List()) return fmt.Errorf("some chains in %s are created but not used: %v", tableName, extraChains.UnsortedList())
} }
} }

View File

@ -1018,7 +1018,7 @@ func (proxier *Proxier) syncProxyRules() {
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to get node IP address matching nodeport cidr") klog.ErrorS(err, "Failed to get node IP address matching nodeport cidr")
} else { } else {
nodeAddresses = nodeAddrSet.List() nodeAddresses = nodeAddrSet.UnsortedList()
for _, address := range nodeAddresses { for _, address := range nodeAddresses {
a := netutils.ParseIPSloppy(address) a := netutils.ParseIPSloppy(address)
if a.IsLoopback() { if a.IsLoopback() {
@ -1839,7 +1839,7 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
} }
// curEndpoints represents IPVS destinations listed from current system. // curEndpoints represents IPVS destinations listed from current system.
curEndpoints := sets.NewString() curEndpoints := sets.New[string]()
curDests, err := proxier.ipvs.GetRealServers(appliedVirtualServer) curDests, err := proxier.ipvs.GetRealServers(appliedVirtualServer)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to list IPVS destinations") klog.ErrorS(err, "Failed to list IPVS destinations")
@ -1883,13 +1883,13 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
} }
} }
newEndpoints := sets.NewString() newEndpoints := sets.New[string]()
for _, epInfo := range endpoints { for _, epInfo := range endpoints {
newEndpoints.Insert(epInfo.String()) newEndpoints.Insert(epInfo.String())
} }
// Create new endpoints // Create new endpoints
for _, ep := range newEndpoints.List() { for _, ep := range sets.List(newEndpoints) {
ip, port, err := net.SplitHostPort(ep) ip, port, err := net.SplitHostPort(ep)
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep) klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep)

View File

@ -1780,7 +1780,7 @@ func TestExternalIPs(t *testing.T) {
fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol) fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol)
svcIP := "10.20.30.41" svcIP := "10.20.30.41"
svcPort := 80 svcPort := 80
svcExternalIPs := sets.NewString("50.60.70.81", "2012::51", "127.0.0.1") svcExternalIPs := sets.New[string]("50.60.70.81", "2012::51", "127.0.0.1")
svcPortName := proxy.ServicePortName{ svcPortName := proxy.ServicePortName{
NamespacedName: makeNSN("ns1", "svc1"), NamespacedName: makeNSN("ns1", "svc1"),
Port: "p80", Port: "p80",
@ -1851,7 +1851,7 @@ func TestOnlyLocalExternalIPs(t *testing.T) {
fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol) fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol)
svcIP := "10.20.30.41" svcIP := "10.20.30.41"
svcPort := 80 svcPort := 80
svcExternalIPs := sets.NewString("50.60.70.81", "2012::51", "127.0.0.1") svcExternalIPs := sets.New[string]("50.60.70.81", "2012::51", "127.0.0.1")
svcPortName := proxy.ServicePortName{ svcPortName := proxy.ServicePortName{
NamespacedName: makeNSN("ns1", "svc1"), NamespacedName: makeNSN("ns1", "svc1"),
Port: "p80", Port: "p80",
@ -2579,7 +2579,7 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
// the not-deleted service, because one of it's ServicePorts was deleted. // the not-deleted service, because one of it's ServicePorts was deleted.
expectedStaleUDPServices := []string{"172.16.55.10", "172.16.55.4", "172.16.55.11", "172.16.55.12"} expectedStaleUDPServices := []string{"172.16.55.10", "172.16.55.4", "172.16.55.11", "172.16.55.12"}
if len(result.DeletedUDPClusterIPs) != len(expectedStaleUDPServices) { if len(result.DeletedUDPClusterIPs) != len(expectedStaleUDPServices) {
t.Errorf("expected stale UDP services length %d, got %v", len(expectedStaleUDPServices), result.DeletedUDPClusterIPs.List()) t.Errorf("expected stale UDP services length %d, got %v", len(expectedStaleUDPServices), result.DeletedUDPClusterIPs.UnsortedList())
} }
for _, ip := range expectedStaleUDPServices { for _, ip := range expectedStaleUDPServices {
if !result.DeletedUDPClusterIPs.Has(ip) { if !result.DeletedUDPClusterIPs.Has(ip) {
@ -2713,7 +2713,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
t.Errorf("expected service map length 2, got %v", fp.svcPortMap) t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
} }
if len(result.DeletedUDPClusterIPs) != 0 { if len(result.DeletedUDPClusterIPs) != 0 {
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.List()) t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
} }
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts() healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
@ -2729,7 +2729,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
t.Errorf("expected service map length 2, got %v", fp.svcPortMap) t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
} }
if len(result.DeletedUDPClusterIPs) != 0 { if len(result.DeletedUDPClusterIPs) != 0 {
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.List()) t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
} }
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts() healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()

View File

@ -330,11 +330,11 @@ func (sct *ServiceChangeTracker) Update(previous, current *v1.Service) bool {
// PendingChanges returns a set whose keys are the names of the services that have changed // PendingChanges returns a set whose keys are the names of the services that have changed
// since the last time sct was used to update a ServiceMap. (You must call this _before_ // since the last time sct was used to update a ServiceMap. (You must call this _before_
// calling sm.Update(sct).) // calling sm.Update(sct).)
func (sct *ServiceChangeTracker) PendingChanges() sets.String { func (sct *ServiceChangeTracker) PendingChanges() sets.Set[string] {
sct.lock.Lock() sct.lock.Lock()
defer sct.lock.Unlock() defer sct.lock.Unlock()
changes := sets.NewString() changes := sets.New[string]()
for name := range sct.items { for name := range sct.items {
changes.Insert(name.String()) changes.Insert(name.String())
} }
@ -346,12 +346,12 @@ type UpdateServiceMapResult struct {
// DeletedUDPClusterIPs holds stale (no longer assigned to a Service) Service IPs // DeletedUDPClusterIPs holds stale (no longer assigned to a Service) Service IPs
// that had UDP ports. Callers can use this to abort timeout-waits or clear // that had UDP ports. Callers can use this to abort timeout-waits or clear
// connection-tracking information. // connection-tracking information.
DeletedUDPClusterIPs sets.String DeletedUDPClusterIPs sets.Set[string]
} }
// Update updates ServicePortMap base on the given changes. // Update updates ServicePortMap base on the given changes.
func (sm ServicePortMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult) { func (sm ServicePortMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult) {
result.DeletedUDPClusterIPs = sets.NewString() result.DeletedUDPClusterIPs = sets.New[string]()
sm.apply(changes, result.DeletedUDPClusterIPs) sm.apply(changes, result.DeletedUDPClusterIPs)
return result return result
} }
@ -407,7 +407,7 @@ func (sct *ServiceChangeTracker) serviceToServiceMap(service *v1.Service) Servic
// apply the changes to ServicePortMap and update the deleted UDP cluster IP set. // apply the changes to ServicePortMap and update the deleted UDP cluster IP set.
// apply triggers processServiceMapChange on every change. // apply triggers processServiceMapChange on every change.
func (sm *ServicePortMap) apply(changes *ServiceChangeTracker, deletedUDPClusterIPs sets.String) { func (sm *ServicePortMap) apply(changes *ServiceChangeTracker, deletedUDPClusterIPs sets.Set[string]) {
changes.lock.Lock() changes.lock.Lock()
defer changes.lock.Unlock() defer changes.lock.Unlock()
for _, change := range changes.items { for _, change := range changes.items {
@ -446,9 +446,9 @@ func (sm *ServicePortMap) apply(changes *ServiceChangeTracker, deletedUDPCluster
// B{{"ns", "cluster-ip", "http"}: {"172.16.55.10", 1234, "TCP"}} // B{{"ns", "cluster-ip", "http"}: {"172.16.55.10", 1234, "TCP"}}
// A updated to be {{"ns", "cluster-ip", "http"}: {"172.16.55.10", 1234, "TCP"}} // A updated to be {{"ns", "cluster-ip", "http"}: {"172.16.55.10", 1234, "TCP"}}
// produce string set {"ns/cluster-ip:http"} // produce string set {"ns/cluster-ip:http"}
func (sm *ServicePortMap) merge(other ServicePortMap) sets.String { func (sm *ServicePortMap) merge(other ServicePortMap) sets.Set[string] {
// existingPorts is going to store all identifiers of all services in `other` ServicePortMap. // existingPorts is going to store all identifiers of all services in `other` ServicePortMap.
existingPorts := sets.NewString() existingPorts := sets.New[string]()
for svcPortName, info := range other { for svcPortName, info := range other {
// Take ServicePortName.String() as the newly merged service's identifier and put it into existingPorts. // Take ServicePortName.String() as the newly merged service's identifier and put it into existingPorts.
existingPorts.Insert(svcPortName.String()) existingPorts.Insert(svcPortName.String())
@ -475,7 +475,7 @@ func (sm *ServicePortMap) filter(other ServicePortMap) {
// unmerge deletes all other ServicePortMap's elements from current ServicePortMap and // unmerge deletes all other ServicePortMap's elements from current ServicePortMap and
// updates deletedUDPClusterIPs with all of the newly-deleted UDP cluster IPs. // updates deletedUDPClusterIPs with all of the newly-deleted UDP cluster IPs.
func (sm *ServicePortMap) unmerge(other ServicePortMap, deletedUDPClusterIPs sets.String) { func (sm *ServicePortMap) unmerge(other ServicePortMap, deletedUDPClusterIPs sets.Set[string]) {
for svcPortName := range other { for svcPortName := range other {
info, exists := (*sm)[svcPortName] info, exists := (*sm)[svcPortName]
if exists { if exists {

View File

@ -481,8 +481,8 @@ func TestServiceToServiceMap(t *testing.T) {
svcInfo.port != expectedInfo.port || svcInfo.port != expectedInfo.port ||
svcInfo.protocol != expectedInfo.protocol || svcInfo.protocol != expectedInfo.protocol ||
svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort || svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort ||
!sets.NewString(svcInfo.externalIPs...).Equal(sets.NewString(expectedInfo.externalIPs...)) || !sets.New[string](svcInfo.externalIPs...).Equal(sets.New[string](expectedInfo.externalIPs...)) ||
!sets.NewString(svcInfo.loadBalancerSourceRanges...).Equal(sets.NewString(expectedInfo.loadBalancerSourceRanges...)) || !sets.New[string](svcInfo.loadBalancerSourceRanges...).Equal(sets.New[string](expectedInfo.loadBalancerSourceRanges...)) ||
!reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) { !reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) {
t.Errorf("[%s] expected new[%v]to be %v, got %v", tc.desc, svcKey, expectedInfo, *svcInfo) t.Errorf("[%s] expected new[%v]to be %v, got %v", tc.desc, svcKey, expectedInfo, *svcInfo)
} }
@ -492,8 +492,8 @@ func TestServiceToServiceMap(t *testing.T) {
svcInfo.port != expectedInfo.port || svcInfo.port != expectedInfo.port ||
svcInfo.protocol != expectedInfo.protocol || svcInfo.protocol != expectedInfo.protocol ||
svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort || svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort ||
!sets.NewString(svcInfo.externalIPs...).Equal(sets.NewString(expectedInfo.externalIPs...)) || !sets.New[string](svcInfo.externalIPs...).Equal(sets.New[string](expectedInfo.externalIPs...)) ||
!sets.NewString(svcInfo.loadBalancerSourceRanges...).Equal(sets.NewString(expectedInfo.loadBalancerSourceRanges...)) || !sets.New[string](svcInfo.loadBalancerSourceRanges...).Equal(sets.New[string](expectedInfo.loadBalancerSourceRanges...)) ||
!reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) { !reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) {
t.Errorf("expected new[%v]to be %v, got %v", svcKey, expectedInfo, *svcInfo) t.Errorf("expected new[%v]to be %v, got %v", svcKey, expectedInfo, *svcInfo)
} }

View File

@ -28,10 +28,10 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
) )
func checkExpectedEndpoints(expected sets.String, actual []Endpoint) error { func checkExpectedEndpoints(expected sets.Set[string], actual []Endpoint) error {
var errs []error var errs []error
expectedCopy := sets.NewString(expected.UnsortedList()...) expectedCopy := sets.New[string](expected.UnsortedList()...)
for _, ep := range actual { for _, ep := range actual {
if !expectedCopy.Has(ep.String()) { if !expectedCopy.Has(ep.String()) {
errs = append(errs, fmt.Errorf("unexpected endpoint %v", ep)) errs = append(errs, fmt.Errorf("unexpected endpoint %v", ep))
@ -55,14 +55,14 @@ func TestCategorizeEndpoints(t *testing.T) {
endpoints []Endpoint endpoints []Endpoint
// We distinguish `nil` ("service doesn't use this kind of endpoints") from // We distinguish `nil` ("service doesn't use this kind of endpoints") from
// `sets.String()` ("service uses this kind of endpoints but has no endpoints"). // `sets.Set[string]()` ("service uses this kind of endpoints but has no endpoints").
// allEndpoints can be left unset if only one of clusterEndpoints and // allEndpoints can be left unset if only one of clusterEndpoints and
// localEndpoints is set, and allEndpoints is identical to it. // localEndpoints is set, and allEndpoints is identical to it.
// onlyRemoteEndpoints should be true if CategorizeEndpoints returns true for // onlyRemoteEndpoints should be true if CategorizeEndpoints returns true for
// hasAnyEndpoints despite allEndpoints being empty. // hasAnyEndpoints despite allEndpoints being empty.
clusterEndpoints sets.String clusterEndpoints sets.Set[string]
localEndpoints sets.String localEndpoints sets.Set[string]
allEndpoints sets.String allEndpoints sets.Set[string]
onlyRemoteEndpoints bool onlyRemoteEndpoints bool
}{{ }{{
name: "hints enabled, hints annotation == auto", name: "hints enabled, hints annotation == auto",
@ -70,12 +70,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "hints, hints annotation == disabled, hints ignored", name: "hints, hints annotation == disabled, hints ignored",
@ -83,12 +83,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "hints disabled, hints annotation == auto", name: "hints disabled, hints annotation == auto",
@ -96,12 +96,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
@ -110,12 +110,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "aUto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "aUto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "hints, hints annotation empty, hints ignored", name: "hints, hints annotation empty, hints ignored",
@ -123,12 +123,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{}, serviceInfo: &BaseServicePortInfo{},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "externalTrafficPolicy: Local, topology ignored for Local endpoints", name: "externalTrafficPolicy: Local, topology ignored for Local endpoints",
@ -136,37 +136,37 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80"), localEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80"),
allEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"), allEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"),
}, { }, {
name: "internalTrafficPolicy: Local, topology ignored for Local endpoints", name: "internalTrafficPolicy: Local, topology ignored for Local endpoints",
hintsEnabled: true, hintsEnabled: true,
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, hintsAnnotation: "auto", externalPolicyLocal: false, nodePort: 8080}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, hintsAnnotation: "auto", externalPolicyLocal: false, nodePort: 8080},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80"), localEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80"),
allEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"), allEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"),
}, { }, {
name: "empty node labels", name: "empty node labels",
hintsEnabled: true, hintsEnabled: true,
nodeLabels: map[string]string{}, nodeLabels: map[string]string{},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "empty zone label", name: "empty zone label",
@ -174,9 +174,9 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: ""}, nodeLabels: map[string]string{v1.LabelTopologyZone: ""},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "node in different zone, no endpoint filtering", name: "node in different zone, no endpoint filtering",
@ -184,9 +184,9 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-b"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-b"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "normal endpoint filtering, auto annotation", name: "normal endpoint filtering, auto annotation",
@ -194,12 +194,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "unready endpoint", name: "unready endpoint",
@ -207,12 +207,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: false}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: false},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "only unready endpoints in same zone (should not filter)", name: "only unready endpoints in same zone (should not filter)",
@ -220,12 +220,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: false}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: false},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: false}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: false},
}, },
clusterEndpoints: sets.NewString("10.1.2.4:80", "10.1.2.5:80"), clusterEndpoints: sets.New[string]("10.1.2.4:80", "10.1.2.5:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "normal endpoint filtering, Auto annotation", name: "normal endpoint filtering, Auto annotation",
@ -233,12 +233,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "Auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "Auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "hintsAnnotation empty, no filtering applied", name: "hintsAnnotation empty, no filtering applied",
@ -246,12 +246,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: ""}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: ""},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "hintsAnnotation disabled, no filtering applied", name: "hintsAnnotation disabled, no filtering applied",
@ -259,12 +259,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "missing hints, no filtering applied", name: "missing hints, no filtering applied",
@ -272,12 +272,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: nil, Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: nil, Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-a"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.5:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "multiple hints per endpoint, filtering includes any endpoint with zone included", name: "multiple hints per endpoint, filtering includes any endpoint with zone included",
@ -285,12 +285,12 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-c"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-c"},
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a", "zone-b", "zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a", "zone-b", "zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b", "zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.New[string]("zone-b", "zone-c"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-b", "zone-d"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.New[string]("zone-b", "zone-d"), Ready: true},
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-c"), Ready: true}, &BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.New[string]("zone-c"), Ready: true},
}, },
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"), clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "conflicting topology and localness require merging allEndpoints", name: "conflicting topology and localness require merging allEndpoints",
@ -298,20 +298,20 @@ func TestCategorizeEndpoints(t *testing.T) {
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"}, nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"},
endpoints: []Endpoint{ endpoints: []Endpoint{
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", ZoneHints: sets.NewString("zone-a"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", ZoneHints: sets.New[string]("zone-a"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", ZoneHints: sets.NewString("zone-b"), Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", ZoneHints: sets.New[string]("zone-b"), Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.2:80", ZoneHints: sets.NewString("zone-a"), Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.2:80", ZoneHints: sets.New[string]("zone-a"), Ready: true, IsLocal: false},
&BaseEndpointInfo{Endpoint: "10.0.0.3:80", ZoneHints: sets.NewString("zone-b"), Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.3:80", ZoneHints: sets.New[string]("zone-b"), Ready: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.2:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.2:80"),
localEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), localEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80", "10.0.0.2:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80", "10.0.0.2:80"),
}, { }, {
name: "internalTrafficPolicy: Local, with empty endpoints", name: "internalTrafficPolicy: Local, with empty endpoints",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
endpoints: []Endpoint{}, endpoints: []Endpoint{},
clusterEndpoints: nil, clusterEndpoints: nil,
localEndpoints: sets.NewString(), localEndpoints: sets.New[string](),
}, { }, {
name: "internalTrafficPolicy: Local, but all endpoints are remote", name: "internalTrafficPolicy: Local, but all endpoints are remote",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
@ -320,7 +320,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: nil, clusterEndpoints: nil,
localEndpoints: sets.NewString(), localEndpoints: sets.New[string](),
onlyRemoteEndpoints: true, onlyRemoteEndpoints: true,
}, { }, {
name: "internalTrafficPolicy: Local, all endpoints are local", name: "internalTrafficPolicy: Local, all endpoints are local",
@ -330,7 +330,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true},
}, },
clusterEndpoints: nil, clusterEndpoints: nil,
localEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), localEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "internalTrafficPolicy: Local, some endpoints are local", name: "internalTrafficPolicy: Local, some endpoints are local",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
@ -339,7 +339,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: nil, clusterEndpoints: nil,
localEndpoints: sets.NewString("10.0.0.0:80"), localEndpoints: sets.New[string]("10.0.0.0:80"),
}, { }, {
name: "Cluster traffic policy, endpoints not Ready", name: "Cluster traffic policy, endpoints not Ready",
serviceInfo: &BaseServicePortInfo{}, serviceInfo: &BaseServicePortInfo{},
@ -347,7 +347,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false},
}, },
clusterEndpoints: sets.NewString(), clusterEndpoints: sets.New[string](),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "Cluster traffic policy, some endpoints are Ready", name: "Cluster traffic policy, some endpoints are Ready",
@ -356,7 +356,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true},
}, },
clusterEndpoints: sets.NewString("10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.1:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "Cluster traffic policy, all endpoints are terminating", name: "Cluster traffic policy, all endpoints are terminating",
@ -366,7 +366,7 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: nil, localEndpoints: nil,
}, { }, {
name: "iTP: Local, eTP: Cluster, some endpoints local", name: "iTP: Local, eTP: Cluster, some endpoints local",
@ -375,9 +375,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: sets.NewString("10.0.0.0:80"), localEndpoints: sets.New[string]("10.0.0.0:80"),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "iTP: Cluster, eTP: Local, some endpoints local", name: "iTP: Cluster, eTP: Local, some endpoints local",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080},
@ -385,9 +385,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: sets.NewString("10.0.0.0:80"), localEndpoints: sets.New[string]("10.0.0.0:80"),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "iTP: Local, eTP: Local, some endpoints local", name: "iTP: Local, eTP: Local, some endpoints local",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, externalPolicyLocal: true, nodePort: 8080}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, externalPolicyLocal: true, nodePort: 8080},
@ -395,9 +395,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: sets.NewString("10.0.0.0:80"), localEndpoints: sets.New[string]("10.0.0.0:80"),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "iTP: Local, eTP: Local, all endpoints remote", name: "iTP: Local, eTP: Local, all endpoints remote",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, externalPolicyLocal: true, nodePort: 8080}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, externalPolicyLocal: true, nodePort: 8080},
@ -405,9 +405,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: false},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: sets.NewString(), localEndpoints: sets.New[string](),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "iTP: Local, eTP: Local, all endpoints remote and terminating", name: "iTP: Local, eTP: Local, all endpoints remote and terminating",
pteEnabled: true, pteEnabled: true,
@ -416,9 +416,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: sets.NewString(), localEndpoints: sets.New[string](),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
onlyRemoteEndpoints: true, onlyRemoteEndpoints: true,
}, { }, {
name: "iTP: Cluster, eTP: Local, with terminating endpoints", name: "iTP: Cluster, eTP: Local, with terminating endpoints",
@ -430,9 +430,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.2:80", Ready: false, Serving: true, Terminating: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.2:80", Ready: false, Serving: true, Terminating: true, IsLocal: true},
&BaseEndpointInfo{Endpoint: "10.0.0.3:80", Ready: false, Serving: true, Terminating: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.3:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80"),
localEndpoints: sets.NewString("10.0.0.2:80"), localEndpoints: sets.New[string]("10.0.0.2:80"),
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.2:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.2:80"),
}, { }, {
name: "externalTrafficPolicy ignored if not externally accessible", name: "externalTrafficPolicy ignored if not externally accessible",
serviceInfo: &BaseServicePortInfo{externalPolicyLocal: true}, serviceInfo: &BaseServicePortInfo{externalPolicyLocal: true},
@ -440,9 +440,9 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: false}, &BaseEndpointInfo{Endpoint: "10.0.0.0:80", Ready: true, IsLocal: false},
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true},
}, },
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
localEndpoints: nil, localEndpoints: nil,
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
}, { }, {
name: "no cluster endpoints for iTP:Local internal-only service", name: "no cluster endpoints for iTP:Local internal-only service",
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true}, serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
@ -451,8 +451,8 @@ func TestCategorizeEndpoints(t *testing.T) {
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true}, &BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true},
}, },
clusterEndpoints: nil, clusterEndpoints: nil,
localEndpoints: sets.NewString("10.0.0.1:80"), localEndpoints: sets.New[string]("10.0.0.1:80"),
allEndpoints: sets.NewString("10.0.0.1:80"), allEndpoints: sets.New[string]("10.0.0.1:80"),
}} }}
for _, tc := range testCases { for _, tc := range testCases {
@ -479,7 +479,7 @@ func TestCategorizeEndpoints(t *testing.T) {
} }
} }
var expectedAllEndpoints sets.String var expectedAllEndpoints sets.Set[string]
if tc.clusterEndpoints != nil && tc.localEndpoints == nil { if tc.clusterEndpoints != nil && tc.localEndpoints == nil {
expectedAllEndpoints = tc.clusterEndpoints expectedAllEndpoints = tc.clusterEndpoints
} else if tc.localEndpoints != nil && tc.clusterEndpoints == nil { } else if tc.localEndpoints != nil && tc.clusterEndpoints == nil {

View File

@ -126,7 +126,7 @@ type Endpoint interface {
IsTerminating() bool IsTerminating() bool
// GetZoneHints returns the zone hint for the endpoint. This is based on // GetZoneHints returns the zone hint for the endpoint. This is based on
// endpoint.hints.forZones[0].name in the EndpointSlice API. // endpoint.hints.forZones[0].name in the EndpointSlice API.
GetZoneHints() sets.String GetZoneHints() sets.Set[string]
// IP returns IP part of the endpoint. // IP returns IP part of the endpoint.
IP() string IP() string
// Port returns the Port part of the endpoint. // Port returns the Port part of the endpoint.

View File

@ -70,8 +70,8 @@ func (npa *NodePortAddresses) String() string {
// verbatim in the response and no actual IPs of that family will be returned. // verbatim in the response and no actual IPs of that family will be returned.
// If no matching IPs are found, GetNodeAddresses will return an error. // If no matching IPs are found, GetNodeAddresses will return an error.
// NetworkInterfacer is injected for test purpose. // NetworkInterfacer is injected for test purpose.
func (npa *NodePortAddresses) GetNodeAddresses(nw NetworkInterfacer) (sets.String, error) { func (npa *NodePortAddresses) GetNodeAddresses(nw NetworkInterfacer) (sets.Set[string], error) {
uniqueAddressList := sets.NewString() uniqueAddressList := sets.New[string]()
// First round of iteration to pick out `0.0.0.0/0` or `::/0` for the sake of excluding non-zero IPs. // First round of iteration to pick out `0.0.0.0/0` or `::/0` for the sake of excluding non-zero IPs.
for _, cidr := range npa.cidrStrings { for _, cidr := range npa.cidrStrings {

View File

@ -35,7 +35,7 @@ func TestGetNodeAddresses(t *testing.T) {
name string name string
cidrs []string cidrs []string
itfAddrsPairs []InterfaceAddrsPair itfAddrsPairs []InterfaceAddrsPair
expected sets.String expected sets.Set[string]
}{ }{
{ {
name: "IPv4 single", name: "IPv4 single",
@ -50,7 +50,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("100.200.201.1"), Mask: net.CIDRMask(24, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("100.200.201.1"), Mask: net.CIDRMask(24, 32)}},
}, },
}, },
expected: sets.NewString("10.20.30.51"), expected: sets.New[string]("10.20.30.51"),
}, },
{ {
name: "IPv4 zero CIDR", name: "IPv4 zero CIDR",
@ -65,7 +65,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}},
}, },
}, },
expected: sets.NewString("0.0.0.0/0"), expected: sets.New[string]("0.0.0.0/0"),
}, },
{ {
name: "IPv6 multiple", name: "IPv6 multiple",
@ -80,7 +80,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}},
}, },
}, },
expected: sets.NewString("2001:db8::1", "::1"), expected: sets.New[string]("2001:db8::1", "::1"),
}, },
{ {
name: "IPv6 zero CIDR", name: "IPv6 zero CIDR",
@ -95,7 +95,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}},
}, },
}, },
expected: sets.NewString("::/0"), expected: sets.New[string]("::/0"),
}, },
{ {
name: "IPv4 localhost exact", name: "IPv4 localhost exact",
@ -110,7 +110,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}},
}, },
}, },
expected: sets.NewString("127.0.0.1"), expected: sets.New[string]("127.0.0.1"),
}, },
{ {
name: "IPv4 localhost subnet", name: "IPv4 localhost subnet",
@ -121,7 +121,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.1.1"), Mask: net.CIDRMask(8, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.1.1"), Mask: net.CIDRMask(8, 32)}},
}, },
}, },
expected: sets.NewString("127.0.1.1"), expected: sets.New[string]("127.0.1.1"),
}, },
{ {
name: "IPv4 multiple", name: "IPv4 multiple",
@ -136,7 +136,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("100.200.201.1"), Mask: net.CIDRMask(24, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("100.200.201.1"), Mask: net.CIDRMask(24, 32)}},
}, },
}, },
expected: sets.NewString("10.20.30.51", "100.200.201.1"), expected: sets.New[string]("10.20.30.51", "100.200.201.1"),
}, },
{ {
name: "IPv4 multiple, no match", name: "IPv4 multiple, no match",
@ -166,7 +166,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("127.0.0.1"), Mask: net.CIDRMask(8, 32)}},
}, },
}, },
expected: sets.NewString("0.0.0.0/0", "::/0"), expected: sets.New[string]("0.0.0.0/0", "::/0"),
}, },
{ {
name: "empty list, IPv6 addrs", name: "empty list, IPv6 addrs",
@ -181,7 +181,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("::1"), Mask: net.CIDRMask(128, 128)}},
}, },
}, },
expected: sets.NewString("0.0.0.0/0", "::/0"), expected: sets.New[string]("0.0.0.0/0", "::/0"),
}, },
{ {
name: "IPv4 redundant CIDRs", name: "IPv4 redundant CIDRs",
@ -192,7 +192,7 @@ func TestGetNodeAddresses(t *testing.T) {
addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("1.2.3.4"), Mask: net.CIDRMask(30, 32)}}, addrs: []net.Addr{&net.IPNet{IP: netutils.ParseIPSloppy("1.2.3.4"), Mask: net.CIDRMask(30, 32)}},
}, },
}, },
expected: sets.NewString("0.0.0.0/0"), expected: sets.New[string]("0.0.0.0/0"),
}, },
{ {
name: "Dual-stack, redundant IPv4", name: "Dual-stack, redundant IPv4",
@ -213,7 +213,7 @@ func TestGetNodeAddresses(t *testing.T) {
}, },
}, },
}, },
expected: sets.NewString("0.0.0.0/0", "2001:db8::1"), expected: sets.New[string]("0.0.0.0/0", "2001:db8::1"),
}, },
{ {
name: "Dual-stack, redundant IPv6", name: "Dual-stack, redundant IPv6",
@ -234,7 +234,7 @@ func TestGetNodeAddresses(t *testing.T) {
}, },
}, },
}, },
expected: sets.NewString("::/0", "1.2.3.4"), expected: sets.New[string]("::/0", "1.2.3.4"),
}, },
} }

View File

@ -312,8 +312,8 @@ func (info *endpointsInfo) IsTerminating() bool {
} }
// GetZoneHint returns the zone hint for the endpoint. // GetZoneHint returns the zone hint for the endpoint.
func (info *endpointsInfo) GetZoneHints() sets.String { func (info *endpointsInfo) GetZoneHints() sets.Set[string] {
return sets.String{} return sets.Set[string]{}
} }
// IP returns just the IP part of the endpoint, it's a part of proxy.Endpoint interface. // IP returns just the IP part of the endpoint, it's a part of proxy.Endpoint interface.