Skip to content

Commit 612108b

Browse files
authored
Merge pull request #3457 from xrstf/improve-lint
Improve linting config
2 parents e3b1339 + cc021e2 commit 612108b

File tree

54 files changed

+170
-179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+170
-179
lines changed

.golangci.yaml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ linters:
1414
- durationcheck
1515
- errcheck
1616
- errchkjson
17+
- fatcontext
1718
- gocritic
1819
- godot
1920
- goprintffuncname
2021
- gosec
2122
- govet
2223
- importas
2324
- ineffassign
25+
- intrange
2426
- misspell
2527
- nilerr
2628
- noctx
@@ -41,25 +43,18 @@ linters:
4143
disabled-checks:
4244
- appendAssign
4345
- dupImport # https://github.com/go-critic/go-critic/issues/845
44-
- evalOrder
4546
- ifElseChain
4647
- octalLiteral
47-
- regexpSimplify
48-
- sloppyReassign
49-
- truncateCmp
5048
- typeDefFirst
5149
- unnamedResult
52-
- unnecessaryDefer
5350
- whyNoLint
54-
- wrapperFunc
5551
- unnecessaryBlock
5652
- rangeValCopy
5753
- hugeParam
5854
- commentedOutCode
5955
- emptyStringTest
6056
- singleCaseSwitch
6157
- nestingReduce
62-
- filepathJoin
6358
- tooManyResultsChecker
6459
enabled-tags:
6560
- diagnostic
@@ -83,7 +78,7 @@ linters:
8378
require-specific: true
8479
allow-unused: false
8580
revive:
86-
# make sure error-strings issues actually surface (default confidence is 0.8)
81+
# make sure error-strings issues actually surface (default confidence is 0.8)
8782
confidence: 0.6
8883
rules:
8984
- name: context-keys-type
@@ -121,22 +116,12 @@ linters:
121116
- legacy
122117
- std-error-handling
123118
rules:
124-
- linters:
125-
- unparam
126-
text: always receives
127-
- linters:
128-
- gosec
129-
path: _test\.go
130-
text: 'G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server'
131119
- linters:
132120
- gosec
133121
path: test/e2e/*
134-
- linters:
135-
- goconst
136-
path: (.+)_test\.go
137122
- linters:
138123
- staticcheck
139-
text: QF1008
124+
text: QF1008 # "could remove embedded field" often impedes readability and clarity
140125
paths:
141126
- third_party$
142127
- builtin$

cmd/sharded-test-server/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func startCacheServer(ctx context.Context, logDirPath, workingDir, hostIP string
136136
},
137137
CurrentContext: "cache",
138138
}
139-
if err = clientcmd.WriteToFile(cacheServerKubeConfig, cacheKubeconfigPath); err != nil {
139+
if err := clientcmd.WriteToFile(cacheServerKubeConfig, cacheKubeconfigPath); err != nil {
140140
return nil, "", err
141141
}
142142
}

cmd/sharded-test-server/frontproxy.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ func startFrontProxy(
7979
Path: "/services/",
8080
// TODO: support multiple virtual workspace backend servers
8181
Backend: fmt.Sprintf("https://localhost:%s", vwPort),
82-
BackendServerCA: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
83-
ProxyClientCert: filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.crt"),
84-
ProxyClientKey: filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.key"),
82+
BackendServerCA: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
83+
ProxyClientCert: filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.crt"),
84+
ProxyClientKey: filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.key"),
8585
},
8686
{
8787
Path: "/clusters/",
8888
// TODO: support multiple shard backend servers
8989
Backend: "https://localhost:6444",
90-
BackendServerCA: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
91-
ProxyClientCert: filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.crt"),
92-
ProxyClientKey: filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.key"),
90+
BackendServerCA: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
91+
ProxyClientCert: filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.crt"),
92+
ProxyClientKey: filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.key"),
9393
},
9494
}
9595

@@ -98,13 +98,13 @@ func startFrontProxy(
9898
return fmt.Errorf("error marshaling mappings yaml: %w", err)
9999
}
100100

101-
if err := os.WriteFile(filepath.Join(workDirPath, ".kcp-front-proxy/mapping.yaml"), mappingsYAML, 0644); err != nil {
101+
if err := os.WriteFile(filepath.Join(workDirPath, ".kcp-front-proxy", "mapping.yaml"), mappingsYAML, 0644); err != nil {
102102
return fmt.Errorf("failed to create front-proxy mapping.yaml: %w", err)
103103
}
104104

105105
// write root shard kubeconfig
106106
configLoader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
107-
&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(workDirPath, ".kcp-0/admin.kubeconfig")},
107+
&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(workDirPath, ".kcp-0", "admin.kubeconfig")},
108108
&clientcmd.ConfigOverrides{CurrentContext: "shard-base"},
109109
)
110110
raw, err := configLoader.RawConfig()
@@ -115,31 +115,31 @@ func startFrontProxy(
115115
if err := clientcmdapi.MinifyConfig(&raw); err != nil {
116116
return err
117117
}
118-
if err := clientcmd.WriteToFile(raw, filepath.Join(workDirPath, ".kcp/root.kubeconfig")); err != nil {
118+
if err := clientcmd.WriteToFile(raw, filepath.Join(workDirPath, ".kcp", "root.kubeconfig")); err != nil {
119119
return err
120120
}
121121

122122
// create serving cert
123-
hostnames := sets.New[string]("localhost", hostIP)
123+
hostnames := sets.New("localhost", hostIP)
124124
logger.Info("creating kcp-front-proxy serving cert with hostnames", "hostnames", hostnames)
125125
cert, err := servingCA.MakeServerCert(hostnames, 365)
126126
if err != nil {
127127
return fmt.Errorf("failed to create server cert: %w", err)
128128
}
129-
if err := cert.WriteCertConfigFile(filepath.Join(workDirPath, ".kcp-front-proxy/apiserver.crt"), filepath.Join(workDirPath, ".kcp-front-proxy/apiserver.key")); err != nil {
129+
if err := cert.WriteCertConfigFile(filepath.Join(workDirPath, ".kcp-front-proxy", "apiserver.crt"), filepath.Join(workDirPath, ".kcp-front-proxy", "apiserver.key")); err != nil {
130130
return fmt.Errorf("failed to write server cert: %w", err)
131131
}
132132

133133
// run front-proxy command
134134
commandLine := append(kcptestingserver.Command("kcp-front-proxy", "front-proxy"),
135135
"--bind-address="+hostIP,
136-
fmt.Sprintf("--mapping-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy/mapping.yaml")),
136+
fmt.Sprintf("--mapping-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy", "mapping.yaml")),
137137
fmt.Sprintf("--root-directory=%s", filepath.Join(workDirPath, ".kcp-front-proxy")),
138-
fmt.Sprintf("--root-kubeconfig=%s", filepath.Join(workDirPath, ".kcp/root.kubeconfig")),
139-
fmt.Sprintf("--shards-kubeconfig=%s", filepath.Join(workDirPath, ".kcp-front-proxy/shards.kubeconfig")),
140-
fmt.Sprintf("--client-ca-file=%s", filepath.Join(workDirPath, ".kcp/client-ca.crt")),
141-
fmt.Sprintf("--tls-cert-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy/apiserver.crt")),
142-
fmt.Sprintf("--tls-private-key-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy/apiserver.key")),
138+
fmt.Sprintf("--root-kubeconfig=%s", filepath.Join(workDirPath, ".kcp", "root.kubeconfig")),
139+
fmt.Sprintf("--shards-kubeconfig=%s", filepath.Join(workDirPath, ".kcp-front-proxy", "shards.kubeconfig")),
140+
fmt.Sprintf("--client-ca-file=%s", filepath.Join(workDirPath, ".kcp", "client-ca.crt")),
141+
fmt.Sprintf("--tls-cert-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy", "apiserver.crt")),
142+
fmt.Sprintf("--tls-private-key-file=%s", filepath.Join(workDirPath, ".kcp-front-proxy", "apiserver.key")),
143143
"--secure-port=6443",
144144
"--v=4",
145145
)
@@ -148,7 +148,7 @@ func startFrontProxy(
148148

149149
cmd := exec.CommandContext(ctx, commandLine[0], commandLine[1:]...) //nolint:gosec
150150

151-
logFilePath := filepath.Join(workDirPath, ".kcp-front-proxy/proxy.log")
151+
logFilePath := filepath.Join(workDirPath, ".kcp-front-proxy", "proxy.log")
152152
if logDirPath != "" {
153153
logFilePath = filepath.Join(logDirPath, "kcp-front-proxy.log")
154154
}
@@ -204,7 +204,7 @@ func startFrontProxy(
204204
}
205205

206206
// intentionally load again every iteration because it can change
207-
configLoader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(workDirPath, ".kcp/admin.kubeconfig")},
207+
configLoader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: filepath.Join(workDirPath, ".kcp", "admin.kubeconfig")},
208208
&clientcmd.ConfigOverrides{CurrentContext: "base"},
209209
)
210210
config, err := configLoader.ClientConfig()
@@ -249,7 +249,7 @@ func scrapeMetrics(ctx context.Context, cfg *rest.Config, workDir string) error
249249
if !set || promUrl == "" {
250250
return nil
251251
}
252-
return kcptestingserver.ScrapeMetrics(ctx, cfg, promUrl, workDir, "kcp-front-proxy", filepath.Join(workDir, ".kcp-front-proxy/apiserver.crt"), map[string]string{
252+
return kcptestingserver.ScrapeMetrics(ctx, cfg, promUrl, workDir, "kcp-front-proxy", filepath.Join(workDir, ".kcp-front-proxy", "apiserver.crt"), map[string]string{
253253
"server": "kcp-front-proxy",
254254
})
255255
}
@@ -260,18 +260,18 @@ func writeAdminKubeConfig(hostIP string, workDirPath string) error {
260260
var kubeConfig clientcmdapi.Config
261261
kubeConfig.AuthInfos = map[string]*clientcmdapi.AuthInfo{
262262
"kcp-admin": {
263-
ClientKey: filepath.Join(workDirPath, ".kcp/kcp-admin.key"),
264-
ClientCertificate: filepath.Join(workDirPath, ".kcp/kcp-admin.crt"),
263+
ClientKey: filepath.Join(workDirPath, ".kcp", "kcp-admin.key"),
264+
ClientCertificate: filepath.Join(workDirPath, ".kcp", "kcp-admin.crt"),
265265
},
266266
}
267267
kubeConfig.Clusters = map[string]*clientcmdapi.Cluster{
268268
"root": {
269269
Server: baseHost + "/clusters/root",
270-
CertificateAuthority: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
270+
CertificateAuthority: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
271271
},
272272
"base": {
273273
Server: baseHost,
274-
CertificateAuthority: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
274+
CertificateAuthority: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
275275
},
276276
}
277277
kubeConfig.Contexts = map[string]*clientcmdapi.Context{
@@ -284,20 +284,20 @@ func writeAdminKubeConfig(hostIP string, workDirPath string) error {
284284
return err
285285
}
286286

287-
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp/admin.kubeconfig"))
287+
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp", "admin.kubeconfig"))
288288
}
289289

290290
func writeShardKubeConfig(workDirPath string) error {
291291
var kubeConfig clientcmdapi.Config
292292
kubeConfig.AuthInfos = map[string]*clientcmdapi.AuthInfo{
293293
"shard-admin": {
294-
ClientKey: filepath.Join(workDirPath, ".kcp-front-proxy/shard-admin.key"),
295-
ClientCertificate: filepath.Join(workDirPath, ".kcp-front-proxy/shard-admin.crt"),
294+
ClientKey: filepath.Join(workDirPath, ".kcp-front-proxy", "shard-admin.key"),
295+
ClientCertificate: filepath.Join(workDirPath, ".kcp-front-proxy", "shard-admin.crt"),
296296
},
297297
}
298298
kubeConfig.Clusters = map[string]*clientcmdapi.Cluster{
299299
"base": {
300-
CertificateAuthority: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
300+
CertificateAuthority: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
301301
},
302302
}
303303
kubeConfig.Contexts = map[string]*clientcmdapi.Context{
@@ -309,7 +309,7 @@ func writeShardKubeConfig(workDirPath string) error {
309309
return err
310310
}
311311

312-
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp-front-proxy/shards.kubeconfig"))
312+
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp-front-proxy", "shards.kubeconfig"))
313313
}
314314

315315
func writeLogicalClusterAdminKubeConfig(hostIP, workDirPath string) error {
@@ -321,14 +321,14 @@ func writeLogicalClusterAdminKubeConfig(hostIP, workDirPath string) error {
321321
var kubeConfig clientcmdapi.Config
322322
kubeConfig.AuthInfos = map[string]*clientcmdapi.AuthInfo{
323323
"logical-cluster-admin": {
324-
ClientKey: filepath.Join(workDirPath, ".kcp/logical-cluster-admin.key"),
325-
ClientCertificate: filepath.Join(workDirPath, ".kcp/logical-cluster-admin.crt"),
324+
ClientKey: filepath.Join(workDirPath, ".kcp", "logical-cluster-admin.key"),
325+
ClientCertificate: filepath.Join(workDirPath, ".kcp", "logical-cluster-admin.crt"),
326326
},
327327
}
328328
kubeConfig.Clusters = map[string]*clientcmdapi.Cluster{
329329
"base": {
330330
Server: baseHost,
331-
CertificateAuthority: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
331+
CertificateAuthority: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
332332
},
333333
}
334334
kubeConfig.Contexts = map[string]*clientcmdapi.Context{
@@ -340,7 +340,7 @@ func writeLogicalClusterAdminKubeConfig(hostIP, workDirPath string) error {
340340
return err
341341
}
342342

343-
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp/logical-cluster-admin.kubeconfig"))
343+
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp", "logical-cluster-admin.kubeconfig"))
344344
}
345345

346346
func writeExternalLogicalClusterAdminKubeConfig(hostIP, workDirPath string) error {
@@ -350,14 +350,14 @@ func writeExternalLogicalClusterAdminKubeConfig(hostIP, workDirPath string) erro
350350
var kubeConfig clientcmdapi.Config
351351
kubeConfig.AuthInfos = map[string]*clientcmdapi.AuthInfo{
352352
"external-logical-cluster-admin": {
353-
ClientKey: filepath.Join(workDirPath, ".kcp/external-logical-cluster-admin.key"),
354-
ClientCertificate: filepath.Join(workDirPath, ".kcp/external-logical-cluster-admin.crt"),
353+
ClientKey: filepath.Join(workDirPath, ".kcp", "external-logical-cluster-admin.key"),
354+
ClientCertificate: filepath.Join(workDirPath, ".kcp", "external-logical-cluster-admin.crt"),
355355
},
356356
}
357357
kubeConfig.Clusters = map[string]*clientcmdapi.Cluster{
358358
"base": {
359359
Server: baseHost,
360-
CertificateAuthority: filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
360+
CertificateAuthority: filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
361361
},
362362
}
363363
kubeConfig.Contexts = map[string]*clientcmdapi.Context{
@@ -369,5 +369,5 @@ func writeExternalLogicalClusterAdminKubeConfig(hostIP, workDirPath string) erro
369369
return err
370370
}
371371

372-
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp/external-logical-cluster-admin.kubeconfig"))
372+
return clientcmd.WriteToFile(kubeConfig, filepath.Join(workDirPath, ".kcp", "external-logical-cluster-admin.kubeconfig"))
373373
}

0 commit comments

Comments
 (0)