Skip to content

Commit ac3707c

Browse files
committed
address comments; bring back timeout and revive
1 parent 4e15990 commit ac3707c

Some content is hidden

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

63 files changed

+241
-238
lines changed

.golangci.yml

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: "2"
22
run:
3+
timeout: 10m
34
build-tags:
45
- build
56
- containers_image_openpgp
@@ -9,28 +10,26 @@ linters:
910
- gosec
1011
- misspell
1112
- errcheck
12-
- gofmt
1313
- gosec
14-
- goimports
15-
# - revive # revive is flagging ginkgo and gomega dot-imports
14+
- revive
1615
exclusions:
1716
generated: lax
1817
presets:
1918
- comments
2019
- common-false-positives
2120
- legacy
2221
- std-error-handling
23-
paths:
24-
- third_party$
25-
- builtin$
26-
- examples$
22+
rules:
23+
- path: 'test/integration/*'
24+
text: 'dot-imports: should not use dot imports'
25+
linters:
26+
- revive
27+
- path: 'test/integration/*'
28+
linters:
29+
- dot-imports
2730
formatters:
2831
enable:
2932
- gofmt
3033
- goimports
3134
exclusions:
3235
generated: lax
33-
paths:
34-
- third_party$
35-
- builtin$
36-
- examples$

cmd/crc-embedder/cmd/embed.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ func embedFiles(executablePath string, filenames []string) error {
8888
logging.Debugf("Embedding %s in %s", filename, executablePath)
8989
f, err := os.Open(filename) // #nosec G304
9090
if err != nil {
91-
return fmt.Errorf("Failed to open %s: %v", filename, err)
91+
return fmt.Errorf("failed to open %s: %v", filename, err)
9292
}
9393
defer f.Close()
9494

9595
err = appender.AppendStreamReader(path.Base(filename), f, false)
9696
if err != nil {
97-
return fmt.Errorf("Failed to append %s to %s: %v", filename, executablePath, err)
97+
return fmt.Errorf("failed to append %s to %s: %v", filename, executablePath, err)
9898
}
9999
}
100100

