Drop the IPGetter

This commit is contained in:
Lars Ekman 2023-02-19 15:05:02 +01:00
parent d6fe718e19
commit 547db63bdf

View File

@ -264,8 +264,6 @@ type Proxier struct {
healthzServer healthcheck.ProxierHealthUpdater healthzServer healthcheck.ProxierHealthUpdater
ipvsScheduler string ipvsScheduler string
// Added as a member to the struct to allow injection for testing.
ipGetter IPGetter
// The following buffers are used to reuse memory and avoid allocations // The following buffers are used to reuse memory and avoid allocations
// that are significantly impacting performance. // that are significantly impacting performance.
iptablesData *bytes.Buffer iptablesData *bytes.Buffer
@ -300,18 +298,6 @@ type Proxier struct {
serviceNoLocalEndpointsExternal sets.String serviceNoLocalEndpointsExternal sets.String
} }
// IPGetter helps get node network interface IP and IPs binded to the IPVS dummy interface
type IPGetter interface {
NodeIPs() ([]net.IP, error)
BindedIPs() (sets.String, error)
}
// realIPGetter is a real NodeIP handler, it implements IPGetter.
type realIPGetter struct {
// nl is a handle for revoking netlink interface
nl NetLinkHandle
}
// NodeIPs returns all LOCAL type IP addresses from host which are // NodeIPs returns all LOCAL type IP addresses from host which are
// taken as the Node IPs of NodePort service. Filtered addresses: // taken as the Node IPs of NodePort service. Filtered addresses:
// //
@ -319,15 +305,15 @@ type realIPGetter struct {
// - Addresses of the "other" family (not handled by this proxier instance) // - Addresses of the "other" family (not handled by this proxier instance)
// - Link-local IPv6 addresses // - Link-local IPv6 addresses
// - Addresses on the created dummy device `kube-ipvs0` // - Addresses on the created dummy device `kube-ipvs0`
func (r *realIPGetter) NodeIPs() (ips []net.IP, err error) { func (p *Proxier) ipGetterNodeIPs() (ips []net.IP, err error) {
nodeAddress, err := r.nl.GetAllLocalAddresses() nodeAddress, err := p.netlinkHandle.GetAllLocalAddresses()
if err != nil { if err != nil {
return nil, fmt.Errorf("error listing LOCAL type addresses from host, error: %v", err) return nil, fmt.Errorf("error listing LOCAL type addresses from host, error: %v", err)
} }
// We must exclude the addresses on the IPVS dummy interface // We must exclude the addresses on the IPVS dummy interface
bindedAddress, err := r.BindedIPs() bindedAddress, err := p.netlinkHandle.GetLocalAddresses(defaultDummyDevice)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -341,11 +327,6 @@ func (r *realIPGetter) NodeIPs() (ips []net.IP, err error) {
return ips, nil return ips, nil
} }
// BindedIPs returns all addresses that are binded to the IPVS dummy interface kube-ipvs0
func (r *realIPGetter) BindedIPs() (sets.String, error) {
return r.nl.GetLocalAddresses(defaultDummyDevice)
}
// Proxier implements proxy.Provider // Proxier implements proxy.Provider
var _ proxy.Provider = &Proxier{} var _ proxy.Provider = &Proxier{}
@ -484,7 +465,6 @@ func NewProxier(ipFamily v1.IPFamily,
healthzServer: healthzServer, healthzServer: healthzServer,
ipvs: ipvs, ipvs: ipvs,
ipvsScheduler: scheduler, ipvsScheduler: scheduler,
ipGetter: &realIPGetter{nl: NewNetLinkHandle(ipFamily == v1.IPv6Protocol)},
iptablesData: bytes.NewBuffer(nil), iptablesData: bytes.NewBuffer(nil),
filterChainsData: bytes.NewBuffer(nil), filterChainsData: bytes.NewBuffer(nil),
natChains: utilproxy.LineBuffer{}, natChains: utilproxy.LineBuffer{},
@ -1049,7 +1029,7 @@ func (proxier *Proxier) syncProxyRules() {
// activeBindAddrs represents ip address successfully bind to defaultDummyDevice in this round of sync // activeBindAddrs represents ip address successfully bind to defaultDummyDevice in this round of sync
activeBindAddrs := map[string]bool{} activeBindAddrs := map[string]bool{}
bindedAddresses, err := proxier.ipGetter.BindedIPs() bindedAddresses, err := proxier.netlinkHandle.GetLocalAddresses(defaultDummyDevice)
if err != nil { if err != nil {
klog.ErrorS(err, "Error listing addresses binded to dummy interface") klog.ErrorS(err, "Error listing addresses binded to dummy interface")
} }
@ -1084,7 +1064,7 @@ func (proxier *Proxier) syncProxyRules() {
continue continue
} }
if utilproxy.IsZeroCIDR(address) { if utilproxy.IsZeroCIDR(address) {
nodeIPs, err = proxier.ipGetter.NodeIPs() nodeIPs, err = proxier.ipGetterNodeIPs()
if err != nil { if err != nil {
klog.ErrorS(err, "Failed to list all node IPs from host") klog.ErrorS(err, "Failed to list all node IPs from host")
} }