Skip to content

Commit accffba

Browse files
authored
Merge pull request #1535 from saschagrunert/errcheck
Enable and fix `errcheck` linter
2 parents 9e07dd1 + b9e5fb6 commit accffba

17 files changed

+69
-48
lines changed

Diff for: .golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ linters:
1919
- dupl
2020
- dupword
2121
- durationcheck
22+
- errcheck
2223
- errchkjson
2324
- errname
2425
- errorlint
@@ -93,7 +94,6 @@ linters:
9394
- zerologlint
9495
# - depguard
9596
# - err113
96-
# - errcheck
9797
# - exhaustruct
9898
# - forbidigo
9999
# - funlen

Diff for: cmd/crictl/util.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ func outputStatusData(statuses []statusData, format, tmplStr string) (err error)
326326

327327
for _, k := range keys {
328328
var genericVal map[string]any
329-
json.Unmarshal([]byte(status.info[k]), &genericVal)
329+
if err := json.Unmarshal([]byte(status.info[k]), &genericVal); err != nil {
330+
return fmt.Errorf("unmarshal status info JSON: %w", err)
331+
}
330332
infoMap[k] = genericVal
331333
}
332334

Diff for: cmd/crictl/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var runtimeVersionCommand = &cli.Command{
3232
Usage: "Display runtime version information",
3333
Action: func(c *cli.Context) error {
3434
if c.NArg() != 0 {
35-
cli.ShowSubcommandHelp(c)
35+
return cli.ShowSubcommandHelp(c)
3636
}
3737

3838
runtimeClient, err := getRuntimeService(c, 0)

Diff for: cmd/critest/cri_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,17 @@ func TestCRISuite(t *testing.T) {
174174
}
175175

176176
if *isBenchMark {
177-
flag.Set("ginkgo.focus", "benchmark")
178-
flag.Set("ginkgo.succinct", "true")
177+
if err := flag.Set("ginkgo.focus", "benchmark"); err != nil {
178+
t.Fatalf("set ginkgo benchmark focus: %v", err)
179+
}
180+
if err := flag.Set("ginkgo.succinct", "true"); err != nil {
181+
t.Fatalf("set ginkgo succinct: %v", err)
182+
}
179183
} else {
180184
// Skip benchmark measurements for validation tests.
181-
flag.Set("ginkgo.skip", "benchmark")
185+
if err := flag.Set("ginkgo.skip", "benchmark"); err != nil {
186+
t.Fatalf("skip ginkgo benchmarks: %v", err)
187+
}
182188
}
183189

184190
if *parallel > 1 {

Diff for: pkg/benchmark/container.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
. "github.com/onsi/ginkgo/v2"
26+
. "github.com/onsi/gomega"
2627
"github.com/onsi/gomega/gmeasure"
2728
"github.com/sirupsen/logrus"
2829
internalapi "k8s.io/cri-api/pkg/apis"
@@ -133,9 +134,9 @@ var _ = framework.KubeDescribe("Container", func() {
133134
resultsChannel <- &res
134135

135136
By(fmt.Sprintf("stop PodSandbox %d", idx))
136-
rc.StopPodSandbox(context.TODO(), podID)
137+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
137138
By(fmt.Sprintf("delete PodSandbox %d", idx))
138-
rc.RemovePodSandbox(context.TODO(), podID)
139+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
139140
}, samplingConfig)
140141

141142
// Send nil and give the manager a minute to process any already-queued results:

Diff for: pkg/benchmark/image.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
. "github.com/onsi/ginkgo/v2"
27+
. "github.com/onsi/gomega"
2728
"github.com/onsi/gomega/gmeasure"
2829
"github.com/sirupsen/logrus"
2930
internalapi "k8s.io/cri-api/pkg/apis"
@@ -75,7 +76,7 @@ var _ = framework.KubeDescribe("Image", func() {
7576
imageSpec := &runtimeapi.ImageSpec{
7677
Image: imageName,
7778
}
78-
ic.RemoveImage(context.TODO(), imageSpec)
79+
Expect(ic.RemoveImage(context.TODO(), imageSpec)).NotTo(HaveOccurred())
7980
}
8081
})
8182

Diff for: pkg/benchmark/pod_container.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
8383
framework.ExpectNoError(err, "failed to start Container: %v", err)
8484

8585
By("stop PodSandbox")
86-
rc.StopPodSandbox(context.TODO(), podID)
86+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
8787
By("delete PodSandbox")
88-
rc.RemovePodSandbox(context.TODO(), podID)
88+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
8989
}
9090

9191
// Run a single test to ensure images are available and everything works

Diff for: pkg/validate/apparmor_linux.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ var _ = framework.KubeDescribe("AppArmor", func() {
9393

9494
AfterEach(func() {
9595
By("stop PodSandbox")
96-
rc.StopPodSandbox(context.TODO(), sandboxID)
96+
Expect(rc.StopPodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
9797
By("delete PodSandbox")
98-
rc.RemovePodSandbox(context.TODO(), sandboxID)
98+
Expect(rc.RemovePodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
9999
})
100100

101101
It("should fail with an unloaded apparmor_profile", func() {
@@ -133,9 +133,9 @@ var _ = framework.KubeDescribe("AppArmor", func() {
133133

134134
AfterEach(func() {
135135
By("stop PodSandbox")
136-
rc.StopPodSandbox(context.TODO(), sandboxID)
136+
Expect(rc.StopPodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
137137
By("delete PodSandbox")
138-
rc.RemovePodSandbox(context.TODO(), sandboxID)
138+
Expect(rc.RemovePodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
139139
})
140140

141141
It("should fail with an unloaded apparmor_profile", func() {
@@ -182,9 +182,9 @@ var _ = framework.KubeDescribe("AppArmor", func() {
182182

183183
AfterEach(func() {
184184
By("stop PodSandbox")
185-
rc.StopPodSandbox(context.TODO(), sandboxID)
185+
Expect(rc.StopPodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
186186
By("delete PodSandbox")
187-
rc.RemovePodSandbox(context.TODO(), sandboxID)
187+
Expect(rc.RemovePodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
188188
})
189189

190190
It("should fail with an unloaded apparmor_profile", func() {

Diff for: pkg/validate/container.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ var _ = framework.KubeDescribe("Container", func() {
7373

7474
AfterEach(func() {
7575
By("stop PodSandbox")
76-
rc.StopPodSandbox(context.TODO(), podID)
76+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
7777
By("delete PodSandbox")
78-
rc.RemovePodSandbox(context.TODO(), podID)
78+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
7979
})
8080

8181
It("runtime should support creating container [Conformance]", func() {
@@ -266,9 +266,9 @@ var _ = framework.KubeDescribe("Container", func() {
266266

267267
AfterEach(func() {
268268
By("stop PodSandbox")
269-
rc.StopPodSandbox(context.TODO(), podID)
269+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
270270
By("delete PodSandbox")
271-
rc.RemovePodSandbox(context.TODO(), podID)
271+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
272272
})
273273

274274
It("runtime should support starting container with volume [Conformance]", func() {
@@ -322,9 +322,9 @@ var _ = framework.KubeDescribe("Container", func() {
322322

323323
AfterEach(func() {
324324
By("stop PodSandbox")
325-
rc.StopPodSandbox(context.TODO(), podID)
325+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
326326
By("delete PodSandbox")
327-
rc.RemovePodSandbox(context.TODO(), podID)
327+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
328328
By("clean up the TempDir")
329329
os.RemoveAll(hostPath)
330330
})

Diff for: pkg/validate/container_linux.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ var _ = framework.KubeDescribe("Container Mount Propagation", func() {
5353

5454
AfterEach(func() {
5555
By("stop PodSandbox")
56-
rc.StopPodSandbox(context.TODO(), podID)
56+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5757
By("delete PodSandbox")
58-
rc.RemovePodSandbox(context.TODO(), podID)
58+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5959
})
6060

6161
testMountPropagation := func(propagation runtimeapi.MountPropagation) {
@@ -139,9 +139,9 @@ var _ = framework.KubeDescribe("Container OOM", func() {
139139

140140
AfterEach(func() {
141141
By("stop PodSandbox")
142-
rc.StopPodSandbox(context.TODO(), podID)
142+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
143143
By("delete PodSandbox")
144-
rc.RemovePodSandbox(context.TODO(), podID)
144+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
145145
})
146146

147147
It("should terminate with exitCode 137 and reason OOMKilled", func() {
@@ -331,9 +331,9 @@ var _ = framework.KubeDescribe("Container Mount Readonly", func() {
331331

332332
AfterEach(func() {
333333
By("stop PodSandbox")
334-
rc.StopPodSandbox(context.TODO(), podID)
334+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
335335
By("delete PodSandbox")
336-
rc.RemovePodSandbox(context.TODO(), podID)
336+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
337337
})
338338

339339
testRRO := func(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, rro bool) {

Diff for: pkg/validate/networking.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ var _ = framework.KubeDescribe("Networking", func() {
4848

4949
AfterEach(func() {
5050
By("stop PodSandbox")
51-
rc.StopPodSandbox(context.TODO(), podID)
51+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5252
By("delete PodSandbox")
53-
rc.RemovePodSandbox(context.TODO(), podID)
53+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5454
})
5555

5656
It("runtime should support DNS config [Conformance]", func() {

Diff for: pkg/validate/pod.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
4343
var podID string
4444

4545
AfterEach(func() {
46-
By("stop PodSandbox")
47-
rc.StopPodSandbox(context.TODO(), podID)
48-
By("delete PodSandbox")
49-
rc.RemovePodSandbox(context.TODO(), podID)
46+
if podID != "" {
47+
By("stop PodSandbox")
48+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
49+
By("delete PodSandbox")
50+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
51+
}
5052
})
5153

5254
It("runtime should support running PodSandbox [Conformance]", func() {
@@ -75,6 +77,7 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
7577

7678
By("test remove PodSandbox")
7779
testRemovePodSandbox(rc, podID)
80+
podID = "" // no need to cleanup pod
7881
})
7982
})
8083
})

Diff for: pkg/validate/pod_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
4747

4848
AfterEach(func() {
4949
By("stop PodSandbox")
50-
rc.StopPodSandbox(context.TODO(), podID)
50+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5151
By("delete PodSandbox")
52-
rc.RemovePodSandbox(context.TODO(), podID)
52+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
5353
})
5454

5555
It("should support safe sysctls", func() {

Diff for: pkg/validate/security_context_linux.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ var _ = framework.KubeDescribe("Security Context", func() {
6464
AfterEach(func() {
6565
if podID != "" {
6666
By("stop PodSandbox")
67-
rc.StopPodSandbox(context.TODO(), podID)
67+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
6868
By("delete PodSandbox")
69-
rc.RemovePodSandbox(context.TODO(), podID)
69+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
7070
}
7171
if podLogDir != "" {
7272
os.RemoveAll(podLogDir)
@@ -243,7 +243,8 @@ var _ = framework.KubeDescribe("Security Context", func() {
243243
if err != nil {
244244
return
245245
}
246-
conn.Write([]byte("hello"))
246+
_, err = conn.Write([]byte("hello"))
247+
Expect(err).NotTo(HaveOccurred())
247248
}
248249
}()
249250
defer srv.Close()
@@ -264,7 +265,8 @@ var _ = framework.KubeDescribe("Security Context", func() {
264265
if err != nil {
265266
return
266267
}
267-
conn.Write([]byte("hello"))
268+
_, err = conn.Write([]byte("hello"))
269+
Expect(err).NotTo(HaveOccurred())
268270
}
269271
}()
270272
defer srv.Close()
@@ -1075,6 +1077,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
10751077
}
10761078

10771079
runUserNamespacePodWithError(rc, podName, usernsOptions)
1080+
podID = "" // no need to cleanup the pod
10781081
})
10791082

10801083
It("runtime should fail if container ID 0 is not mapped", func() {
@@ -1090,18 +1093,21 @@ var _ = framework.KubeDescribe("Security Context", func() {
10901093
}
10911094

10921095
runUserNamespacePodWithError(rc, podName, usernsOptions)
1096+
podID = "" // no need to cleanup the pod
10931097
})
10941098

10951099
It("runtime should fail with NamespaceMode_CONTAINER", func() {
10961100
usernsOptions := &runtimeapi.UserNamespace{Mode: runtimeapi.NamespaceMode_CONTAINER}
10971101

10981102
runUserNamespacePodWithError(rc, podName, usernsOptions)
1103+
podID = "" // no need to cleanup the pod
10991104
})
11001105

11011106
It("runtime should fail with NamespaceMode_TARGET", func() {
11021107
usernsOptions := &runtimeapi.UserNamespace{Mode: runtimeapi.NamespaceMode_TARGET}
11031108

11041109
runUserNamespacePodWithError(rc, podName, usernsOptions)
1110+
podID = "" // no need to cleanup the pod
11051111
})
11061112
})
11071113
})

Diff for: pkg/validate/selinux_linux.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func checkContainerSelinux(rc internalapi.RuntimeService, containerID string, sh
215215

216216
func cleanupSandbox(rc internalapi.RuntimeService, sandboxID string) {
217217
By("stop PodSandbox")
218-
rc.StopPodSandbox(context.TODO(), sandboxID)
218+
Expect(rc.StopPodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
219219
By("delete PodSandbox")
220-
rc.RemovePodSandbox(context.TODO(), sandboxID)
220+
Expect(rc.RemovePodSandbox(context.TODO(), sandboxID)).NotTo(HaveOccurred())
221221
}
222222

223223
func checkMountLabelRoleType(rc internalapi.RuntimeService, containerID string) {

Diff for: pkg/validate/streaming.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ var _ = framework.KubeDescribe("Streaming", func() {
5858

5959
AfterEach(func() {
6060
By("stop PodSandbox")
61-
rc.StopPodSandbox(context.TODO(), podID)
61+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
6262
By("delete PodSandbox")
63-
rc.RemovePodSandbox(context.TODO(), podID)
63+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
6464
})
6565

6666
It("runtime should support exec with tty=false and stdin=false [Conformance]", func() {
@@ -283,7 +283,8 @@ func checkAttach(c internalapi.RuntimeService, attachServerURL string) {
283283
header = localOut.String()
284284
return len(header) == len(oldHeader)
285285
}, 10*time.Second, time.Second).Should(BeTrue(), "The container should stop output when there is no input")
286-
writer.Write([]byte(strings.Join(echoHelloCmd, " ") + "\n"))
286+
_, err := writer.Write([]byte(strings.Join(echoHelloCmd, " ") + "\n"))
287+
Expect(err).NotTo(HaveOccurred())
287288
Eventually(func() string {
288289
return strings.TrimPrefix(localOut.String(), header)
289290
}, time.Minute, time.Second).Should(Equal(attachEchoHelloOutput), "The stdout of attach should be hello")

Diff for: pkg/validate/streaming_linux.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121

2222
. "github.com/onsi/ginkgo/v2"
23+
. "github.com/onsi/gomega"
2324
internalapi "k8s.io/cri-api/pkg/apis"
2425
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
2526

@@ -42,9 +43,9 @@ var _ = framework.KubeDescribe("Streaming", func() {
4243

4344
AfterEach(func() {
4445
By("stop PodSandbox")
45-
rc.StopPodSandbox(context.TODO(), podID)
46+
Expect(rc.StopPodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
4647
By("delete PodSandbox")
47-
rc.RemovePodSandbox(context.TODO(), podID)
48+
Expect(rc.RemovePodSandbox(context.TODO(), podID)).NotTo(HaveOccurred())
4849
})
4950

5051
It("runtime should support portforward in host network", func() {

0 commit comments

Comments
 (0)