cmd/crc/cmd/config/get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ func configGetCmd(config config.Storage) *cobra.Command {
1616
Long: `Gets a crc configuration property.`,
1717
RunE: func(cmd *cobra.Command, args []string) error {
1818
if len(args) < 1 {
19-
return errors.New("Please provide a configuration property to get")
19+
return errors.New("please provide a configuration property to get")
2020
}
2121
key := args[0]
2222

2323
v := config.Get(key)
2424
if v.Invalid {
25-
return fmt.Errorf("Configuration property '%s' does not exist", key)
25+
return fmt.Errorf("configuration property '%s' does not exist", key)
2626
}
2727

2828
telemetry.SetConfigurationKey(cmd.Context(), args[0])

cmd/crc/cmd/config/set.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func configSetCmd(config *config.Config) *cobra.Command {
1717
CONFIG-KEYS: ` + "\n\n" + configurableFields(config),
1818
RunE: func(cmd *cobra.Command, args []string) error {
1919
if len(args) < 2 {
20-
return errors.New("Please provide a configuration property and its value as in 'crc config set KEY VALUE'")
20+
return errors.New("please provide a configuration property and its value as in 'crc config set KEY VALUE'")
2121
}
2222
setMessage, err := config.Set(args[0], args[1])
2323
if err != nil {

cmd/crc/cmd/config/unset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func configUnsetCmd(config config.Storage) *cobra.Command {
1616
Long: `Unsets a crc configuration property.`,
1717
RunE: func(cmd *cobra.Command, args []string) error {
1818
if len(args) != 1 {
19-
return errors.New("Please provide a configuration property to unset")
19+
return errors.New("please provide a configuration property to unset")
2020
}
2121
unsetMessage, err := config.Unset(args[0])
2222
if err != nil {

cmd/crc/cmd/console.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ func (s *consoleResult) prettyPrintTo(writer io.Writer) error {
9393
}
9494

9595
if s.state != state.Running {
96-
return errors.New("The OpenShift cluster is not running, cannot open the OpenShift Web Console")
96+
return errors.New("the OpenShift cluster is not running, cannot open the OpenShift Web Console")
9797
}
9898

9999
if _, err := fmt.Fprintln(writer, "Opening the OpenShift Web Console in the default browser..."); err != nil {
100100
return err
101101
}
102102
if err := browser.OpenURL(s.ClusterConfig.WebConsoleURL); err != nil {
103-
return fmt.Errorf("Failed to open the OpenShift Web Console, you can access it by opening %s in your web browser", s.ClusterConfig.WebConsoleURL)
103+
return fmt.Errorf("failed to open the OpenShift Web Console, you can access it by opening %s in your web browser", s.ClusterConfig.WebConsoleURL)
104104
}
105105

106106
return nil

cmd/crc/cmd/oc_env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var ocEnvCmd = &cobra.Command{
2424
func runOcEnv(_ []string) error {
2525
userShell, err := shell.GetShell(forceShell)
2626
if err != nil {
27-
return fmt.Errorf("Error running the oc-env command: %s", err.Error())
27+
return fmt.Errorf("error running the oc-env command: %s", err.Error())
2828
}
2929

3030
client := newMachine()

cmd/crc/cmd/podman_env.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var podmanEnvCmd = &cobra.Command{
2525
func runPodmanEnv() error {
2626
userShell, err := shell.GetShell(forceShell)
2727
if err != nil {
28-
return fmt.Errorf("Error running the podman-env command: %s", err.Error())
28+
return fmt.Errorf("error running the podman-env command: %s", err.Error())
2929
}
3030

3131
client := newMachine()

pkg/compress/compress_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func checkFileList(destDir string, extractedFiles []string, expectedFiles fileMa
8484
}
8585
_, found := expectedFiles[rel]
8686
if !found {
87-
return fmt.Errorf("Unexpected file '%s' in file list %v", rel, expectedFiles)
87+
return fmt.Errorf("unexpected file '%s' in file list %v", rel, expectedFiles)
8888
}
8989
delete(expectedFiles, rel)
9090
}
@@ -117,7 +117,7 @@ func checkFiles(destDir string, files fileMap) error {
117117
}
118118
expectedContent, found := files[archivePath]
119119
if !found {
120-
return fmt.Errorf("Unexpected extracted file '%s'", path)
120+
return fmt.Errorf("unexpected extracted file '%s'", path)
121121
}
122122
delete(files, archivePath)
123123

@@ -126,7 +126,7 @@ func checkFiles(destDir string, files fileMap) error {
126126
return err
127127
}
128128
if string(data) != expectedContent {
129-
return fmt.Errorf("Unexpected content for '%s': expected [%s], got [%s]", path, expectedContent, string(data))
129+
return fmt.Errorf("unexpected content for '%s': expected [%s], got [%s]", path, expectedContent, string(data))
130130
}
131131
logging.Debugf("'%s' successfully checked", path)
132132
return nil

pkg/crc/api/client/client.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (c *client) Start(config StartConfig) (StartResult, error) {
8080

8181
if config != (StartConfig{}) {
8282
if err := json.NewEncoder(data).Encode(config); err != nil {
83-
return sr, fmt.Errorf("Failed to encode data to JSON: %w", err)
83+
return sr, fmt.Errorf("failed to encode data to JSON: %w", err)
8484
}
8585
}
8686
body, err := c.sendPostRequest("/start", data)
@@ -140,11 +140,11 @@ func (c *client) SetConfig(configs SetConfigRequest) (SetOrUnsetConfigResult, er
140140
var data = new(bytes.Buffer)
141141

142142
if len(configs.Properties) == 0 {
143-
return scr, fmt.Errorf("No config key value pair provided to set")
143+
return scr, fmt.Errorf("no config key value pair provided to set")
144144
}
145145

146146
if err := json.NewEncoder(data).Encode(configs); err != nil {
147-
return scr, fmt.Errorf("Failed to encode data to JSON: %w", err)
147+
return scr, fmt.Errorf("failed to encode data to JSON: %w", err)
148148
}
149149

150150
body, err := c.sendPostRequest("/config", data)
@@ -167,7 +167,7 @@ func (c *client) UnsetConfig(configs []string) (SetOrUnsetConfigResult, error) {
167167
Properties: configs,
168168
}
169169
if err := json.NewEncoder(data).Encode(cfg); err != nil {
170-
return ucr, fmt.Errorf("Failed to encode data to JSON: %w", err)
170+
return ucr, fmt.Errorf("failed to encode data to JSON: %w", err)
171171
}
172172
body, err := c.sendDeleteRequest("/config", data)
173173
if err != nil {
@@ -185,7 +185,7 @@ func (c *client) Telemetry(action string) error {
185185
Action: action,
186186
})
187187
if err != nil {
188-
return fmt.Errorf("Failed to encode data to JSON: %w", err)
188+
return fmt.Errorf("failed to encode data to JSON: %w", err)
189189
}
190190

191191
_, err = c.sendPostRequest("/telemetry", bytes.NewReader(data))
@@ -219,7 +219,7 @@ func (c *client) sendGetRequest(url string) ([]byte, error) {
219219

220220
body, err := io.ReadAll(res.Body)
221221
if err != nil {
222-
return nil, fmt.Errorf("Unknown error reading response: %w", err)
222+
return nil, fmt.Errorf("unknown error reading response: %w", err)
223223
}
224224

225225
if res.StatusCode != http.StatusOK {
@@ -258,17 +258,17 @@ func (c *client) sendRequest(url string, method string, data io.Reader) ([]byte,
258258
switch method {
259259
case http.MethodPost:
260260
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated {
261-
return nil, fmt.Errorf("Error occurred sending POST request to : %s : %d", url, res.StatusCode)
261+
return nil, fmt.Errorf("error occurred sending POST request to : %s : %d", url, res.StatusCode)
262262
}
263263
case http.MethodDelete, http.MethodGet:
264264
if res.StatusCode != http.StatusOK {
265-
return nil, fmt.Errorf("Error occurred sending %s request to : %s : %d", method, url, res.StatusCode)
265+
return nil, fmt.Errorf("error occurred sending %s request to : %s : %d", method, url, res.StatusCode)
266266
}
267267
}
268268

269269
body, err := io.ReadAll(res.Body)
270270
if err != nil {
271-
return nil, fmt.Errorf("Unknown error reading response: %w", err)
271+
return nil, fmt.Errorf("unknown error reading response: %w", err)
272272
}
273273
return body, nil
274274
}

pkg/crc/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func getVersionGeneric(executablePath string, args ...string) (string, error) {
6262
parsedOutput := strings.Split(stdOut, ":")
6363
if len(parsedOutput) < 2 {
6464
logging.Debugf("failed to parse version information for %s: %s", executablePath, stdOut)
65-
return "", fmt.Errorf("Unable to parse the version information of %s", executablePath)
65+
return "", fmt.Errorf("unable to parse the version information of %s", executablePath)
6666
}
6767
return strings.TrimSpace(parsedOutput[1]), nil
6868
}

pkg/crc/cluster/cert_renewal.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ func approvePendingCSRs(ctx context.Context, ocConfig oc.Config, expectedSignerN
3232
logging.Debugf("Approving csr %s (signerName: %s)", csr.Name, expectedSignerName)
3333
_, stderr, err := ocConfig.RunOcCommand("adm", "certificate", "approve", csr.Name)
3434
if err != nil {
35-
return fmt.Errorf("Not able to approve csr (%v : %s)", err, stderr)
35+
return fmt.Errorf("not able to approve csr (%v : %s)", err, stderr)
3636
}
3737
csrsApproved = true
3838
}
3939
if !csrsApproved {
40-
return &crcerrors.RetriableError{Err: fmt.Errorf("No Pending CSR with signerName %s", expectedSignerName)}
40+
return &crcerrors.RetriableError{Err: fmt.Errorf("no Pending CSR with signerName %s", expectedSignerName)}
4141
}
4242
return nil
4343
}, time.Second*5)

pkg/crc/cluster/cluster.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func EnsureSSHKeyPresentInTheCluster(ctx context.Context, ocConfig oc.Config, ss
168168
}
169169
stdout, stderr, err := ocConfig.RunOcCommand("get", "machineconfigs", "99-master-ssh", "-o", `jsonpath='{.spec.config.passwd.users[0].sshAuthorizedKeys[0]}'`)
170170
if err != nil {
171-
return fmt.Errorf("Failed to get machine configs %v: %s", err, stderr)
171+
return fmt.Errorf("failed to get machine configs %v: %s", err, stderr)
172172
}
173173
if stdout == string(sshPublicKey) {
174174
return nil
@@ -179,7 +179,7 @@ func EnsureSSHKeyPresentInTheCluster(ctx context.Context, ocConfig oc.Config, ss
179179
"--type", "merge"}
180180
_, stderr, err = ocConfig.RunOcCommand(cmdArgs...)
181181
if err != nil {
182-
return fmt.Errorf("Failed to update ssh key %v: %s", err, stderr)
182+
return fmt.Errorf("failed to update ssh key %v: %s", err, stderr)
183183
}
184184
return nil
185185
}
@@ -191,7 +191,7 @@ func EnsurePullSecretPresentInTheCluster(ctx context.Context, ocConfig oc.Config
191191

192192
stdout, stderr, err := ocConfig.RunOcCommandPrivate("get", "secret", "pull-secret", "-n", "openshift-config", "-o", `jsonpath="{['data']['\.dockerconfigjson']}"`)
193193
if err != nil {
194-
return fmt.Errorf("Failed to get pull secret %v: %s", err, stderr)
194+
return fmt.Errorf("failed to get pull secret %v: %s", err, stderr)
195195
}
196196
decoded, err := base64.StdEncoding.DecodeString(stdout)
197197
if err != nil {
@@ -213,7 +213,7 @@ func EnsurePullSecretPresentInTheCluster(ctx context.Context, ocConfig oc.Config
213213

214214
_, stderr, err = ocConfig.RunOcCommandPrivate(cmdArgs...)
215215
if err != nil {
216-
return fmt.Errorf("Failed to add Pull secret %v: %s", err, stderr)
216+
return fmt.Errorf("failed to add Pull secret %v: %s", err, stderr)
217217
}
218218
return nil
219219
}
@@ -225,7 +225,7 @@ func EnsureGeneratedClientCAPresentInTheCluster(ctx context.Context, ocConfig oc
225225
}
226226
clusterClientCA, stderr, err := ocConfig.RunOcCommand("get", "configmaps", "admin-kubeconfig-client-ca", "-n", "openshift-config", "-o", `jsonpath="{.data.ca-bundle\.crt}"`)
227227
if err != nil {
228-
return fmt.Errorf("Failed to get config map %v: %s", err, stderr)
228+
return fmt.Errorf("failed to get config map %v: %s", err, stderr)
229229
}
230230

231231
ok, err := crctls.VerifyCertificateAgainstRootCA(clusterClientCA, adminCert)
@@ -242,10 +242,10 @@ func EnsureGeneratedClientCAPresentInTheCluster(ctx context.Context, ocConfig oc
242242
"-n", "openshift-config", "--patch", jsonPath}
243243
_, stderr, err = ocConfig.RunOcCommand(cmdArgs...)
244244
if err != nil {
245-
return fmt.Errorf("Failed to patch admin-kubeconfig-client-ca config map with new CA` %v: %s", err, stderr)
245+
return fmt.Errorf("failed to patch admin-kubeconfig-client-ca config map with new CA` %v: %s", err, stderr)
246246
}
247247
if err := sshRunner.CopyFile(constants.KubeconfigFilePath, ocConfig.KubeconfigPath, 0644); err != nil {
248-
return fmt.Errorf("Failed to copy generated kubeconfig file to VM: %v", err)
248+
return fmt.Errorf("failed to copy generated kubeconfig file to VM: %v", err)
249249
}
250250

251251
return nil
@@ -259,7 +259,7 @@ func RemovePullSecretFromCluster(ctx context.Context, ocConfig oc.Config, sshRun
259259

260260
_, stderr, err := ocConfig.RunOcCommand(cmdArgs...)
261261
if err != nil {
262-
return fmt.Errorf("Failed to remove Pull secret %w: %s", err, stderr)
262+
return fmt.Errorf("failed to remove Pull secret %w: %s", err, stderr)
263263
}
264264
return waitForPullSecretRemovedFromInstanceDisk(ctx, sshRunner)
265265
}
@@ -318,7 +318,7 @@ func RemoveOldRenderedMachineConfig(ocConfig oc.Config) error {
318318
if deleteRenderedMachineConfig != "" {
319319
_, stderr, err = ocConfig.RunOcCommand(fmt.Sprintf("delete %s", deleteRenderedMachineConfig))
320320
if err != nil {
321-
return fmt.Errorf("Failed to remove machineconfigpools %w: %s", err, stderr)
321+
return fmt.Errorf("failed to remove machineconfigpools %w: %s", err, stderr)
322322
}
323323
}
324324
return nil
@@ -331,7 +331,7 @@ func EnsureClusterIDIsNotEmpty(ctx context.Context, ocConfig oc.Config) error {
331331

332332
stdout, stderr, err := ocConfig.RunOcCommand("get", "clusterversion", "version", "-o", `jsonpath="{['spec']['clusterID']}"`)
333333
if err != nil {
334-
return fmt.Errorf("Failed to get clusterversion %v: %s", err, stderr)
334+
return fmt.Errorf("failed to get clusterversion %v: %s", err, stderr)
335335
}
336336
if strings.TrimSpace(stdout) != "" {
337337
return nil
@@ -344,7 +344,7 @@ func EnsureClusterIDIsNotEmpty(ctx context.Context, ocConfig oc.Config) error {
344344

345345
_, stderr, err = ocConfig.RunOcCommand(cmdArgs...)
346346
if err != nil {
347-
return fmt.Errorf("Failed to update cluster ID %v: %s", err, stderr)
347+
return fmt.Errorf("failed to update cluster ID %v: %s", err, stderr)
348348
}
349349

350350
return nil
@@ -389,13 +389,13 @@ func AddProxyConfigToCluster(ctx context.Context, sshRunner *ssh.Runner, ocConfi
389389

390390
patchEncode, err := json.Marshal(patch)
391391
if err != nil {
392-
return fmt.Errorf("Failed to encode to json: %v", err)
392+
return fmt.Errorf("failed to encode to json: %v", err)
393393
}
394394
logging.Debugf("Patch string %s", string(patchEncode))
395395

396396
cmdArgs := []string{"patch", "proxy", "cluster", "-p", fmt.Sprintf("'%s'", string(patchEncode)), "--type", "merge"}
397397
if _, stderr, err := ocConfig.RunOcCommandPrivate(cmdArgs...); err != nil {
398-
return fmt.Errorf("Failed to add proxy details %v: %s", err, stderr)
398+
return fmt.Errorf("failed to add proxy details %v: %s", err, stderr)
399399
}
400400
return nil
401401
}
@@ -423,7 +423,7 @@ func addProxyCACertToCluster(sshRunner *ssh.Runner, ocConfig oc.Config, proxy *h
423423
}
424424
cmdArgs := []string{"apply", "-f", proxyConfigMapFileName}
425425
if _, stderr, err := ocConfig.RunOcCommandPrivate(cmdArgs...); err != nil {
426-
return fmt.Errorf("Failed to add proxy cert details %v: %s", err, stderr)
426+
return fmt.Errorf("failed to add proxy cert details %v: %s", err, stderr)
427427
}
428428
return nil
429429
}

pkg/crc/cluster/csr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func getCSRList(ctx context.Context, ocConfig oc.Config, expectedSignerName stri
3333
}
3434
output, stderr, err := ocConfig.WithFailFast().RunOcCommand("get", "csr", "-ojson")
3535
if err != nil {
36-
return nil, fmt.Errorf("Failed to get all certificate signing requests: %v %s", err, stderr)
36+
return nil, fmt.Errorf("failed to get all certificate signing requests: %v %s", err, stderr)
3737
}
3838
err = json.Unmarshal([]byte(output), &csrs)
3939
if err != nil {

0 commit comments

Comments
 (0)