Skip to content

Commit 61ec469

Browse files
committed
enable filepathJoin
On-behalf-of: @SAP [email protected]
1 parent 87557dd commit 61ec469

File tree

9 files changed

+105
-108
lines changed

9 files changed

+105
-108
lines changed

.golangci.yaml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,20 @@ linters:
4141
settings:
4242
gocritic:
4343
disabled-checks:
44-
- appendAssign
44+
# - appendAssign
4545
- dupImport # https://github.com/go-critic/go-critic/issues/845
46-
- evalOrder
4746
- ifElseChain
4847
- octalLiteral
49-
- regexpSimplify
50-
- sloppyReassign
51-
- truncateCmp
5248
- typeDefFirst
5349
- unnamedResult
54-
- unnecessaryDefer
5550
- whyNoLint
56-
- wrapperFunc
57-
- unnecessaryBlock
51+
# - unnecessaryBlock
5852
- rangeValCopy
5953
- hugeParam
6054
- commentedOutCode
6155
- emptyStringTest
6256
- singleCaseSwitch
63-
- nestingReduce
64-
- filepathJoin
57+
# - nestingReduce
6558
- tooManyResultsChecker
6659
enabled-tags:
6760
- diagnostic

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
}

cmd/sharded-test-server/main.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
8080

8181
// create request header CA and client cert for front-proxy to connect to shards
8282
requestHeaderCA, _, err := crypto.EnsureCA(
83-
filepath.Join(workDirPath, ".kcp/requestheader-ca.crt"),
84-
filepath.Join(workDirPath, ".kcp/requestheader-ca.key"),
85-
filepath.Join(workDirPath, ".kcp/requestheader-ca-serial.txt"),
83+
filepath.Join(workDirPath, ".kcp", "requestheader-ca.crt"),
84+
filepath.Join(workDirPath, ".kcp", "requestheader-ca.key"),
85+
filepath.Join(workDirPath, ".kcp", "requestheader-ca-serial.txt"),
8686
"kcp-front-proxy-requestheader-ca",
8787
365,
8888
)
8989
if err != nil {
9090
return fmt.Errorf("failed to create requestheader-ca: %w", err)
9191
}
9292
_, _, err = requestHeaderCA.EnsureClientCertificate(
93-
filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.crt"),
94-
filepath.Join(workDirPath, ".kcp-front-proxy/requestheader.key"),
93+
filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.crt"),
94+
filepath.Join(workDirPath, ".kcp-front-proxy", "requestheader.key"),
9595
&kuser.DefaultInfo{Name: "kcp-front-proxy"},
9696
365,
9797
)
@@ -101,18 +101,18 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
101101

