Skip to content

Commit 97c682e

Browse files
authored
Ignore deletion of unknown IPVS rules (#830)
* add a --excluded-cidrs * ignore deletion of ipvs rules with address in excluded cidrs Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
1 parent 13421da commit 97c682e

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

docs/user-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Usage of kube-router:
5353
--enable-overlay When enable-overlay is set to true, IP-in-IP tunneling is used for pod-to-pod networking across nodes in different subnets. When set to false no tunneling is used and routing infrastructure is expected to route traffic for pod-to-pod networking across nodes in different subnets (default true)
5454
--enable-pod-egress SNAT traffic from Pods to destinations outside the cluster. (default true)
5555
--enable-pprof Enables pprof for debugging performance and memory leak issues.
56+
--excluded-cidrs strings Excluded CIDRs are used to exclude IPVS rules from deletion.
5657
--hairpin-mode Add iptables rules for every Service Endpoint to support hairpin traffic.
5758
--health-port uint16 Health check port, 0 = Disabled (default 20244)
5859
-h, --help Print usage information.

pkg/controllers/proxy/network_services_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ type NetworkServicesController struct {
209209
serviceMap serviceInfoMap
210210
endpointsMap endpointsInfoMap
211211
podCidr string
212+
excludedCidrs []net.IPNet
212213
masqueradeAll bool
213214
globalHairpin bool
214215
ipvsPermitAll bool
@@ -2105,6 +2106,15 @@ func NewNetworkServicesController(clientset kubernetes.Interface,
21052106
nsc.podCidr = cidr
21062107
}
21072108

2109+
nsc.excludedCidrs = make([]net.IPNet, len(config.ExcludedCidrs))
2110+
for i, excludedCidr := range config.ExcludedCidrs {
2111+
_, ipnet, err := net.ParseCIDR(excludedCidr)
2112+
if err != nil {
2113+
return nil, fmt.Errorf("Failed to get excluded CIDR details: %s", err.Error())
2114+
}
2115+
nsc.excludedCidrs[i] = *ipnet
2116+
}
2117+
21082118
node, err := utils.GetNodeObject(clientset, config.HostnameOverride)
21092119
if err != nil {
21102120
return nil, err

pkg/controllers/proxy/service_endpoints_sync.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,20 @@ func (nsc *NetworkServicesController) cleanupStaleIPVSConfig(activeServiceEndpoi
489489
// Only delete the service if it's not there anymore to prevent flapping
490490
// old: if !ok || len(endpoints) == 0 {
491491
if !ok {
492+
excluded := false
493+
for _, excludedCidr := range nsc.excludedCidrs {
494+
if excludedCidr.Contains(ipvsSvc.Address) {
495+
excluded = true
496+
break
497+
}
498+
}
499+
500+
if excluded {
501+
glog.V(1).Infof("Ignoring deletion of an IPVS service %s in an excluded cidr",
502+
ipvsServiceString(ipvsSvc))
503+
continue
504+
}
505+
492506
glog.V(1).Infof("Found a IPVS service %s which is no longer needed so cleaning up",
493507
ipvsServiceString(ipvsSvc))
494508
err := nsc.ln.ipvsDelService(ipvsSvc)

pkg/options/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type KubeRouterConfig struct {
2929
EnableOverlay bool
3030
EnablePodEgress bool
3131
EnablePprof bool
32+
ExcludedCidrs []string
3233
FullMeshMode bool
3334
OverlayType string
3435
GlobalHairpinMode bool
@@ -99,6 +100,8 @@ func (s *KubeRouterConfig) AddFlags(fs *pflag.FlagSet) {
99100
"SNAT all traffic to cluster IP/node port.")
100101
fs.StringVar(&s.ClusterCIDR, "cluster-cidr", s.ClusterCIDR,
101102
"CIDR range of pods in the cluster. It is used to identify traffic originating from and destinated to pods.")
103+
fs.StringSliceVar(&s.ExcludedCidrs, "excluded-cidrs", s.ExcludedCidrs,
104+
"Excluded CIDRs are used to exclude IPVS rules from deletion.")
102105
fs.BoolVar(&s.EnablePodEgress, "enable-pod-egress", true,
103106
"SNAT traffic from Pods to destinations outside the cluster.")
104107
fs.DurationVar(&s.IPTablesSyncPeriod, "iptables-sync-period", s.IPTablesSyncPeriod,

0 commit comments

Comments
 (0)