Skip to content

Commit 9c1a021

Browse files
chore: enable linter (#59)
* chore: enable linter enables go linter. * chore: fixing lint complains make sure the code is free of lint problems.
1 parent 36e9d72 commit 9c1a021

File tree

10 files changed

+34
-28
lines changed

10 files changed

+34
-28
lines changed

.github/workflows/pull-request.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ jobs:
1212
uses: actions/setup-go@v4
1313
with:
1414
go-version: "1.21.0"
15+
- name: Pull static dependencies
16+
run: |
17+
make static
18+
make static-linux-amd64
19+
- name: Lint
20+
uses: golangci/golangci-lint-action@v3
21+
with:
22+
version: v1.54
23+
skip-cache: true
24+
args: --timeout=1m
1525
- name: Go vet
1626
run: |
1727
make vet

cmd/builder/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func download(w http.ResponseWriter, r *http.Request) {
6363
}
6464
content = bytes.ReplaceAll(content, []byte("{HOST}"), []byte(r.Host))
6565
content = bytes.ReplaceAll(content, []byte("{SCHEME}"), []byte(scheme))
66-
w.Write(content)
66+
_, _ = w.Write(content)
6767
}
6868

6969
func main() {

cmd/helmvm/bundle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ var bundleCommand = &cli.Command{
5454
}
5555
defer dst.Close()
5656
writer, end := progressbar.Start()
57-
writer.Write([]byte("Downloading base images bundle."))
57+
_, _ = writer.Write([]byte("Downloading base images bundle."))
5858
src, err := goods.DownloadImagesBundle(defaults.K0sVersion)
5959
if err != nil {
6060
writer.Close()
@@ -79,7 +79,7 @@ var bundleCommand = &cli.Command{
7979
images = append(images, embed...)
8080
for _, img := range images {
8181
writer, end = progressbar.Start()
82-
writer.Write([]byte(fmt.Sprintf("Pulling image %s", img)))
82+
_, _ = writer.Write([]byte(fmt.Sprintf("Pulling image %s", img)))
8383
if err := pullImage(c.Context, img); err != nil {
8484
writer.Close()
8585
<-end

cmd/helmvm/install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ func runPostApplyOnHost(ctx context.Context, host *cluster.Host) error {
107107
src = "/etc/systemd/system/k0sworker.service"
108108
}
109109
dst := fmt.Sprintf("/etc/systemd/system/%s.service", defaults.BinaryName())
110-
host.ExecOutput(fmt.Sprintf("sudo ln -s %s %s", src, dst))
111-
host.ExecOutput("sudo systemctl daemon-reload")
110+
_, _ = host.ExecOutput(fmt.Sprintf("sudo ln -s %s %s", src, dst))
111+
_, _ = host.ExecOutput("sudo systemctl daemon-reload")
112112
return nil
113113
}
114114

@@ -262,7 +262,7 @@ func runK0sctlApply(ctx context.Context) error {
262262
<-pbwait
263263
}()
264264
cfgpath := defaults.PathToConfig("k0sctl.yaml")
265-
messages.Write([]byte("Running k0sctl apply"))
265+
_, _ = messages.Write([]byte("Running k0sctl apply"))
266266
kctl := exec.Command(bin, "apply", "-c", cfgpath, "--disable-telemetry")
267267
kctl.Stderr = messages
268268
kctl.Stdout = messages

cmd/helmvm/shell.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ var shellCommand = &cli.Command{
6666
signal.Stop(sigch)
6767
close(sigch)
6868
fd := int(os.Stdin.Fd())
69-
term.Restore(fd, state)
69+
_ = term.Restore(fd, state)
7070
}()
7171
kcpath := defaults.PathToConfig("kubeconfig")
7272
config := fmt.Sprintf("export KUBECONFIG=%q\n", kcpath)
73-
shellpty.WriteString(config)
74-
io.CopyN(io.Discard, shellpty, int64(len(config)+1))
73+
_, _ = shellpty.WriteString(config)
74+
_, _ = io.CopyN(io.Discard, shellpty, int64(len(config)+1))
7575
bindir := defaults.HelmVMBinsSubDir()
7676
config = fmt.Sprintf("export PATH=\"$PATH:%s\"\n", bindir)
77-
shellpty.WriteString(config)
78-
io.CopyN(io.Discard, shellpty, int64(len(config)+1))
79-
go func() { io.Copy(shellpty, os.Stdin) }()
80-
go func() { io.Copy(os.Stdout, shellpty) }()
81-
shell.Wait()
77+
_, _ = shellpty.WriteString(config)
78+
_, _ = io.CopyN(io.Discard, shellpty, int64(len(config)+1))
79+
go func() { _, _ = io.Copy(shellpty, os.Stdin) }()
80+
go func() { _, _ = io.Copy(os.Stdout, shellpty) }()
81+
_ = shell.Wait()
8282
return nil
8383
},
8484
}

pkg/addons/adminconsole/customize.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,8 @@ func (a *AdminConsoleCustomization) hostPreflights() (*v1beta2.HostPreflightSpec
183183
if err != nil {
184184
return nil, fmt.Errorf("unable to unserialize preflight spec: %w", err)
185185
}
186-
for _, collector := range spec.Collectors {
187-
all.Collectors = append(all.Collectors, collector)
188-
}
189-
for _, analyzer := range spec.Analyzers {
190-
all.Analyzers = append(all.Analyzers, analyzer)
191-
}
186+
all.Collectors = append(all.Collectors, spec.Collectors...)
187+
all.Analyzers = append(all.Analyzers, spec.Analyzers...)
192188
}
193189
return all, nil
194190
}

pkg/addons/applier.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,8 @@ func (a *Applier) HostPreflights() (*v1beta2.HostPreflightSpec, error) {
8181
} else if hpf == nil {
8282
continue
8383
}
84-
for _, c := range hpf.Collectors {
85-
allpf.Collectors = append(allpf.Collectors, c)
86-
}
87-
for _, a := range hpf.Analyzers {
88-
allpf.Analyzers = append(allpf.Analyzers, a)
89-
}
84+
allpf.Collectors = append(allpf.Collectors, hpf.Collectors...)
85+
allpf.Analyzers = append(allpf.Analyzers, hpf.Analyzers...)
9086
}
9187
return allpf, nil
9288
}

