New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix staticcheck failures for pkg/proxy/... #81886
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -727,14 +727,14 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE | |
const endpointChainsNumberThreshold = 1000 | ||
|
||
// Assumes proxier.mu is held. | ||
func (proxier *Proxier) appendServiceCommentLocked(args []string, svcName string) { | ||
func (proxier *Proxier) appendServiceCommentLocked(args []string, svcName string) []string { | ||
// Not printing these comments, can reduce size of iptables (in case of large | ||
// number of endpoints) even by 40%+. So if total number of endpoint chains | ||
// is large enough, we simply drop those comments. | ||
if proxier.endpointChainsNumber > endpointChainsNumberThreshold { | ||
return | ||
return args | ||
} | ||
args = append(args, "-m", "comment", "--comment", svcName) | ||
return append(args, "-m", "comment", "--comment", svcName) | ||
} | ||
|
||
// This is where all of the iptables-save/restore calls happen. | ||
|
@@ -1266,7 +1266,7 @@ func (proxier *Proxier) syncProxyRules() { | |
args = append(args[:0], | ||
"-A", string(svcChain), | ||
) | ||
proxier.appendServiceCommentLocked(args, svcNameString) | ||
args = proxier.appendServiceCommentLocked(args, svcNameString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change means that the return value of |
||
args = append(args, | ||
"-m", "recent", "--name", string(endpointChain), | ||
"--rcheck", "--seconds", strconv.Itoa(svcInfo.StickyMaxAgeSeconds()), "--reap", | ||
|
@@ -1278,13 +1278,10 @@ func (proxier *Proxier) syncProxyRules() { | |
|
||
// Now write loadbalancing & DNAT rules. | ||
n := len(endpointChains) | ||
localEndpoints := make([]*endpointsInfo, 0) | ||
localEndpointChains := make([]utiliptables.Chain, 0) | ||
for i, endpointChain := range endpointChains { | ||
// Write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic. | ||
if svcInfo.OnlyNodeLocalEndpoints() && endpoints[i].IsLocal { | ||
// These slices parallel each other; must be kept in sync | ||
localEndpoints = append(localEndpoints, endpoints[i]) | ||
localEndpointChains = append(localEndpointChains, endpointChains[i]) | ||
} | ||
|
||
|
@@ -1296,7 +1293,7 @@ func (proxier *Proxier) syncProxyRules() { | |
|
||
// Balancing rules in the per-service chain. | ||
args = append(args[:0], "-A", string(svcChain)) | ||
proxier.appendServiceCommentLocked(args, svcNameString) | ||
args = proxier.appendServiceCommentLocked(args, svcNameString) | ||
if i < (n - 1) { | ||
// Each rule is a probabilistic match. | ||
args = append(args, | ||
|
@@ -1310,7 +1307,7 @@ func (proxier *Proxier) syncProxyRules() { | |
|
||
// Rules in the per-endpoint chain. | ||
args = append(args[:0], "-A", string(endpointChain)) | ||
proxier.appendServiceCommentLocked(args, svcNameString) | ||
args = proxier.appendServiceCommentLocked(args, svcNameString) | ||
// Handle traffic that loops back to the originator with SNAT. | ||
writeLine(proxier.natRules, append(args, | ||
"-s", utilproxy.ToCIDR(net.ParseIP(epIP)), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,7 +290,7 @@ func (udp *udpProxySocket) proxyClient(cliAddr net.Addr, svrConn net.Conn, activ | |
klog.Errorf("SetDeadline failed: %v", err) | ||
break | ||
} | ||
n, err = udp.WriteTo(buffer[0:n], cliAddr) | ||
_, err = udp.WriteTo(buffer[0:n], cliAddr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we ignoring this output? Is the linter complaining that it is not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, from the commit message:
|
||
if err != nil { | ||
if !logTimeout(err) { | ||
klog.Errorf("WriteTo failed: %v", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,8 +91,6 @@ type Proxier struct { | |
serviceMap map[ServicePortPortalName]*serviceInfo | ||
syncPeriod time.Duration | ||
udpIdleTimeout time.Duration | ||
portMapMutex sync.Mutex | ||
portMap map[portMapKey]*portMapValue | ||
numProxyLoops int32 // use atomic ops to access this; mostly for testing | ||
netsh netsh.Interface | ||
hostIP net.IP | ||
|
@@ -101,26 +99,6 @@ type Proxier struct { | |
// assert Proxier is a proxy.Provider | ||
var _ proxy.Provider = &Proxier{} | ||
|
||
// A key for the portMap. The ip has to be a string because slices can't be map | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these pieces removed because they are not used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, from the commit message:
(exact line numbers are different due to rebase / other changes) |
||
// keys. | ||
type portMapKey struct { | ||
ip string | ||
port int | ||
protocol v1.Protocol | ||
} | ||
|
||
func (k *portMapKey) String() string { | ||
return fmt.Sprintf("%s/%s", net.JoinHostPort(k.ip, strconv.Itoa(k.port)), k.protocol) | ||
} | ||
|
||
// A value for the portMap | ||
type portMapValue struct { | ||
owner ServicePortPortalName | ||
socket interface { | ||
Close() error | ||
} | ||
} | ||
|
||
var ( | ||
// ErrProxyOnLocalhost is returned by NewProxier if the user requests a proxier on | ||
// the loopback address. May be checked for by callers of NewProxier to know whether | ||
|
@@ -154,7 +132,6 @@ func createProxier(loadBalancer LoadBalancer, listenIP net.IP, netsh netsh.Inter | |
return &Proxier{ | ||
loadBalancer: loadBalancer, | ||
serviceMap: make(map[ServicePortPortalName]*serviceInfo), | ||
portMap: make(map[portMapKey]*portMapValue), | ||
syncPeriod: syncPeriod, | ||
udpIdleTimeout: udpIdleTimeout, | ||
netsh: netsh, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above suggests that not returning the args was an explicit decision. I'm not sure that re-adding them is the right choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need
return args
here, otherwise on L1187 in this file will replaceargs
by nil - see #81886 (comment).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in #81563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wait for that PR to merge?