102102
// create client CA and kcp-admin client cert to connect through front-proxy
103103
clientCA, _, err := crypto.EnsureCA(
104-
filepath.Join(workDirPath, ".kcp/client-ca.crt"),
105-
filepath.Join(workDirPath, ".kcp/client-ca.key"),
106-
filepath.Join(workDirPath, ".kcp/client-ca-serial.txt"),
104+
filepath.Join(workDirPath, ".kcp", "client-ca.crt"),
105+
filepath.Join(workDirPath, ".kcp", "client-ca.key"),
106+
filepath.Join(workDirPath, ".kcp", "client-ca-serial.txt"),
107107
"kcp-client-ca",
108108
365,
109109
)
110110
if err != nil {
111111
return fmt.Errorf("failed to create client-ca: %w", err)
112112
}
113113
_, _, err = clientCA.EnsureClientCertificate(
114-
filepath.Join(workDirPath, ".kcp/kcp-admin.crt"),
115-
filepath.Join(workDirPath, ".kcp/kcp-admin.key"),
114+
filepath.Join(workDirPath, ".kcp", "kcp-admin.crt"),
115+
filepath.Join(workDirPath, ".kcp", "kcp-admin.key"),
116116
&kuser.DefaultInfo{
117117
Name: "kcp-admin",
118118
Groups: []string{bootstrap.SystemKcpAdminGroup},
@@ -125,8 +125,8 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
125125

126126
// client cert for logical-cluster-admin
127127
_, _, err = clientCA.EnsureClientCertificate(
128-
filepath.Join(workDirPath, ".kcp/logical-cluster-admin.crt"),
129-
filepath.Join(workDirPath, ".kcp/logical-cluster-admin.key"),
128+
filepath.Join(workDirPath, ".kcp", "logical-cluster-admin.crt"),
129+
filepath.Join(workDirPath, ".kcp", "logical-cluster-admin.key"),
130130
&kuser.DefaultInfo{
131131
Name: "logical-cluster-admin",
132132
Groups: []string{bootstrap.SystemLogicalClusterAdmin},
@@ -139,8 +139,8 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
139139

140140
// client cert for external-logical-cluster-admin
141141
_, _, err = clientCA.EnsureClientCertificate(
142-
filepath.Join(workDirPath, ".kcp/external-logical-cluster-admin.crt"),
143-
filepath.Join(workDirPath, ".kcp/external-logical-cluster-admin.key"),
142+
filepath.Join(workDirPath, ".kcp", "external-logical-cluster-admin.crt"),
143+
filepath.Join(workDirPath, ".kcp", "external-logical-cluster-admin.key"),
144144
&kuser.DefaultInfo{
145145
Name: "external-logical-cluster-admin",
146146
Groups: []string{bootstrap.SystemExternalLogicalClusterAdmin},
@@ -156,8 +156,8 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
156156
// for now we will use the privileged system group to bypass the authz stack
157157
// create privileged system user client cert to connect to shards
158158
_, _, err = clientCA.EnsureClientCertificate(
159-
filepath.Join(workDirPath, ".kcp-front-proxy/shard-admin.crt"),
160-
filepath.Join(workDirPath, ".kcp-front-proxy/shard-admin.key"),
159+
filepath.Join(workDirPath, ".kcp-front-proxy", "shard-admin.crt"),
160+
filepath.Join(workDirPath, ".kcp-front-proxy", "shard-admin.key"),
161161
&kuser.DefaultInfo{
162162
Name: "shard-admin",
163163
Groups: []string{kuser.SystemPrivilegedGroup},
@@ -170,9 +170,9 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
170170

171171
// create server CA to be used to sign shard serving certs
172172
servingCA, _, err := crypto.EnsureCA(
173-
filepath.Join(workDirPath, ".kcp/serving-ca.crt"),
174-
filepath.Join(workDirPath, ".kcp/serving-ca.key"),
175-
filepath.Join(workDirPath, ".kcp/serving-ca-serial.txt"),
173+
filepath.Join(workDirPath, ".kcp", "serving-ca.crt"),
174+
filepath.Join(workDirPath, ".kcp", "serving-ca.key"),
175+
filepath.Join(workDirPath, ".kcp", "serving-ca-serial.txt"),
176176
"kcp-serving-ca",
177177
365,
178178
)
@@ -182,9 +182,9 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
182182

183183
// create service account signing and verification key
184184
if _, _, err := crypto.EnsureCA(
185-
filepath.Join(workDirPath, ".kcp/service-account.crt"),
186-
filepath.Join(workDirPath, ".kcp/service-account.key"),
187-
filepath.Join(workDirPath, ".kcp/service-account-serial.txt"),
185+
filepath.Join(workDirPath, ".kcp", "service-account.crt"),
186+
filepath.Join(workDirPath, ".kcp", "service-account.key"),
187+
filepath.Join(workDirPath, ".kcp", "service-account-serial.txt"),
188188
"kcp-service-account-signing-ca",
189189
365,
190190
); err != nil {
@@ -294,7 +294,7 @@ func start(proxyFlags, shardFlags []string, logDirPath, workDirPath string, numb
294294
}
295295

296296
// Label region of shards
297-
clientConfig, err := loadKubeConfig(filepath.Join(workDirPath, ".kcp/admin.kubeconfig"), "base")
297+
clientConfig, err := loadKubeConfig(filepath.Join(workDirPath, ".kcp", "admin.kubeconfig"), "base")
298298
if err != nil {
299299
return err
300300
}

0 commit comments

Comments
 (0)