mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 20:17:41 +00:00
pkg/proxy: using generic sets
pkg/proxy: using generic sets Signed-off-by: Daman <aroradaman@gmail.com>
This commit is contained in:
parent
940101e07e
commit
c2c8b8d178
@ -181,7 +181,7 @@ func validateProxyMode(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) fiel
|
||||
}
|
||||
|
||||
func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
||||
validModes := sets.NewString(
|
||||
validModes := sets.New[string](
|
||||
string(kubeproxyconfig.ProxyModeIPTables),
|
||||
string(kubeproxyconfig.ProxyModeIPVS),
|
||||
)
|
||||
@ -190,12 +190,12 @@ func validateProxyModeLinux(mode kubeproxyconfig.ProxyMode, fldPath *field.Path)
|
||||
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)}
|
||||
}
|
||||
|
||||
func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Path) field.ErrorList {
|
||||
validModes := sets.NewString(
|
||||
validModes := sets.New[string](
|
||||
string(kubeproxyconfig.ProxyModeKernelspace),
|
||||
)
|
||||
|
||||
@ -203,7 +203,7 @@ func validateProxyModeWindows(mode kubeproxyconfig.ProxyMode, fldPath *field.Pat
|
||||
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)}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
utilproxy "k8s.io/kubernetes/pkg/proxy/util"
|
||||
)
|
||||
|
||||
var supportedEndpointSliceAddressTypes = sets.NewString(
|
||||
var supportedEndpointSliceAddressTypes = sets.New[string](
|
||||
string(discovery.AddressTypeIPv4),
|
||||
string(discovery.AddressTypeIPv6),
|
||||
)
|
||||
@ -49,7 +49,7 @@ type BaseEndpointInfo struct {
|
||||
|
||||
// ZoneHints represent the zone hints for the endpoint. This is based on
|
||||
// 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.
|
||||
// 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
|
||||
@ -103,7 +103,7 @@ func (info *BaseEndpointInfo) IsTerminating() bool {
|
||||
}
|
||||
|
||||
// GetZoneHints returns the zone hint for the endpoint.
|
||||
func (info *BaseEndpointInfo) GetZoneHints() sets.String {
|
||||
func (info *BaseEndpointInfo) GetZoneHints() sets.Set[string] {
|
||||
return info.ZoneHints
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ func (info *BaseEndpointInfo) GetZone() string {
|
||||
}
|
||||
|
||||
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{
|
||||
Endpoint: net.JoinHostPort(IP, strconv.Itoa(port)),
|
||||
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
|
||||
// have changed since the last time ect was used to update an EndpointsMap. (You must call
|
||||
// this _before_ calling em.Update(ect).)
|
||||
func (ect *EndpointChangeTracker) PendingChanges() sets.String {
|
||||
func (ect *EndpointChangeTracker) PendingChanges() sets.Set[string] {
|
||||
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.
|
||||
func (em EndpointsMap) getLocalReadyEndpointIPs() map[types.NamespacedName]sets.String {
|
||||
localIPs := make(map[types.NamespacedName]sets.String)
|
||||
func (em EndpointsMap) getLocalReadyEndpointIPs() map[types.NamespacedName]sets.Set[string] {
|
||||
localIPs := make(map[types.NamespacedName]sets.Set[string])
|
||||
for svcPortName, epList := range em {
|
||||
for _, ep := range epList {
|
||||
// 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() {
|
||||
nsn := svcPortName.NamespacedName
|
||||
if localIPs[nsn] == nil {
|
||||
localIPs[nsn] = sets.NewString()
|
||||
localIPs[nsn] = sets.New[string]()
|
||||
}
|
||||
localIPs[nsn].Insert(ep.IP())
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ func (proxier *FakeProxier) deleteEndpointSlice(slice *discovery.EndpointSlice)
|
||||
func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
testCases := []struct {
|
||||
endpointsMap EndpointsMap
|
||||
expected map[types.NamespacedName]sets.String
|
||||
expected map[types.NamespacedName]sets.Set[string]
|
||||
}{{
|
||||
// Case[0]: nothing
|
||||
endpointsMap: EndpointsMap{},
|
||||
expected: map[types.NamespacedName]sets.String{},
|
||||
expected: map[types.NamespacedName]sets.Set[string]{},
|
||||
}, {
|
||||
// Case[1]: unnamed port
|
||||
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},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{},
|
||||
expected: map[types.NamespacedName]sets.Set[string]{},
|
||||
}, {
|
||||
// Case[2]: unnamed port local
|
||||
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},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.1"),
|
||||
expected: map[types.NamespacedName]sets.Set[string]{
|
||||
{Namespace: "ns1", Name: "ep1"}: sets.New[string]("1.1.1.1"),
|
||||
},
|
||||
}, {
|
||||
// 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},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
{Namespace: "ns1", Name: "ep1"}: sets.NewString("1.1.1.2"),
|
||||
expected: map[types.NamespacedName]sets.Set[string]{
|
||||
{Namespace: "ns1", Name: "ep1"}: sets.New[string]("1.1.1.2"),
|
||||
},
|
||||
}, {
|
||||
// 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},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
{Namespace: "ns2", Name: "ep2"}: sets.NewString("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"),
|
||||
expected: map[types.NamespacedName]sets.Set[string]{
|
||||
{Namespace: "ns2", Name: "ep2"}: sets.New[string]("2.2.2.2", "2.2.2.22", "2.2.2.3"),
|
||||
{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.
|
||||
@ -129,9 +129,9 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
&BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true, Ready: true, Serving: true, Terminating: false},
|
||||
},
|
||||
},
|
||||
expected: map[types.NamespacedName]sets.String{
|
||||
{Namespace: "ns2", Name: "ep2"}: sets.NewString("2.2.2.2", "2.2.2.22"),
|
||||
{Namespace: "ns4", Name: "ep4"}: sets.NewString("4.4.4.4", "4.4.4.6"),
|
||||
expected: map[types.NamespacedName]sets.Set[string]{
|
||||
{Namespace: "ns2", Name: "ep2"}: sets.New[string]("2.2.2.2", "2.2.2.22"),
|
||||
{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
|
||||
@ -154,7 +154,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
|
||||
&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 {
|
||||
@ -506,7 +506,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedDeletedUDPEndpoints []ServiceEndpoint
|
||||
expectedNewlyActiveUDPServices map[ServicePortName]bool
|
||||
expectedLocalEndpoints map[types.NamespacedName]int
|
||||
expectedChangedEndpoints sets.String
|
||||
expectedChangedEndpoints sets.Set[string]
|
||||
}{{
|
||||
name: "empty",
|
||||
oldEndpoints: map[ServicePortName][]*BaseEndpointInfo{},
|
||||
@ -514,7 +514,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedDeletedUDPEndpoints: []ServiceEndpoint{},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "no change, unnamed port",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -536,7 +536,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedDeletedUDPEndpoints: []ServiceEndpoint{},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "no change, named port, local",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -560,7 +560,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "no change, multiple slices",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -590,7 +590,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedDeletedUDPEndpoints: []ServiceEndpoint{},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "no change, multiple slices, multiple ports, local",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -628,7 +628,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "no change, multiple services, slices, IPs, and ports",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -699,7 +699,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
makeNSN("ns1", "ep1"): 2,
|
||||
makeNSN("ns2", "ep2"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "add an EndpointSlice",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -721,7 +721,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "remove an EndpointSlice",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -742,7 +742,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
}},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "add an IP and port",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -773,7 +773,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "remove an IP and port",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -809,7 +809,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
}},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "add a slice to an endpoint",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -840,7 +840,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "remove a slice from an endpoint",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -870,7 +870,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
}},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "rename a port",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -897,7 +897,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
makeServicePortName("ns1", "ep1", "p11-2", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "renumber a port",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -922,7 +922,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
}},
|
||||
expectedNewlyActiveUDPServices: map[ServicePortName]bool{},
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/ep1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/ep1"),
|
||||
}, {
|
||||
name: "complex add and remove",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -1012,7 +1012,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
expectedLocalEndpoints: map[types.NamespacedName]int{
|
||||
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",
|
||||
previousEndpoints: []*discovery.EndpointSlice{
|
||||
@ -1032,7 +1032,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): true,
|
||||
},
|
||||
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()
|
||||
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)
|
||||
@ -1273,7 +1273,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
|
||||
paramRemoveSlice bool
|
||||
expectedReturnVal bool
|
||||
expectedCurrentChange map[ServicePortName][]*BaseEndpointInfo
|
||||
expectedChangedEndpoints sets.String
|
||||
expectedChangedEndpoints sets.Set[string]
|
||||
}{
|
||||
// test starting from an empty state
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// test no modification to state - current change should be nil as nothing changes
|
||||
"add the same slice that already exists": {
|
||||
@ -1308,7 +1308,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
|
||||
paramRemoveSlice: false,
|
||||
expectedReturnVal: false,
|
||||
expectedCurrentChange: nil,
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
},
|
||||
// ensure that only valide address types are processed
|
||||
"add an FQDN slice (invalid address type)": {
|
||||
@ -1321,7 +1321,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
|
||||
paramRemoveSlice: false,
|
||||
expectedReturnVal: false,
|
||||
expectedCurrentChange: nil,
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
},
|
||||
// test additions to 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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// test additions to existing state with partially overlapping slices and 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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// test deletions from existing state with partially overlapping slices and ports
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// ensure a removal that has no effect turns into a no-op
|
||||
"remove a slice that doesn't even exist in current state": {
|
||||
@ -1422,7 +1422,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
|
||||
paramRemoveSlice: true,
|
||||
expectedReturnVal: false,
|
||||
expectedCurrentChange: nil,
|
||||
expectedChangedEndpoints: sets.NewString(),
|
||||
expectedChangedEndpoints: sets.New[string](),
|
||||
},
|
||||
// start with all endpoints ready, transition to no endpoints ready
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// start with no endpoints ready, transition to all endpoints ready
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// start with some endpoints ready, transition to more endpoints ready
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
// start with some endpoints ready, transition to some terminating
|
||||
"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},
|
||||
},
|
||||
},
|
||||
expectedChangedEndpoints: sets.NewString("ns1/svc1"),
|
||||
expectedChangedEndpoints: sets.New[string]("ns1/svc1"),
|
||||
},
|
||||
}
|
||||
|
||||
@ -1541,7 +1541,7 @@ func TestEndpointSliceUpdate(t *testing.T) {
|
||||
|
||||
pendingChanges := tc.endpointChangeTracker.PendingChanges()
|
||||
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()
|
||||
|
@ -81,7 +81,7 @@ type endpointInfo struct {
|
||||
Addresses []string
|
||||
NodeName *string
|
||||
Zone *string
|
||||
ZoneHints sets.String
|
||||
ZoneHints sets.Set[string]
|
||||
|
||||
Ready bool
|
||||
Serving bool
|
||||
@ -141,7 +141,7 @@ func newEndpointSliceInfo(endpointSlice *discovery.EndpointSlice, remove bool) *
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.TopologyAwareHints) {
|
||||
if endpoint.Hints != nil && len(endpoint.Hints.ForZones) > 0 {
|
||||
epInfo.ZoneHints = sets.String{}
|
||||
epInfo.ZoneHints = sets.New[string]()
|
||||
for _, zone := range endpoint.Hints.ForZones {
|
||||
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
|
||||
// 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()
|
||||
defer cache.lock.Unlock()
|
||||
|
||||
changes := sets.NewString()
|
||||
changes := sets.New[string]()
|
||||
for serviceNN, esTracker := range cache.trackerByServiceMap {
|
||||
if len(esTracker.pending) > 0 {
|
||||
changes.Insert(serviceNN.String())
|
||||
|
@ -32,12 +32,12 @@ import (
|
||||
)
|
||||
|
||||
type fakeListener struct {
|
||||
openPorts sets.String
|
||||
openPorts sets.Set[string]
|
||||
}
|
||||
|
||||
func newFakeListener() *fakeListener {
|
||||
return &fakeListener{
|
||||
openPorts: sets.String{},
|
||||
openPorts: sets.Set[string]{},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,15 +63,15 @@ func newServiceHealthServer(hostname string, recorder events.EventRecorder, list
|
||||
nodeAddresses, err := nodePortAddresses.GetNodeAddresses(utilproxy.RealNetwork{})
|
||||
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)
|
||||
nodeAddresses = sets.NewString()
|
||||
nodeAddresses = sets.New[string]()
|
||||
nodeAddresses.Insert(utilproxy.IPv4ZeroCIDR)
|
||||
}
|
||||
|
||||
// if any of the addresses is zero cidr then we listen
|
||||
// to old style :<port>
|
||||
for _, addr := range nodeAddresses.List() {
|
||||
for _, addr := range nodeAddresses.UnsortedList() {
|
||||
if utilproxy.IsZeroCIDR(addr) {
|
||||
nodeAddresses = sets.NewString("")
|
||||
nodeAddresses = sets.New[string]("")
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ func NewServiceHealthServer(hostname string, recorder events.EventRecorder, node
|
||||
type server struct {
|
||||
hostname string
|
||||
// node addresses where health check port will listen on
|
||||
nodeAddresses sets.String
|
||||
nodeAddresses sets.Set[string]
|
||||
recorder events.EventRecorder // can be nil
|
||||
listener listener
|
||||
httpFactory httpServerFactory
|
||||
@ -169,7 +169,7 @@ func (hcI *hcInstance) listenAndServeAll(hcs *server) error {
|
||||
var err error
|
||||
var listener net.Listener
|
||||
|
||||
addresses := hcs.nodeAddresses.List()
|
||||
addresses := hcs.nodeAddresses.UnsortedList()
|
||||
hcI.httpServers = make([]httpServer, 0, len(addresses))
|
||||
|
||||
// for each of the node addresses start listening and serving
|
||||
|
@ -787,7 +787,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
}()
|
||||
|
||||
tryPartialSync := !proxier.needFullSync && utilfeature.DefaultFeatureGate.Enabled(features.MinimizeIPTablesRestore)
|
||||
var serviceChanged, endpointsChanged sets.String
|
||||
var serviceChanged, endpointsChanged sets.Set[string]
|
||||
if tryPartialSync {
|
||||
serviceChanged = proxier.serviceChanges.PendingChanges()
|
||||
endpointsChanged = proxier.endpointsChanges.PendingChanges()
|
||||
@ -1419,7 +1419,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
for addr := range nodeAddresses {
|
||||
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.
|
||||
nodeAddresses = sets.NewString(addr)
|
||||
nodeAddresses = sets.New[string](addr)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
func findAllMatches(lines []string, pattern string) []string {
|
||||
regex := regexp.MustCompile(pattern)
|
||||
allMatches := sets.NewString()
|
||||
allMatches := sets.New[string]()
|
||||
for _, line := range lines {
|
||||
match := regex.FindStringSubmatch(line)
|
||||
if len(match) == 2 {
|
||||
allMatches.Insert(match[1])
|
||||
}
|
||||
}
|
||||
return allMatches.List()
|
||||
return sets.List(allMatches)
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// Find all of the lines like ":KUBE-SERVICES", indicating chains that
|
||||
// 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
|
||||
// that we are deleting because they are no longer used, and remove
|
||||
// those chains from createdChains.
|
||||
@ -637,11 +637,11 @@ func checkIPTablesRuleJumps(ruleData string) error {
|
||||
|
||||
// Find all of the lines like "-A KUBE-SERVICES ..." indicating chains
|
||||
// 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
|
||||
// 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
|
||||
// didn't create them itself.
|
||||
jumpedChains.Delete("ACCEPT", "REJECT", "DROP", "MARK", "RETURN", "DNAT", "SNAT", "MASQUERADE")
|
||||
@ -651,7 +651,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
|
||||
missingChains := jumpedChains.Difference(createdChains)
|
||||
missingChains = missingChains.Union(filledChains.Difference(createdChains))
|
||||
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 ...",
|
||||
@ -661,7 +661,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
|
||||
emptyChains := jumpedChains.Difference(filledChains)
|
||||
emptyChains.Delete(string(kubeNodePortsChain))
|
||||
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
|
||||
@ -669,7 +669,7 @@ func checkIPTablesRuleJumps(ruleData string) error {
|
||||
extraChains := createdChains.Difference(jumpedChains)
|
||||
extraChains.Delete(string(kubeServicesChain), string(kubeExternalServicesChain), string(kubeNodePortsChain), string(kubePostroutingChain), string(kubeForwardChain), string(kubeMarkMasqChain), string(kubeProxyFirewallChain), string(kubeletFirewallChain))
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1018,7 +1018,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Failed to get node IP address matching nodeport cidr")
|
||||
} else {
|
||||
nodeAddresses = nodeAddrSet.List()
|
||||
nodeAddresses = nodeAddrSet.UnsortedList()
|
||||
for _, address := range nodeAddresses {
|
||||
a := netutils.ParseIPSloppy(address)
|
||||
if a.IsLoopback() {
|
||||
@ -1839,7 +1839,7 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
|
||||
}
|
||||
|
||||
// curEndpoints represents IPVS destinations listed from current system.
|
||||
curEndpoints := sets.NewString()
|
||||
curEndpoints := sets.New[string]()
|
||||
curDests, err := proxier.ipvs.GetRealServers(appliedVirtualServer)
|
||||
if err != nil {
|
||||
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 {
|
||||
newEndpoints.Insert(epInfo.String())
|
||||
}
|
||||
|
||||
// Create new endpoints
|
||||
for _, ep := range newEndpoints.List() {
|
||||
for _, ep := range sets.List(newEndpoints) {
|
||||
ip, port, err := net.SplitHostPort(ep)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Failed to parse endpoint", "endpoint", ep)
|
||||
|
@ -1780,7 +1780,7 @@ func TestExternalIPs(t *testing.T) {
|
||||
fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol)
|
||||
svcIP := "10.20.30.41"
|
||||
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{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
@ -1851,7 +1851,7 @@ func TestOnlyLocalExternalIPs(t *testing.T) {
|
||||
fp := NewFakeProxier(ipt, ipvs, ipset, nil, nil, v1.IPv4Protocol)
|
||||
svcIP := "10.20.30.41"
|
||||
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{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
@ -2579,7 +2579,7 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
// 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"}
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
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()
|
||||
@ -2729,7 +2729,7 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
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()
|
||||
|
@ -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
|
||||
// since the last time sct was used to update a ServiceMap. (You must call this _before_
|
||||
// calling sm.Update(sct).)
|
||||
func (sct *ServiceChangeTracker) PendingChanges() sets.String {
|
||||
func (sct *ServiceChangeTracker) PendingChanges() sets.Set[string] {
|
||||
sct.lock.Lock()
|
||||
defer sct.lock.Unlock()
|
||||
|
||||
changes := sets.NewString()
|
||||
changes := sets.New[string]()
|
||||
for name := range sct.items {
|
||||
changes.Insert(name.String())
|
||||
}
|
||||
@ -346,12 +346,12 @@ type UpdateServiceMapResult struct {
|
||||
// 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
|
||||
// connection-tracking information.
|
||||
DeletedUDPClusterIPs sets.String
|
||||
DeletedUDPClusterIPs sets.Set[string]
|
||||
}
|
||||
|
||||
// Update updates ServicePortMap base on the given changes.
|
||||
func (sm ServicePortMap) Update(changes *ServiceChangeTracker) (result UpdateServiceMapResult) {
|
||||
result.DeletedUDPClusterIPs = sets.NewString()
|
||||
result.DeletedUDPClusterIPs = sets.New[string]()
|
||||
sm.apply(changes, result.DeletedUDPClusterIPs)
|
||||
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 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()
|
||||
defer changes.lock.Unlock()
|
||||
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"}}
|
||||
// A updated to be {{"ns", "cluster-ip", "http"}: {"172.16.55.10", 1234, "TCP"}}
|
||||
// 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 := sets.NewString()
|
||||
existingPorts := sets.New[string]()
|
||||
for svcPortName, info := range other {
|
||||
// Take ServicePortName.String() as the newly merged service's identifier and put it into existingPorts.
|
||||
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
|
||||
// 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 {
|
||||
info, exists := (*sm)[svcPortName]
|
||||
if exists {
|
||||
|
@ -481,8 +481,8 @@ func TestServiceToServiceMap(t *testing.T) {
|
||||
svcInfo.port != expectedInfo.port ||
|
||||
svcInfo.protocol != expectedInfo.protocol ||
|
||||
svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort ||
|
||||
!sets.NewString(svcInfo.externalIPs...).Equal(sets.NewString(expectedInfo.externalIPs...)) ||
|
||||
!sets.NewString(svcInfo.loadBalancerSourceRanges...).Equal(sets.NewString(expectedInfo.loadBalancerSourceRanges...)) ||
|
||||
!sets.New[string](svcInfo.externalIPs...).Equal(sets.New[string](expectedInfo.externalIPs...)) ||
|
||||
!sets.New[string](svcInfo.loadBalancerSourceRanges...).Equal(sets.New[string](expectedInfo.loadBalancerSourceRanges...)) ||
|
||||
!reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) {
|
||||
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.protocol != expectedInfo.protocol ||
|
||||
svcInfo.healthCheckNodePort != expectedInfo.healthCheckNodePort ||
|
||||
!sets.NewString(svcInfo.externalIPs...).Equal(sets.NewString(expectedInfo.externalIPs...)) ||
|
||||
!sets.NewString(svcInfo.loadBalancerSourceRanges...).Equal(sets.NewString(expectedInfo.loadBalancerSourceRanges...)) ||
|
||||
!sets.New[string](svcInfo.externalIPs...).Equal(sets.New[string](expectedInfo.externalIPs...)) ||
|
||||
!sets.New[string](svcInfo.loadBalancerSourceRanges...).Equal(sets.New[string](expectedInfo.loadBalancerSourceRanges...)) ||
|
||||
!reflect.DeepEqual(svcInfo.loadBalancerStatus, expectedInfo.loadBalancerStatus) {
|
||||
t.Errorf("expected new[%v]to be %v, got %v", svcKey, expectedInfo, *svcInfo)
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ import (
|
||||
"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
|
||||
|
||||
expectedCopy := sets.NewString(expected.UnsortedList()...)
|
||||
expectedCopy := sets.New[string](expected.UnsortedList()...)
|
||||
for _, ep := range actual {
|
||||
if !expectedCopy.Has(ep.String()) {
|
||||
errs = append(errs, fmt.Errorf("unexpected endpoint %v", ep))
|
||||
@ -55,14 +55,14 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
endpoints []Endpoint
|
||||
|
||||
// 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
|
||||
// localEndpoints is set, and allEndpoints is identical to it.
|
||||
// onlyRemoteEndpoints should be true if CategorizeEndpoints returns true for
|
||||
// hasAnyEndpoints despite allEndpoints being empty.
|
||||
clusterEndpoints sets.String
|
||||
localEndpoints sets.String
|
||||
allEndpoints sets.String
|
||||
clusterEndpoints sets.Set[string]
|
||||
localEndpoints sets.Set[string]
|
||||
allEndpoints sets.Set[string]
|
||||
onlyRemoteEndpoints bool
|
||||
}{{
|
||||
name: "hints enabled, hints annotation == auto",
|
||||
@ -70,12 +70,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "hints, hints annotation == disabled, hints ignored",
|
||||
@ -83,12 +83,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "hints disabled, hints annotation == auto",
|
||||
@ -96,12 +96,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
|
||||
@ -110,12 +110,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "aUto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "hints, hints annotation empty, hints ignored",
|
||||
@ -123,12 +123,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
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"},
|
||||
serviceInfo: &BaseServicePortInfo{externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("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.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: 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.New[string]("zone-b"), Ready: true, IsLocal: 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.New[string]("zone-a"), Ready: true},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"),
|
||||
localEndpoints: sets.NewString("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"),
|
||||
clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
|
||||
localEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4: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",
|
||||
hintsEnabled: true,
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true, hintsAnnotation: "auto", externalPolicyLocal: false, nodePort: 8080},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("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.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: 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.New[string]("zone-b"), Ready: true, IsLocal: 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.New[string]("zone-a"), Ready: true},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.1.2.3:80", "10.1.2.6:80"),
|
||||
localEndpoints: sets.NewString("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"),
|
||||
clusterEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.6:80"),
|
||||
localEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80"),
|
||||
allEndpoints: sets.New[string]("10.1.2.3:80", "10.1.2.4:80", "10.1.2.6:80"),
|
||||
}, {
|
||||
name: "empty node labels",
|
||||
hintsEnabled: true,
|
||||
nodeLabels: map[string]string{},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
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,
|
||||
}, {
|
||||
name: "empty zone label",
|
||||
@ -174,9 +174,9 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: ""},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
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,
|
||||
}, {
|
||||
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"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
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,
|
||||
}, {
|
||||
name: "normal endpoint filtering, auto annotation",
|
||||
@ -194,12 +194,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "unready endpoint",
|
||||
@ -207,12 +207,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6:80", ZoneHints: sets.NewString("zone-a"), Ready: false},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.New[string]("zone-a"), 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.New[string]("zone-c"), Ready: true},
|
||||
&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,
|
||||
}, {
|
||||
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"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: false},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "normal endpoint filtering, Auto annotation",
|
||||
@ -233,12 +233,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "Auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "hintsAnnotation empty, no filtering applied",
|
||||
@ -246,12 +246,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: ""},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "hintsAnnotation disabled, no filtering applied",
|
||||
@ -259,12 +259,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "disabled"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.5:80", ZoneHints: sets.NewString("zone-c"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.6: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.New[string]("zone-b"), 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.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,
|
||||
}, {
|
||||
name: "missing hints, no filtering applied",
|
||||
@ -272,12 +272,12 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
nodeLabels: map[string]string{v1.LabelTopologyZone: "zone-a"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.3:80", ZoneHints: sets.NewString("zone-a"), Ready: true},
|
||||
&BaseEndpointInfo{Endpoint: "10.1.2.4:80", ZoneHints: sets.NewString("zone-b"), 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.New[string]("zone-b"), 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,
|
||||
}, {
|
||||
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"},
|
||||
serviceInfo: &BaseServicePortInfo{hintsAnnotation: "auto"},
|
||||
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.4:80", ZoneHints: sets.NewString("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.6:80", ZoneHints: sets.NewString("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.New[string]("zone-b", "zone-c"), 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.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,
|
||||
}, {
|
||||
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"},
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: false, externalPolicyLocal: true, nodePort: 8080, hintsAnnotation: "auto"},
|
||||
endpoints: []Endpoint{
|
||||
&BaseEndpointInfo{Endpoint: "10.0.0.0:80", ZoneHints: sets.NewString("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.2:80", ZoneHints: sets.NewString("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.0:80", ZoneHints: sets.New[string]("zone-a"), 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.New[string]("zone-a"), 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"),
|
||||
localEndpoints: sets.NewString("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"),
|
||||
clusterEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.2:80"),
|
||||
localEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1: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",
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
|
||||
endpoints: []Endpoint{},
|
||||
clusterEndpoints: nil,
|
||||
localEndpoints: sets.NewString(),
|
||||
localEndpoints: sets.New[string](),
|
||||
}, {
|
||||
name: "internalTrafficPolicy: Local, but all endpoints are remote",
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
|
||||
@ -320,7 +320,7 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: nil,
|
||||
localEndpoints: sets.NewString(),
|
||||
localEndpoints: sets.New[string](),
|
||||
onlyRemoteEndpoints: true,
|
||||
}, {
|
||||
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},
|
||||
},
|
||||
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",
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
|
||||
@ -339,7 +339,7 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
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",
|
||||
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.1:80", Ready: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString(),
|
||||
clusterEndpoints: sets.New[string](),
|
||||
localEndpoints: nil,
|
||||
}, {
|
||||
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.1:80", Ready: true},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.1:80"),
|
||||
clusterEndpoints: sets.New[string]("10.0.0.1:80"),
|
||||
localEndpoints: nil,
|
||||
}, {
|
||||
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.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,
|
||||
}, {
|
||||
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.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"),
|
||||
localEndpoints: sets.NewString("10.0.0.0:80"),
|
||||
allEndpoints: 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.New[string]("10.0.0.0:80"),
|
||||
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
|
||||
}, {
|
||||
name: "iTP: Cluster, eTP: Local, some endpoints local",
|
||||
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.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"),
|
||||
localEndpoints: sets.NewString("10.0.0.0:80"),
|
||||
allEndpoints: 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.New[string]("10.0.0.0:80"),
|
||||
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
|
||||
}, {
|
||||
name: "iTP: Local, eTP: Local, some endpoints local",
|
||||
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.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"),
|
||||
localEndpoints: sets.NewString("10.0.0.0:80"),
|
||||
allEndpoints: 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.New[string]("10.0.0.0:80"),
|
||||
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
|
||||
}, {
|
||||
name: "iTP: Local, eTP: Local, all endpoints remote",
|
||||
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.1:80", Ready: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"),
|
||||
localEndpoints: sets.NewString(),
|
||||
allEndpoints: 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.New[string](),
|
||||
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
|
||||
}, {
|
||||
name: "iTP: Local, eTP: Local, all endpoints remote and terminating",
|
||||
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.1:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.1:80"),
|
||||
localEndpoints: sets.NewString(),
|
||||
allEndpoints: 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.New[string](),
|
||||
allEndpoints: sets.New[string]("10.0.0.0:80", "10.0.0.1:80"),
|
||||
onlyRemoteEndpoints: true,
|
||||
}, {
|
||||
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.3:80", Ready: false, Serving: true, Terminating: true, IsLocal: false},
|
||||
},
|
||||
clusterEndpoints: sets.NewString("10.0.0.0:80"),
|
||||
localEndpoints: sets.NewString("10.0.0.2:80"),
|
||||
allEndpoints: sets.NewString("10.0.0.0:80", "10.0.0.2:80"),
|
||||
clusterEndpoints: sets.New[string]("10.0.0.0:80"),
|
||||
localEndpoints: sets.New[string]("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",
|
||||
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.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,
|
||||
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",
|
||||
serviceInfo: &BaseServicePortInfo{internalPolicyLocal: true},
|
||||
@ -451,8 +451,8 @@ func TestCategorizeEndpoints(t *testing.T) {
|
||||
&BaseEndpointInfo{Endpoint: "10.0.0.1:80", Ready: true, IsLocal: true},
|
||||
},
|
||||
clusterEndpoints: nil,
|
||||
localEndpoints: sets.NewString("10.0.0.1:80"),
|
||||
allEndpoints: sets.NewString("10.0.0.1:80"),
|
||||
localEndpoints: sets.New[string]("10.0.0.1:80"),
|
||||
allEndpoints: sets.New[string]("10.0.0.1:80"),
|
||||
}}
|
||||
|
||||
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 {
|
||||
expectedAllEndpoints = tc.clusterEndpoints
|
||||
} else if tc.localEndpoints != nil && tc.clusterEndpoints == nil {
|
||||
|
@ -126,7 +126,7 @@ type Endpoint interface {
|
||||
IsTerminating() bool
|
||||
// GetZoneHints returns the zone hint for the endpoint. This is based on
|
||||
// endpoint.hints.forZones[0].name in the EndpointSlice API.
|
||||
GetZoneHints() sets.String
|
||||
GetZoneHints() sets.Set[string]
|
||||
// IP returns IP part of the endpoint.
|
||||
IP() string
|
||||
// Port returns the Port part of the endpoint.
|
||||
|
@ -70,8 +70,8 @@ func (npa *NodePortAddresses) String() string {
|
||||
// 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.
|
||||
// NetworkInterfacer is injected for test purpose.
|
||||
func (npa *NodePortAddresses) GetNodeAddresses(nw NetworkInterfacer) (sets.String, error) {
|
||||
uniqueAddressList := sets.NewString()
|
||||
func (npa *NodePortAddresses) GetNodeAddresses(nw NetworkInterfacer) (sets.Set[string], error) {
|
||||
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.
|
||||
for _, cidr := range npa.cidrStrings {
|
||||
|
@ -35,7 +35,7 @@ func TestGetNodeAddresses(t *testing.T) {
|
||||
name string
|
||||
cidrs []string
|
||||
itfAddrsPairs []InterfaceAddrsPair
|
||||
expected sets.String
|
||||
expected sets.Set[string]
|
||||
}{
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("10.20.30.51"),
|
||||
expected: sets.New[string]("10.20.30.51"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("0.0.0.0/0"),
|
||||
expected: sets.New[string]("0.0.0.0/0"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("2001:db8::1", "::1"),
|
||||
expected: sets.New[string]("2001:db8::1", "::1"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("::/0"),
|
||||
expected: sets.New[string]("::/0"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("127.0.0.1"),
|
||||
expected: sets.New[string]("127.0.0.1"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("127.0.1.1"),
|
||||
expected: sets.New[string]("127.0.1.1"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
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",
|
||||
@ -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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("0.0.0.0/0", "::/0"),
|
||||
expected: sets.New[string]("0.0.0.0/0", "::/0"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("0.0.0.0/0", "::/0"),
|
||||
expected: sets.New[string]("0.0.0.0/0", "::/0"),
|
||||
},
|
||||
{
|
||||
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)}},
|
||||
},
|
||||
},
|
||||
expected: sets.NewString("0.0.0.0/0"),
|
||||
expected: sets.New[string]("0.0.0.0/0"),
|
||||
},
|
||||
{
|
||||
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",
|
||||
@ -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"),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -312,8 +312,8 @@ func (info *endpointsInfo) IsTerminating() bool {
|
||||
}
|
||||
|
||||
// GetZoneHint returns the zone hint for the endpoint.
|
||||
func (info *endpointsInfo) GetZoneHints() sets.String {
|
||||
return sets.String{}
|
||||
func (info *endpointsInfo) GetZoneHints() sets.Set[string] {
|
||||
return sets.Set[string]{}
|
||||
}
|
||||
|
||||
// IP returns just the IP part of the endpoint, it's a part of proxy.Endpoint interface.
|
||||
|
Loading…
Reference in New Issue
Block a user