mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
proxy/conntrack: interface update
Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
parent
9ec52fc063
commit
ba3940c2e0
@ -75,8 +75,10 @@ func deleteStaleServiceConntrackEntries(ct Interface, ipFamily v1.IPFamily, svcP
|
||||
filters = append(filters, filterForPort(nodePort, v1.ProtocolUDP))
|
||||
}
|
||||
|
||||
if err := ct.ClearEntries(ipFamilyMap[ipFamily], filters...); err != nil {
|
||||
if n, err := ct.ClearEntries(ipFamilyMap[ipFamily], filters...); err != nil {
|
||||
klog.ErrorS(err, "Failed to delete stale service connections")
|
||||
} else {
|
||||
klog.V(4).InfoS("Deleted conntrack stale entries for services", "count", n)
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,8 +105,10 @@ func deleteStaleEndpointConntrackEntries(ct Interface, ipFamily v1.IPFamily, svc
|
||||
}
|
||||
}
|
||||
|
||||
if err := ct.ClearEntries(ipFamilyMap[ipFamily], filters...); err != nil {
|
||||
if n, err := ct.ClearEntries(ipFamilyMap[ipFamily], filters...); err != nil {
|
||||
klog.ErrorS(err, "Failed to delete stale endpoint connections")
|
||||
} else {
|
||||
klog.V(4).InfoS("Deleted conntrack stale entries for endpoints", "count", n)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
type Interface interface {
|
||||
// ClearEntries deletes conntrack entries for connections of the given IP family,
|
||||
// filtered by the given filters.
|
||||
ClearEntries(ipFamily uint8, filters ...netlink.CustomConntrackFilter) error
|
||||
ClearEntries(ipFamily uint8, filters ...netlink.CustomConntrackFilter) (int, error)
|
||||
}
|
||||
|
||||
// netlinkHandler allows consuming real and mockable implementation for testing.
|
||||
@ -56,16 +56,16 @@ func newConntracker(handler netlinkHandler) Interface {
|
||||
|
||||
// ClearEntries deletes conntrack entries for connections of the given IP family,
|
||||
// filtered by the given filters.
|
||||
func (ct *conntracker) ClearEntries(ipFamily uint8, filters ...netlink.CustomConntrackFilter) error {
|
||||
func (ct *conntracker) ClearEntries(ipFamily uint8, filters ...netlink.CustomConntrackFilter) (int, error) {
|
||||
if len(filters) == 0 {
|
||||
klog.V(7).InfoS("no conntrack filters provided")
|
||||
return nil
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
n, err := ct.handler.ConntrackDeleteFilters(netlink.ConntrackTable, netlink.InetFamily(ipFamily), filters...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error deleting conntrack entries, error: %w", err)
|
||||
return 0, fmt.Errorf("error deleting conntrack entries, error: %w", err)
|
||||
}
|
||||
klog.V(4).InfoS("Cleared conntrack entries", "count", n)
|
||||
return nil
|
||||
return int(n), nil
|
||||
}
|
||||
|
@ -91,7 +91,8 @@ func TestConntracker_ClearEntries(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
handler := &fakeHandler{}
|
||||
ct := newConntracker(handler)
|
||||
require.NoError(t, ct.ClearEntries(tc.ipFamily, tc.filters...))
|
||||
_, err := ct.ClearEntries(tc.ipFamily, tc.filters...)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, netlink.ConntrackTableType(netlink.ConntrackTable), handler.tableType)
|
||||
require.Equal(t, netlink.InetFamily(tc.ipFamily), handler.ipFamily)
|
||||
require.Equal(t, len(tc.filters), len(handler.filters))
|
||||
|
@ -54,11 +54,11 @@ func (fake *FakeInterface) Reset() {
|
||||
}
|
||||
|
||||
// ClearEntries is part of Interface
|
||||
func (fake *FakeInterface) ClearEntries(_ uint8, filters ...netlink.CustomConntrackFilter) error {
|
||||
func (fake *FakeInterface) ClearEntries(_ uint8, filters ...netlink.CustomConntrackFilter) (int, error) {
|
||||
for _, anyFilter := range filters {
|
||||
filter := anyFilter.(*conntrackFilter)
|
||||
if filter.protocol != protocolMap[v1.ProtocolUDP] {
|
||||
return fmt.Errorf("FakeInterface currently only supports UDP")
|
||||
return 0, fmt.Errorf("FakeInterface currently only supports UDP")
|
||||
}
|
||||
|
||||
// record IP and Port entries
|
||||
@ -77,7 +77,7 @@ func (fake *FakeInterface) ClearEntries(_ uint8, filters ...netlink.CustomConntr
|
||||
origin := filter.original.dstIP.String()
|
||||
dest := filter.reply.srcIP.String()
|
||||
if previous, exists := fake.ClearedNATs[origin]; exists && previous != dest {
|
||||
return fmt.Errorf("filter for NAT passed with same origin (%s), different destination (%s / %s)", origin, previous, dest)
|
||||
return 0, fmt.Errorf("filter for NAT passed with same origin (%s), different destination (%s / %s)", origin, previous, dest)
|
||||
}
|
||||
fake.ClearedNATs[filter.original.dstIP.String()] = filter.reply.srcIP.String()
|
||||
}
|
||||
@ -86,11 +86,11 @@ func (fake *FakeInterface) ClearEntries(_ uint8, filters ...netlink.CustomConntr
|
||||
dest := filter.reply.srcIP.String()
|
||||
port := int(filter.original.dstPort)
|
||||
if previous, exists := fake.ClearedPortNATs[port]; exists && previous != dest {
|
||||
return fmt.Errorf("filter for PortNAT passed with same port (%d), different destination (%s / %s)", port, previous, dest)
|
||||
return 0, fmt.Errorf("filter for PortNAT passed with same port (%d), different destination (%s / %s)", port, previous, dest)
|
||||
}
|
||||
fake.ClearedPortNATs[port] = dest
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return 0, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user