mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Simple cleanup before refactoring
This commit is contained in:
parent
1c180e0865
commit
d578105a44
@ -150,8 +150,8 @@ type serviceInfo struct {
|
|||||||
|
|
||||||
// internal struct for endpoints information
|
// internal struct for endpoints information
|
||||||
type endpointsInfo struct {
|
type endpointsInfo struct {
|
||||||
ip string
|
endpoint string // TODO: should be an endpointString type
|
||||||
localEndpoint bool
|
isLocal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns a new serviceInfo struct
|
// returns a new serviceInfo struct
|
||||||
@ -546,7 +546,7 @@ func (proxier *Proxier) OnServiceUpdate(allServices []api.Service) {
|
|||||||
func flattenEndpointsInfo(endPoints []*endpointsInfo) []string {
|
func flattenEndpointsInfo(endPoints []*endpointsInfo) []string {
|
||||||
var endpointIPs []string
|
var endpointIPs []string
|
||||||
for _, ep := range endPoints {
|
for _, ep := range endPoints {
|
||||||
endpointIPs = append(endpointIPs, ep.ip)
|
endpointIPs = append(endpointIPs, ep.endpoint)
|
||||||
}
|
}
|
||||||
return endpointIPs
|
return endpointIPs
|
||||||
}
|
}
|
||||||
@ -562,7 +562,7 @@ func flattenEndpointsInfo(endPoints []*endpointsInfo) []string {
|
|||||||
// then output will be
|
// then output will be
|
||||||
//
|
//
|
||||||
// []endpointsInfo{ {"2.2.2.2:80", localEndpointOnly=<bool>} }
|
// []endpointsInfo{ {"2.2.2.2:80", localEndpointOnly=<bool>} }
|
||||||
func (proxier *Proxier) buildEndpointInfoList(endPoints []hostPortInfo, endpointIPs []string) []*endpointsInfo {
|
func buildEndpointInfoList(endPoints []hostPortInfo, endpointIPs []string) []*endpointsInfo {
|
||||||
lookupSet := sets.NewString()
|
lookupSet := sets.NewString()
|
||||||
for _, ip := range endpointIPs {
|
for _, ip := range endpointIPs {
|
||||||
lookupSet.Insert(ip)
|
lookupSet.Insert(ip)
|
||||||
@ -571,7 +571,7 @@ func (proxier *Proxier) buildEndpointInfoList(endPoints []hostPortInfo, endpoint
|
|||||||
for _, hpp := range endPoints {
|
for _, hpp := range endPoints {
|
||||||
key := net.JoinHostPort(hpp.host, strconv.Itoa(hpp.port))
|
key := net.JoinHostPort(hpp.host, strconv.Itoa(hpp.port))
|
||||||
if lookupSet.Has(key) {
|
if lookupSet.Has(key) {
|
||||||
filteredEndpoints = append(filteredEndpoints, &endpointsInfo{ip: key, localEndpoint: hpp.localEndpoint})
|
filteredEndpoints = append(filteredEndpoints, &endpointsInfo{endpoint: key, isLocal: hpp.isLocal})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredEndpoints
|
return filteredEndpoints
|
||||||
@ -609,7 +609,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) {
|
|||||||
hostPortObject := hostPortInfo{
|
hostPortObject := hostPortInfo{
|
||||||
host: addr.IP,
|
host: addr.IP,
|
||||||
port: int(port.Port),
|
port: int(port.Port),
|
||||||
localEndpoint: addr.NodeName != nil && *addr.NodeName == proxier.hostname,
|
isLocal: addr.NodeName != nil && *addr.NodeName == proxier.hostname,
|
||||||
}
|
}
|
||||||
portsToEndpoints[port.Name] = append(portsToEndpoints[port.Name], hostPortObject)
|
portsToEndpoints[port.Name] = append(portsToEndpoints[port.Name], hostPortObject)
|
||||||
}
|
}
|
||||||
@ -631,7 +631,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Once the set operations using the list of ips are complete, build the list of endpoint infos
|
// Once the set operations using the list of ips are complete, build the list of endpoint infos
|
||||||
newEndpointsMap[svcPort] = proxier.buildEndpointInfoList(portsToEndpoints[portname], newEndpoints)
|
newEndpointsMap[svcPort] = buildEndpointInfoList(portsToEndpoints[portname], newEndpoints)
|
||||||
activeEndpoints[svcPort] = true
|
activeEndpoints[svcPort] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -641,7 +641,7 @@ func (proxier *Proxier) OnEndpointsUpdate(allEndpoints []api.Endpoints) {
|
|||||||
glog.V(2).Infof("Removing endpoints for %q", svcPort)
|
glog.V(2).Infof("Removing endpoints for %q", svcPort)
|
||||||
// record endpoints of unactive service to stale connections
|
// record endpoints of unactive service to stale connections
|
||||||
for _, ep := range proxier.endpointsMap[svcPort] {
|
for _, ep := range proxier.endpointsMap[svcPort] {
|
||||||
staleConnections[endpointServicePair{endpoint: ep.ip, servicePortName: svcPort}] = true
|
staleConnections[endpointServicePair{endpoint: ep.endpoint, servicePortName: svcPort}] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -677,7 +677,7 @@ func (proxier *Proxier) updateHealthCheckEntries(name types.NamespacedName, host
|
|||||||
// Use a set instead of a slice to provide deduplication
|
// Use a set instead of a slice to provide deduplication
|
||||||
endpoints := sets.NewString()
|
endpoints := sets.NewString()
|
||||||
for _, portInfo := range hostPorts {
|
for _, portInfo := range hostPorts {
|
||||||
if portInfo.localEndpoint {
|
if portInfo.isLocal {
|
||||||
// kube-proxy health check only needs local endpoints
|
// kube-proxy health check only needs local endpoints
|
||||||
endpoints.Insert(fmt.Sprintf("%s/%s", name.Namespace, name.Name))
|
endpoints.Insert(fmt.Sprintf("%s/%s", name.Namespace, name.Name))
|
||||||
}
|
}
|
||||||
@ -689,7 +689,7 @@ func (proxier *Proxier) updateHealthCheckEntries(name types.NamespacedName, host
|
|||||||
type hostPortInfo struct {
|
type hostPortInfo struct {
|
||||||
host string
|
host string
|
||||||
port int
|
port int
|
||||||
localEndpoint bool
|
isLocal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidEndpoint(hpp *hostPortInfo) bool {
|
func isValidEndpoint(hpp *hostPortInfo) bool {
|
||||||
@ -1194,7 +1194,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
endpointChains := make([]utiliptables.Chain, 0)
|
endpointChains := make([]utiliptables.Chain, 0)
|
||||||
for _, ep := range proxier.endpointsMap[svcName] {
|
for _, ep := range proxier.endpointsMap[svcName] {
|
||||||
endpoints = append(endpoints, ep)
|
endpoints = append(endpoints, ep)
|
||||||
endpointChain := servicePortEndpointChainName(svcName, protocol, ep.ip)
|
endpointChain := servicePortEndpointChainName(svcName, protocol, ep.endpoint)
|
||||||
endpointChains = append(endpointChains, endpointChain)
|
endpointChains = append(endpointChains, endpointChain)
|
||||||
|
|
||||||
// Create the endpoint chain, retaining counters if possible.
|
// Create the endpoint chain, retaining counters if possible.
|
||||||
@ -1244,14 +1244,14 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
}
|
}
|
||||||
// Handle traffic that loops back to the originator with SNAT.
|
// Handle traffic that loops back to the originator with SNAT.
|
||||||
writeLine(natRules, append(args,
|
writeLine(natRules, append(args,
|
||||||
"-s", fmt.Sprintf("%s/32", strings.Split(endpoints[i].ip, ":")[0]),
|
"-s", fmt.Sprintf("%s/32", strings.Split(endpoints[i].endpoint, ":")[0]),
|
||||||
"-j", string(KubeMarkMasqChain))...)
|
"-j", string(KubeMarkMasqChain))...)
|
||||||
// Update client-affinity lists.
|
// Update client-affinity lists.
|
||||||
if svcInfo.sessionAffinityType == api.ServiceAffinityClientIP {
|
if svcInfo.sessionAffinityType == api.ServiceAffinityClientIP {
|
||||||
args = append(args, "-m", "recent", "--name", string(endpointChain), "--set")
|
args = append(args, "-m", "recent", "--name", string(endpointChain), "--set")
|
||||||
}
|
}
|
||||||
// DNAT to final destination.
|
// DNAT to final destination.
|
||||||
args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", endpoints[i].ip)
|
args = append(args, "-m", protocol, "-p", protocol, "-j", "DNAT", "--to-destination", endpoints[i].endpoint)
|
||||||
writeLine(natRules, args...)
|
writeLine(natRules, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1265,7 +1265,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
localEndpoints := make([]*endpointsInfo, 0)
|
localEndpoints := make([]*endpointsInfo, 0)
|
||||||
localEndpointChains := make([]utiliptables.Chain, 0)
|
localEndpointChains := make([]utiliptables.Chain, 0)
|
||||||
for i := range endpointChains {
|
for i := range endpointChains {
|
||||||
if endpoints[i].localEndpoint {
|
if endpoints[i].isLocal {
|
||||||
// These slices parallel each other; must be kept in sync
|
// These slices parallel each other; must be kept in sync
|
||||||
localEndpoints = append(localEndpoints, endpoints[i])
|
localEndpoints = append(localEndpoints, endpoints[i])
|
||||||
localEndpointChains = append(localEndpointChains, endpointChains[i])
|
localEndpointChains = append(localEndpointChains, endpointChains[i])
|
||||||
|
Loading…
Reference in New Issue
Block a user