mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
kube-proxy: iptables proxy should ignore endpoints with condition ready=false
Signed-off-by: Andrew Sy Kim <kim.andrewsy@gmail.com>
This commit is contained in:
parent
1acdfb4e7c
commit
9c096292cc
@ -1020,8 +1020,6 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
|
|
||||||
allEndpoints := proxier.endpointsMap[svcName]
|
allEndpoints := proxier.endpointsMap[svcName]
|
||||||
|
|
||||||
hasEndpoints := len(allEndpoints) > 0
|
|
||||||
|
|
||||||
// Service Topology will not be enabled in the following cases:
|
// Service Topology will not be enabled in the following cases:
|
||||||
// 1. externalTrafficPolicy=Local (mutually exclusive with service topology).
|
// 1. externalTrafficPolicy=Local (mutually exclusive with service topology).
|
||||||
// 2. ServiceTopology is not enabled.
|
// 2. ServiceTopology is not enabled.
|
||||||
@ -1029,9 +1027,18 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
// to get topology information).
|
// to get topology information).
|
||||||
if !svcInfo.OnlyNodeLocalEndpoints() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceTopology) && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceProxying) {
|
if !svcInfo.OnlyNodeLocalEndpoints() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceTopology) && utilfeature.DefaultFeatureGate.Enabled(features.EndpointSliceProxying) {
|
||||||
allEndpoints = proxy.FilterTopologyEndpoint(proxier.nodeLabels, svcInfo.TopologyKeys(), allEndpoints)
|
allEndpoints = proxy.FilterTopologyEndpoint(proxier.nodeLabels, svcInfo.TopologyKeys(), allEndpoints)
|
||||||
hasEndpoints = len(allEndpoints) > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readyEndpoints := make([]proxy.Endpoint, 0, len(allEndpoints))
|
||||||
|
for _, endpoint := range allEndpoints {
|
||||||
|
if !endpoint.IsReady() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
readyEndpoints = append(readyEndpoints, endpoint)
|
||||||
|
}
|
||||||
|
hasEndpoints := len(readyEndpoints) > 0
|
||||||
|
|
||||||
svcChain := svcInfo.servicePortChainName
|
svcChain := svcInfo.servicePortChainName
|
||||||
if hasEndpoints {
|
if hasEndpoints {
|
||||||
// Create the per-service chain, retaining counters if possible.
|
// Create the per-service chain, retaining counters if possible.
|
||||||
@ -1340,7 +1347,7 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
endpoints = endpoints[:0]
|
endpoints = endpoints[:0]
|
||||||
endpointChains = endpointChains[:0]
|
endpointChains = endpointChains[:0]
|
||||||
var endpointChain utiliptables.Chain
|
var endpointChain utiliptables.Chain
|
||||||
for _, ep := range allEndpoints {
|
for _, ep := range readyEndpoints {
|
||||||
epInfo, ok := ep.(*endpointsInfo)
|
epInfo, ok := ep.(*endpointsInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
klog.ErrorS(err, "Failed to cast endpointsInfo", "endpointsInfo", ep.String())
|
klog.ErrorS(err, "Failed to cast endpointsInfo", "endpointsInfo", ep.String())
|
||||||
|
@ -2670,6 +2670,10 @@ COMMIT
|
|||||||
Addresses: []string{"10.0.1.3"},
|
Addresses: []string{"10.0.1.3"},
|
||||||
Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(true)},
|
Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(true)},
|
||||||
Topology: map[string]string{"kubernetes.io/hostname": "node3"},
|
Topology: map[string]string{"kubernetes.io/hostname": "node3"},
|
||||||
|
}, { // not ready endpoints should be ignored
|
||||||
|
Addresses: []string{"10.0.1.4"},
|
||||||
|
Conditions: discovery.EndpointConditions{Ready: utilpointer.BoolPtr(false)},
|
||||||
|
Topology: map[string]string{"kubernetes.io/hostname": "node4"},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user