Skip to content

Commit 8d1ccce

Browse files
authored
Merge pull request #1514 from saschagrunert/gofumpt
Fix and enable `gofumpt` linter
2 parents 77f4a60 + 53b0b53 commit 8d1ccce

26 files changed

+42
-49
lines changed

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ linters:
2626
- gocritic
2727
- godot
2828
- gofmt
29+
- gofumpt
2930
- goheader
3031
- goimports
3132
- gomoddirectives
@@ -88,7 +89,6 @@ linters:
8889
# - goconst
8990
# - gocyclo
9091
# - godox
91-
# - gofumpt
9292
# - goprintffuncname
9393
# - gosec
9494
# - gosimple

cmd/crictl/attach.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ var runtimeAttachCommand = &cli.Command{
6969
ctx, cancel := context.WithCancel(c.Context)
7070
defer cancel()
7171

72-
var opts = attachOptions{
72+
opts := attachOptions{
7373
id: id,
7474
tty: c.Bool("tty"),
7575
stdin: c.Bool("stdin"),
7676
}
7777
if err = Attach(ctx, runtimeClient, opts); err != nil {
7878
return fmt.Errorf("attaching running container failed: %w", err)
79-
8079
}
8180
return nil
8281
},
@@ -86,7 +85,6 @@ var runtimeAttachCommand = &cli.Command{
8685
func Attach(ctx context.Context, client internalapi.RuntimeService, opts attachOptions) error {
8786
if opts.id == "" {
8887
return errors.New("ID cannot be empty")
89-
9088
}
9189
request := &pb.AttachRequest{
9290
ContainerId: opts.id,

cmd/crictl/completion.go

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ func zshCompletion(c *cli.Context) error {
9090

9191
fmt.Fprintln(c.App.Writer, fmt.Sprintf(zshCompletionTemplate, strings.Join(subcommands, "' '"), strings.Join(opts, "' '")))
9292
return nil
93-
9493
}
9594

9695
func fishCompletion(c *cli.Context) error {

cmd/crictl/container.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ func CreateContainer(
781781
rClient internalapi.RuntimeService,
782782
opts createOptions,
783783
) (string, error) {
784-
785784
config, err := loadContainerConfig(opts.configPath)
786785
if err != nil {
787786
return "", err
@@ -1185,8 +1184,10 @@ func ListContainers(runtimeClient internalapi.RuntimeService, imageClient intern
11851184
image = orig
11861185
}
11871186
podName := getPodNameFromLabels(c.Labels)
1188-
display.AddRow([]string{id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
1189-
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName})
1187+
display.AddRow([]string{
1188+
id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
1189+
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName,
1190+
})
11901191
continue
11911192
}
11921193

cmd/crictl/container_stats.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ func (d containerStatsDisplayer) displayStats(ctx context.Context, client intern
213213
}
214214
cpuPerc = float64(cpu-old.GetCpu().GetUsageCoreNanoSeconds().GetValue()) / float64(duration) * 100
215215
}
216-
d.display.AddRow([]string{id, name, fmt.Sprintf("%.2f", cpuPerc), units.HumanSize(float64(mem)),
217-
units.HumanSize(float64(disk)), strconv.FormatUint(inodes, 10)})
216+
d.display.AddRow([]string{
217+
id, name, fmt.Sprintf("%.2f", cpuPerc), units.HumanSize(float64(mem)),
218+
units.HumanSize(float64(disk)), strconv.FormatUint(inodes, 10),
219+
})
218220

219221
}
220222
d.display.ClearScreen()

cmd/crictl/container_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// fakeContainersWithCreatedAtDesc creates fake containers in the least recent order of the createdAt.
2929
func fakeContainersWithCreatedAtDesc(names ...string) []*pb.Container {
3030
containers := make([]*pb.Container, len(names), len(names))
31-
creationTime := time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC)
31+
creationTime := time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC)
3232
for i, name := range names {
3333
containers[i] = fakeContainer(name, creationTime.UnixNano())
3434
creationTime = creationTime.Truncate(time.Hour)
@@ -56,9 +56,9 @@ var _ = DescribeTable("getContainersList",
5656
},
5757
Entry("returns containers in order by createdAt desc",
5858
[]*pb.Container{
59-
fakeContainer("test0", time.Date(2023, 1, 2, 12, 00, 00, 00, time.UTC).UnixNano()),
60-
fakeContainer("test1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
61-
fakeContainer("test2", time.Date(2023, 1, 3, 12, 00, 00, 00, time.UTC).UnixNano()),
59+
fakeContainer("test0", time.Date(2023, 1, 2, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
60+
fakeContainer("test1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
61+
fakeContainer("test2", time.Date(2023, 1, 3, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
6262
},
6363
listOptions{},
6464
[]int{2, 0, 1},
@@ -70,7 +70,7 @@ var _ = DescribeTable("getContainersList",
7070
Name: "v0",
7171
},
7272
},
73-
fakeContainer("v1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
73+
fakeContainer("v1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
7474
},
7575
listOptions{},
7676
[]int{1, 0},

cmd/crictl/exec.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ var runtimeExecCommand = &cli.Command{
8888
return err
8989
}
9090

91-
var opts = execOptions{
91+
opts := execOptions{
9292
id: c.Args().First(),
9393
timeout: c.Int64("timeout"),
9494
tty: c.Bool("tty"),

cmd/crictl/main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ import (
4141
"sigs.k8s.io/cri-tools/pkg/version"
4242
)
4343

44-
const defaultTimeout = 2 * time.Second
45-
const defaultTimeoutWindows = 200 * time.Second
44+
const (
45+
defaultTimeout = 2 * time.Second
46+
defaultTimeoutWindows = 200 * time.Second
47+
)
4648

4749
var (
4850
// RuntimeEndpoint is CRI server runtime endpoint.

cmd/crictl/portforward.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var runtimePortForwardCommand = &cli.Command{
5656
return err
5757
}
5858

59-
var opts = portforwardOptions{
59+
opts := portforwardOptions{
6060
id: c.Args().Get(0),
6161
ports: c.Args().Tail(),
6262
transport: c.String(transportFlag),
@@ -72,7 +72,6 @@ var runtimePortForwardCommand = &cli.Command{
7272
func PortForward(client internalapi.RuntimeService, opts portforwardOptions) error {
7373
if opts.id == "" {
7474
return errors.New("ID cannot be empty")
75-
7675
}
7776
request := &pb.PortForwardRequest{
7877
PodSandboxId: opts.id,

cmd/crictl/templates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func tmplExecuteRawJSON(tmplStr string, rawJSON string) (string, error) {
6060
return "", fmt.Errorf("failed to decode json: %w", err)
6161
}
6262

63-
var o = new(bytes.Buffer)
63+
o := new(bytes.Buffer)
6464
tmpl, err := template.New("tmplExecuteRawJSON").Funcs(builtinTmplFuncs()).Parse(tmplStr)
6565
if err != nil {
6666
return "", fmt.Errorf("failed to generate go-template: %w", err)

cmd/crictl/util_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func TestOutputStatusData(t *testing.T) {
187187
}
188188
return nil
189189
})
190-
191190
if err != nil {
192191
Expect(err).To(BeNil())
193192
}

pkg/benchmark/container.go

-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ var _ = framework.KubeDescribe("Container", func() {
136136
rc.StopPodSandbox(context.TODO(), podID)
137137
By(fmt.Sprintf("delete PodSandbox %d", idx))
138138
rc.RemovePodSandbox(context.TODO(), podID)
139-
140139
}, samplingConfig)
141140

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

pkg/benchmark/image.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var defaultImageListingBenchmarkImagesAmd64 = []string{
4646
defaultImageListingPrefix + "busybox:1-glibc",
4747
defaultImageListingPrefix + "busybox:1-musl",
4848
}
49+
4950
var defaultImageListingBenchmarkImages = []string{
5051
defaultImageListingPrefix + "busybox:1",
5152
defaultImageListingPrefix + "busybox:1-glibc",
@@ -158,7 +159,6 @@ var _ = framework.KubeDescribe("Image", func() {
158159
MetaInfo: map[string]string{"imageId": imageId},
159160
}
160161
lifecycleResultsChannel <- &res
161-
162162
}, samplingConfig)
163163

164164
// Send nil and give the manager a minute to process any already-queued results:
@@ -232,7 +232,6 @@ var _ = framework.KubeDescribe("Image", func() {
232232
MetaInfo: nil,
233233
}
234234
imagesResultsChannel <- &res
235-
236235
}, samplingConfig)
237236

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

pkg/benchmark/pod.go

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
131131
MetaInfo: map[string]string{"podId": podID, "podSandboxName": podSandboxName},
132132
}
133133
resultsChannel <- &res
134-
135134
}, samplingConfig)
136135

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

pkg/benchmark/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (lbrm *LifecycleBenchmarksResultsManager) WriteResultsFile(filepath string)
166166

167167
data, err := json.MarshalIndent(lbrm.resultsSet, "", " ")
168168
if err == nil {
169-
err = os.WriteFile(filepath, data, 0644)
169+
err = os.WriteFile(filepath, data, 0o644)
170170
if err != nil {
171171
return fmt.Errorf("Failed to write benchmarks results to file: %v", filepath)
172172
}

pkg/common/file.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func setConfigOption(configName, configValue string, yamlData *yaml.Node) {
151151
Tag: "!!map",
152152
}
153153
}
154-
var contentLen = 0
155-
var foundOption = false
154+
contentLen := 0
155+
foundOption := false
156156
if yamlData.Content[0].Content != nil {
157157
contentLen = len(yamlData.Content[0].Content)
158158
}

pkg/framework/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func LoadCRIClient() (*InternalAPIClient, error) {
140140
return nil, err
141141
}
142142

143-
var imageServiceAddr = TestContext.ImageServiceAddr
143+
imageServiceAddr := TestContext.ImageServiceAddr
144144
if imageServiceAddr == "" {
145145
// Fallback to runtime service endpoint
146146
imageServiceAddr = TestContext.RuntimeServiceAddr

pkg/validate/consts.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ const (
267267
attachEchoHelloWindowsOutput = "hello\r\n\r\nC:\\>"
268268
)
269269

270-
var (
271-
attachEchoHelloOutput string
272-
)
270+
var attachEchoHelloOutput string
273271

274272
var _ = framework.AddBeforeSuiteCallback(func() {
275273
if runtime.GOOS != "windows" || framework.TestContext.IsLcow {

pkg/validate/container_linux.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.M
174174

175175
mntSource := filepath.Join(hostPath, "mnt")
176176
propagationMntPoint := filepath.Join(mntSource, "propagationMnt")
177-
err = os.MkdirAll(propagationMntPoint, 0700)
177+
err = os.MkdirAll(propagationMntPoint, 0o700)
178178
framework.ExpectNoError(err, "failed to create volume dir %q: %v", propagationMntPoint, err)
179179

180180
propagationSrcDir := filepath.Join(hostPath, "propagationSrcDir")
181-
err = os.MkdirAll(propagationSrcDir, 0700)
181+
err = os.MkdirAll(propagationSrcDir, 0o700)
182182
framework.ExpectNoError(err, "failed to create volume dir %q: %v", propagationSrcDir, err)
183183

184184
_, err = os.Create(filepath.Join(propagationSrcDir, "flagFile"))
@@ -434,7 +434,7 @@ func createHostPathForRROMount(podID string) (string, func()) {
434434
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
435435

436436
tmpfsMntPoint := filepath.Join(hostPath, "tmpfs")
437-
err = os.MkdirAll(tmpfsMntPoint, 0700)
437+
err = os.MkdirAll(tmpfsMntPoint, 0o700)
438438
framework.ExpectNoError(err, "failed to create tmpfs dir %q: %v", tmpfsMntPoint, err)
439439

440440
err = unix.Mount("none", tmpfsMntPoint, "tmpfs", 0, "")

pkg/validate/multi_container_linux.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (string, *
131131

132132
// createMultiContainerTestHttpdContainer creates an httpd container.
133133
func createMultiContainerTestHttpdContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix string,
134-
podID string, podConfig *runtimeapi.PodSandboxConfig) string {
134+
podID string, podConfig *runtimeapi.PodSandboxConfig,
135+
) string {
135136
containerName := prefix + framework.NewUUID()
136137
containerConfig := &runtimeapi.ContainerConfig{
137138
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
@@ -144,7 +145,8 @@ func createMultiContainerTestHttpdContainer(rc internalapi.RuntimeService, ic in
144145

145146
// createMultiContainerTestBusyboxContainer creates a busybox container.
146147
func createMultiContainerTestBusyboxContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService,
147-
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig) string {
148+
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig,
149+
) string {
148150
containerName := prefix + framework.NewUUID()
149151
containerConfig := &runtimeapi.ContainerConfig{
150152
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),

pkg/validate/pod.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func createLogTempDir(podSandboxName string) (string, string) {
162162
hostPath, err := os.MkdirTemp("", "podLogTest")
163163
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
164164
podLogPath := filepath.Join(hostPath, podSandboxName)
165-
err = os.MkdirAll(podLogPath, 0777)
165+
err = os.MkdirAll(podLogPath, 0o777)
166166
framework.ExpectNoError(err, "failed to create host path %s: %v", podLogPath, err)
167167

168168
return hostPath, podLogPath

pkg/validate/security_context_linux.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ var _ = framework.KubeDescribe("Security Context", func() {
130130
if !strings.Contains(pids, nginxPid) {
131131
framework.Failf("nginx's pid should be seen by hostpid containers")
132132
}
133-
134133
})
135134

136135
testHostIPC := func(mode runtimeapi.NamespaceMode) {
@@ -921,7 +920,6 @@ var _ = framework.KubeDescribe("Security Context", func() {
921920

922921
matchContainerOutputRe(podConfig, containerName, `\s+0\s+1000\s+100000\n`)
923922
})
924-
925923
})
926924

927925
When("Host idmap mount support is not needed", func() {
@@ -1150,7 +1148,6 @@ func createNamespaceContainer(rc internalapi.RuntimeService, ic internalapi.Imag
11501148
}
11511149

11521150
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig), containerName, containerConfig.LogPath
1153-
11541151
}
11551152

11561153
// createReadOnlyRootfsContainer creates the container with specified ReadOnlyRootfs in ContainerConfig.
@@ -1316,7 +1313,7 @@ func createSeccompProfileDir() (string, error) {
13161313
// createSeccompProfile creates a seccomp test profile with profileContents.
13171314
func createSeccompProfile(profileContents string, profileName string, hostPath string) (string, error) {
13181315
profilePath := filepath.Join(hostPath, profileName)
1319-
err := os.WriteFile(profilePath, []byte(profileContents), 0644)
1316+
err := os.WriteFile(profilePath, []byte(profileContents), 0o644)
13201317
if err != nil {
13211318
return "", fmt.Errorf("create %s: %w", profilePath, err)
13221319
}
@@ -1387,7 +1384,8 @@ func createSeccompContainer(rc internalapi.RuntimeService,
13871384
profile *runtimeapi.SecurityProfile,
13881385
caps []string,
13891386
privileged bool,
1390-
expectContainerCreateToPass bool) string {
1387+
expectContainerCreateToPass bool,
1388+
) string {
13911389
By("create " + profile.GetProfileType().String() + " Seccomp container")
13921390
containerName := prefix + framework.NewUUID()
13931391
containerConfig := &runtimeapi.ContainerConfig{
@@ -1418,7 +1416,8 @@ func createContainerWithExpectation(rc internalapi.RuntimeService,
14181416
config *runtimeapi.ContainerConfig,
14191417
podID string,
14201418
podConfig *runtimeapi.PodSandboxConfig,
1421-
expectContainerCreateToPass bool) string {
1419+
expectContainerCreateToPass bool,
1420+
) string {
14221421
// Pull the image if it does not exist. (don't fail for inability to pull image)
14231422
imageName := config.Image.Image
14241423
if !strings.Contains(imageName, ":") {

pkg/validate/selinux_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var _ = framework.KubeDescribe("SELinux", func() {
4747
var sandboxID string
4848
var sandboxConfig *runtimeapi.PodSandboxConfig
4949

50-
var sandboxTests = func(privileged bool) {
50+
sandboxTests := func(privileged bool) {
5151
It("should work with just selinux level set", func() {
5252
options := &runtimeapi.SELinuxOption{
5353
Level: "s0",

pkg/validate/streaming.go

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ var _ = framework.KubeDescribe("Streaming", func() {
146146
By("check the output of portforward")
147147
checkPortForward(rc, req, webServerHostPortForPortForward, webServerContainerPort)
148148
})
149-
150149
})
151150
})
152151

pkg/validate/streaming_linux.go

-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,5 @@ var _ = framework.KubeDescribe("Streaming", func() {
7171
By("check the output of portforward")
7272
checkPortForward(rc, req, webServerHostPortForHostNetPortFroward, webServerHostNetContainerPort)
7373
})
74-
7574
})
7675
})

test/e2e/help_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
// The actual test suite.
2424
var _ = t.Describe("help", func() {
25-
2625
const helpMessageIdentifier = "crictl - client for CRI"
2726

2827
It("should succeed with `help` subcommand", func() {

0 commit comments

Comments
 (0)