Skip to content

Commit d758fc3

Browse files
authored
Merge pull request kubernetes#81886 from praseodym/fix-staticcheck-pkg/proxy
Fix staticcheck failures for pkg/proxy/...
2 parents 5e31799 + a54e5ce commit d758fc3

File tree

11 files changed

+23
-64
lines changed

11 files changed

+23
-64
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ pkg/kubelet/pluginmanager/operationexecutor
1717
pkg/kubelet/pluginmanager/pluginwatcher
1818
pkg/kubelet/remote
1919
pkg/probe/http
20-
pkg/proxy/healthcheck
21-
pkg/proxy/iptables
22-
pkg/proxy/userspace
23-
pkg/proxy/winkernel
24-
pkg/proxy/winuserspace
2520
pkg/registry/autoscaling/horizontalpodautoscaler/storage
2621
pkg/registry/core/namespace/storage
2722
pkg/registry/core/persistentvolumeclaim/storage

pkg/proxy/healthcheck/proxier_health.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ type ProxierHealthServer struct {
5252
clock clock.Clock
5353

5454
addr string
55-
port int32
5655
healthTimeout time.Duration
5756
recorder record.EventRecorder
5857
nodeRef *v1.ObjectReference
@@ -159,5 +158,5 @@ func (h healthzHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
159158
lastUpdated = currentTime
160159

161160
}
162-
fmt.Fprintf(resp, fmt.Sprintf(`{"lastUpdated": %q,"currentTime": %q}`, lastUpdated, currentTime))
161+
fmt.Fprintf(resp, `{"lastUpdated": %q,"currentTime": %q}`, lastUpdated, currentTime)
163162
}

