Skip to content

Commit

Permalink
pkg/proxy: using generic sets
Browse files Browse the repository at this point in the history
pkg/proxy: using generic sets

Signed-off-by: Daman <aroradaman@gmail.com>
  • Loading branch information
aroradaman committed May 5, 2023
1 parent 940101e commit c2c8b8d
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 244 deletions.
8 changes: 4 additions & 4 deletions pkg/proxy/apis/config/validation/validation.go
Expand Up @@ -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),
)
Expand All @@ -190,20 +190,20 @@ 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),
)

if mode == "" || validModes.Has(string(mode)) {
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)}
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/proxy/endpoints.go
Expand Up @@ -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),
)
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand All @@ -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())
}
Expand Down

0 comments on commit c2c8b8d

Please sign in to comment.