Don't increment "no local endpoints" metric when there are no remote endpoints

A service having no _local_ endpoints when it does have remote
endpoints is different from a service having no endpoints at all.
This commit is contained in:
Dan Winship
2022-04-06 10:59:05 -04:00
parent 2fd498f620
commit 84ad54f0e5
4 changed files with 32 additions and 21 deletions

View File

@@ -1354,24 +1354,19 @@ func (proxier *Proxier) syncProxyRules() {
if len(localEndpoints) != 0 {
// Write rules jumping from localPolicyChain to localEndpointChains
proxier.writeServiceToEndpointRules(svcNameString, svcInfo, localPolicyChain, localEndpoints, args)
} else {
} else if hasEndpoints {
if svcInfo.InternalPolicyLocal() && utilfeature.DefaultFeatureGate.Enabled(features.ServiceInternalTrafficPolicy) {
serviceNoLocalEndpointsTotalInternal++
}
if svcInfo.ExternalPolicyLocal() {
serviceNoLocalEndpointsTotalExternal++
}
if hasEndpoints {
// Blackhole all traffic since there are no local endpoints
args = append(args[:0],
"-A", string(localPolicyChain),
"-m", "comment", "--comment",
fmt.Sprintf(`"%s has no local endpoints"`, svcNameString),
"-j",
string(KubeMarkDropChain),
)
proxier.natRules.Write(args)
}
// Blackhole all traffic since there are no local endpoints
proxier.natRules.Write(
"-A", string(localPolicyChain),
"-m", "comment", "--comment",
fmt.Sprintf(`"%s has no local endpoints"`, svcNameString),
"-j", string(KubeMarkDropChain))
}
}
}