pkg/defaults/provider_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ func TestDecentralizedInstall(t *testing.T) {
2424
defer os.RemoveAll(tmpdir)
2525
def := NewProvider(tmpdir)
2626
assert.False(t, def.DecentralizedInstall(), "default should be centralized")
27-
def.SetInstallAsDecentralized()
27+
err = def.SetInstallAsDecentralized()
28+
assert.NoError(t, err)
2829
assert.True(t, def.DecentralizedInstall(), "unable to set decentralized install")
2930
}
3031

pkg/preflights/preflights.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ import (
2929
// UnserlizeSpec unserializes an HostPreflightSpec from a raw slice of bytes.
3030
func UnserializeSpec(data []byte) (*v1beta2.HostPreflightSpec, error) {
3131
scheme := kruntime.NewScheme()
32-
v1beta2.AddToScheme(scheme)
32+
if err := v1beta2.AddToScheme(scheme); err != nil {
33+
return nil, err
34+
}
3335
decoder := conversion.NewDecoder(scheme)
3436
var hpf v1beta2.HostPreflight
3537
if err := decoder.DecodeInto(data, &hpf); err != nil {

pkg/ssh/ssh_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestKeysCreatedOnlyOnce(t *testing.T) {
3939
err = ssh.AllowLocalSSH()
4040
assert.NoError(t, err)
4141
newfinfo, err := os.Stat(private)
42+
assert.NoError(t, err)
4243
assert.Equal(t, oldfinfo.ModTime(), newfinfo.ModTime(), "private key should not be updated")
4344
}
4445

0 commit comments

Comments
 (0)