mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-13 11:25:19 +00:00
Merge pull request #62083 from rramkumar1/ipvs-exclude-cidrs-flag
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Add --ipvs-exclude-cidrs flag to kube-proxy. **What this PR does / why we need it**: Add a flag to kube-proxy called --ipvs-exclude-cidrs. This flag allows a user to specify a list of CIDR ranges that should not be included in the cleanup of IPVS rules. Fixes: #59507 **Release note**: ``` Use --ipvs-exclude-cidrs to specify a list of CIDR's which the IPVS proxier should not touch when cleaning up IPVS rules. ``` /assign @m1093782566
This commit is contained in:
@@ -125,6 +125,7 @@ func NewFakeProxier(ipt utiliptables.Interface, ipvs utilipvs.Interface, ipset u
|
||||
serviceChanges: proxy.NewServiceChangeTracker(newServiceInfo, nil, nil),
|
||||
endpointsMap: make(proxy.EndpointsMap),
|
||||
endpointsChanges: proxy.NewEndpointChangeTracker(testHostname, nil, nil, nil),
|
||||
excludeCIDRs: make([]string, 0),
|
||||
iptables: ipt,
|
||||
ipvs: ipvs,
|
||||
ipset: ipset,
|
||||
@@ -2395,6 +2396,87 @@ func Test_syncService(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_cleanLegacyService(t *testing.T) {
|
||||
// All ipvs services that were processed in the latest sync loop.
|
||||
activeServices := map[string]bool{"ipvs0": true, "ipvs1": true}
|
||||
// All ipvs services in the system.
|
||||
currentServices := map[string]*utilipvs.VirtualServer{
|
||||
// Created by kube-proxy.
|
||||
"ipvs0": {
|
||||
Address: net.ParseIP("1.1.1.1"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 53,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
// Created by kube-proxy.
|
||||
"ipvs1": {
|
||||
Address: net.ParseIP("2.2.2.2"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 54,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
// Created by an external party.
|
||||
"ipvs2": {
|
||||
Address: net.ParseIP("3.3.3.3"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 55,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
// Created by an external party.
|
||||
"ipvs3": {
|
||||
Address: net.ParseIP("4.4.4.4"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 56,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
// Created by an external party.
|
||||
"ipvs4": {
|
||||
Address: net.ParseIP("5.5.5.5"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 57,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
// Created by kube-proxy, but now stale.
|
||||
"ipvs5": {
|
||||
Address: net.ParseIP("6.6.6.6"),
|
||||
Protocol: string(api.ProtocolUDP),
|
||||
Port: 58,
|
||||
Scheduler: "rr",
|
||||
Flags: utilipvs.FlagHashed,
|
||||
},
|
||||
}
|
||||
|
||||
ipt := iptablestest.NewFake()
|
||||
ipvs := ipvstest.NewFake()
|
||||
ipset := ipsettest.NewFake(testIPSetVersion)
|
||||
proxier := NewFakeProxier(ipt, ipvs, ipset, nil)
|
||||
// These CIDRs cover only ipvs2 and ipvs3.
|
||||
proxier.excludeCIDRs = []string{"3.3.3.0/24", "4.4.4.0/24"}
|
||||
for v := range currentServices {
|
||||
proxier.ipvs.AddVirtualServer(currentServices[v])
|
||||
}
|
||||
proxier.cleanLegacyService(activeServices, currentServices)
|
||||
// ipvs4 and ipvs5 should have been cleaned.
|
||||
remainingVirtualServers, _ := proxier.ipvs.GetVirtualServers()
|
||||
if len(remainingVirtualServers) != 4 {
|
||||
t.Errorf("Expected number of remaining IPVS services after cleanup to be %v. Got %v", 4, len(remainingVirtualServers))
|
||||
}
|
||||
for _, vs := range remainingVirtualServers {
|
||||
// Checking that ipvs4 and ipvs5 were removed.
|
||||
if vs.Port == 57 {
|
||||
t.Errorf("Expected ipvs4 to be removed after cleanup. It still remains")
|
||||
}
|
||||
if vs.Port == 58 {
|
||||
t.Errorf("Expected ipvs5 to be removed after cleanup. It still remains")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func buildFakeProxier(nodeIP []net.IP) (*iptablestest.FakeIPTables, *Proxier) {
|
||||
ipt := iptablestest.NewFake()
|
||||
ipvs := ipvstest.NewFake()
|
||||
|
||||
Reference in New Issue
Block a user