pkg/proxy/healthcheck/service_health.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (h hcHandler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
163163
} else {
164164
resp.WriteHeader(http.StatusOK)
165165
}
166-
fmt.Fprintf(resp, strings.Trim(dedent.Dedent(fmt.Sprintf(`
166+
fmt.Fprint(resp, strings.Trim(dedent.Dedent(fmt.Sprintf(`
167167
{
168168
"service": {
169169
"namespace": %q,

pkg/proxy/iptables/proxier.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,14 @@ func (proxier *Proxier) deleteEndpointConnections(connectionMap []proxy.ServiceE
727727
const endpointChainsNumberThreshold = 1000
728728

729729
// Assumes proxier.mu is held.
730-
func (proxier *Proxier) appendServiceCommentLocked(args []string, svcName string) {
730+
func (proxier *Proxier) appendServiceCommentLocked(args []string, svcName string) []string {
731731
// Not printing these comments, can reduce size of iptables (in case of large
732732
// number of endpoints) even by 40%+. So if total number of endpoint chains
733733
// is large enough, we simply drop those comments.
734734
if proxier.endpointChainsNumber > endpointChainsNumberThreshold {
735-
return
735+
return args
736736
}
737-
args = append(args, "-m", "comment", "--comment", svcName)
737+
return append(args, "-m", "comment", "--comment", svcName)
738738
}
739739

740740
// This is where all of the iptables-save/restore calls happen.
@@ -1266,7 +1266,7 @@ func (proxier *Proxier) syncProxyRules() {
12661266
args = append(args[:0],
12671267
"-A", string(svcChain),
12681268
)
1269-
proxier.appendServiceCommentLocked(args, svcNameString)
1269+
args = proxier.appendServiceCommentLocked(args, svcNameString)
12701270
args = append(args,
12711271
"-m", "recent", "--name", string(endpointChain),
12721272
"--rcheck", "--seconds", strconv.Itoa(svcInfo.StickyMaxAgeSeconds()), "--reap",
@@ -1278,13 +1278,10 @@ func (proxier *Proxier) syncProxyRules() {
12781278

12791279
// Now write loadbalancing & DNAT rules.
12801280
n := len(endpointChains)
1281-
localEndpoints := make([]*endpointsInfo, 0)
12821281
localEndpointChains := make([]utiliptables.Chain, 0)
12831282
for i, endpointChain := range endpointChains {
12841283
// Write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic.
12851284
if svcInfo.OnlyNodeLocalEndpoints() && endpoints[i].IsLocal {
1286-
// These slices parallel each other; must be kept in sync
1287-
localEndpoints = append(localEndpoints, endpoints[i])
12881285
localEndpointChains = append(localEndpointChains, endpointChains[i])
12891286
}
12901287

@@ -1296,7 +1293,7 @@ func (proxier *Proxier) syncProxyRules() {
12961293

12971294
// Balancing rules in the per-service chain.
12981295
args = append(args[:0], "-A", string(svcChain))
1299-
proxier.appendServiceCommentLocked(args, svcNameString)
1296+
args = proxier.appendServiceCommentLocked(args, svcNameString)
13001297
if i < (n - 1) {
13011298
// Each rule is a probabilistic match.
13021299
args = append(args,
@@ -1310,7 +1307,7 @@ func (proxier *Proxier) syncProxyRules() {
13101307

13111308
// Rules in the per-endpoint chain.
13121309
args = append(args[:0], "-A", string(endpointChain))
1313-
proxier.appendServiceCommentLocked(args, svcNameString)
1310+
args = proxier.appendServiceCommentLocked(args, svcNameString)
13141311
// Handle traffic that loops back to the originator with SNAT.
13151312
writeLine(proxier.natRules, append(args,
13161313
"-s", utilproxy.ToCIDR(net.ParseIP(epIP)),

pkg/proxy/iptables/proxier_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,15 +2358,15 @@ COMMIT
23582358
-A KUBE-MARK-MASQ -j MARK --set-xmark
23592359
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m tcp -p tcp -d 172.20.1.1/32 --dport 0 ! -s 10.0.0.0/24 -j KUBE-MARK-MASQ
23602360
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m tcp -p tcp -d 172.20.1.1/32 --dport 0 -j KUBE-SVC-AHZNAGK3SCETOS2T
2361-
-A KUBE-SVC-AHZNAGK3SCETOS2T -m statistic --mode random --probability 0.3333333333 -j KUBE-SEP-PXD6POUVGD2I37UY
2362-
-A KUBE-SEP-PXD6POUVGD2I37UY -s 10.0.1.1/32 -j KUBE-MARK-MASQ
2363-
-A KUBE-SEP-PXD6POUVGD2I37UY -m tcp -p tcp -j DNAT --to-destination 10.0.1.1:80
2364-
-A KUBE-SVC-AHZNAGK3SCETOS2T -m statistic --mode random --probability 0.5000000000 -j KUBE-SEP-SOKZUIT7SCEVIP33
2365-
-A KUBE-SEP-SOKZUIT7SCEVIP33 -s 10.0.1.2/32 -j KUBE-MARK-MASQ
2366-
-A KUBE-SEP-SOKZUIT7SCEVIP33 -m tcp -p tcp -j DNAT --to-destination 10.0.1.2:80
2367-
-A KUBE-SVC-AHZNAGK3SCETOS2T -j KUBE-SEP-WVE3FAB34S7NZGDJ
2368-
-A KUBE-SEP-WVE3FAB34S7NZGDJ -s 10.0.1.3/32 -j KUBE-MARK-MASQ
2369-
-A KUBE-SEP-WVE3FAB34S7NZGDJ -m tcp -p tcp -j DNAT --to-destination 10.0.1.3:80
2361+
-A KUBE-SVC-AHZNAGK3SCETOS2T -m comment --comment ns1/svc1: -m statistic --mode random --probability 0.3333333333 -j KUBE-SEP-PXD6POUVGD2I37UY
2362+
-A KUBE-SEP-PXD6POUVGD2I37UY -m comment --comment ns1/svc1: -s 10.0.1.1/32 -j KUBE-MARK-MASQ
2363+
-A KUBE-SEP-PXD6POUVGD2I37UY -m comment --comment ns1/svc1: -m tcp -p tcp -j DNAT --to-destination 10.0.1.1:80
2364+
-A KUBE-SVC-AHZNAGK3SCETOS2T -m comment --comment ns1/svc1: -m statistic --mode random --probability 0.5000000000 -j KUBE-SEP-SOKZUIT7SCEVIP33
2365+
-A KUBE-SEP-SOKZUIT7SCEVIP33 -m comment --comment ns1/svc1: -s 10.0.1.2/32 -j KUBE-MARK-MASQ
2366+
-A KUBE-SEP-SOKZUIT7SCEVIP33 -m comment --comment ns1/svc1: -m tcp -p tcp -j DNAT --to-destination 10.0.1.2:80
2367+
-A KUBE-SVC-AHZNAGK3SCETOS2T -m comment --comment ns1/svc1: -j KUBE-SEP-WVE3FAB34S7NZGDJ
2368+
-A KUBE-SEP-WVE3FAB34S7NZGDJ -m comment --comment ns1/svc1: -s 10.0.1.3/32 -j KUBE-MARK-MASQ
2369+
-A KUBE-SEP-WVE3FAB34S7NZGDJ -m comment --comment ns1/svc1: -m tcp -p tcp -j DNAT --to-destination 10.0.1.3:80
23702370
-A KUBE-SERVICES -m comment --comment "kubernetes service nodeports; NOTE: this must be the last rule in this chain" -m addrtype --dst-type LOCAL -j KUBE-NODEPORTS
23712371
COMMIT
23722372
`

pkg/proxy/userspace/proxysocket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (udp *udpProxySocket) proxyClient(cliAddr net.Addr, svrConn net.Conn, activ
290290
klog.Errorf("SetDeadline failed: %v", err)
291291
break
292292
}
293-
n, err = udp.WriteTo(buffer[0:n], cliAddr)
293+
_, err = udp.WriteTo(buffer[0:n], cliAddr)
294294
if err != nil {
295295
if !logTimeout(err) {
296296
klog.Errorf("WriteTo failed: %v", err)

pkg/proxy/winkernel/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//pkg/proxy/apis/config:go_default_library",
2222
"//pkg/proxy/config:go_default_library",
2323
"//pkg/proxy/healthcheck:go_default_library",
24+
"//pkg/proxy/metrics:go_default_library",
2425
"//pkg/util/async:go_default_library",
2526
"//staging/src/k8s.io/api/core/v1:go_default_library",
2627
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",

pkg/proxy/winkernel/metrics.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package winkernel
1818

1919
import (
2020
"sync"
21-
"time"
2221

2322
"k8s.io/component-base/metrics"
2423
"k8s.io/component-base/metrics/legacyregistry"
@@ -69,13 +68,3 @@ func RegisterMetrics() {
6968
legacyregistry.MustRegister(SyncProxyRulesLastTimestamp)
7069
})
7170
}
72-
73-
// Gets the time since the specified start in microseconds.
74-
func sinceInMicroseconds(start time.Time) float64 {
75-
return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
76-
}
77-
78-
// Gets the time since the specified start in seconds.
79-
func sinceInSeconds(start time.Time) float64 {
80-
return time.Since(start).Seconds()
81-
}

pkg/proxy/winkernel/proxier.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import (
4747
"k8s.io/kubernetes/pkg/proxy/apis/config"
4848
proxyconfig "k8s.io/kubernetes/pkg/proxy/config"
4949
"k8s.io/kubernetes/pkg/proxy/healthcheck"
50+
"k8s.io/kubernetes/pkg/proxy/metrics"
5051
"k8s.io/kubernetes/pkg/util/async"
5152
)
5253

@@ -1000,8 +1001,8 @@ func (proxier *Proxier) syncProxyRules() {
10001001

10011002
start := time.Now()
10021003
defer func() {
1003-
SyncProxyRulesLatency.Observe(sinceInSeconds(start))
1004-
DeprecatedSyncProxyRulesLatency.Observe(sinceInMicroseconds(start))
1004+
SyncProxyRulesLatency.Observe(metrics.SinceInSeconds(start))
1005+
DeprecatedSyncProxyRulesLatency.Observe(metrics.SinceInMicroseconds(start))
10051006
klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
10061007
}()
10071008
// don't sync rules till we've received services and endpoints

pkg/proxy/winuserspace/proxier.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ type Proxier struct {
9191
serviceMap map[ServicePortPortalName]*serviceInfo
9292
syncPeriod time.Duration
9393
udpIdleTimeout time.Duration
94-
portMapMutex sync.Mutex
95-
portMap map[portMapKey]*portMapValue
9694
numProxyLoops int32 // use atomic ops to access this; mostly for testing
9795
netsh netsh.Interface
9896
hostIP net.IP
@@ -101,26 +99,6 @@ type Proxier struct {
10199
// assert Proxier is a proxy.Provider
102100
var _ proxy.Provider = &Proxier{}
103101

104-
// A key for the portMap. The ip has to be a string because slices can't be map
105-
// keys.
106-
type portMapKey struct {
107-
ip string
108-
port int
109-
protocol v1.Protocol
110-
}
111-
112-
func (k *portMapKey) String() string {
113-
return fmt.Sprintf("%s/%s", net.JoinHostPort(k.ip, strconv.Itoa(k.port)), k.protocol)
114-
}
115-
116-
// A value for the portMap
117-
type portMapValue struct {
118-
owner ServicePortPortalName
119-
socket interface {
120-
Close() error
121-
}
122-
}
123-
124102
var (
125103
// ErrProxyOnLocalhost is returned by NewProxier if the user requests a proxier on
126104
// 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
154132
return &Proxier{
155133
loadBalancer: loadBalancer,
156134
serviceMap: make(map[ServicePortPortalName]*serviceInfo),
157-
portMap: make(map[portMapKey]*portMapValue),
158135
syncPeriod: syncPeriod,
159136
udpIdleTimeout: udpIdleTimeout,
160137
netsh: netsh,

0 commit comments

Comments
 (0)