Skip to content

Commit 53b0b53

Browse files
committed
Fix gofumpt linter
Signed-off-by: Sascha Grunert <[email protected]>
1 parent 71d27b1 commit 53b0b53

27 files changed

+42
-51
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ linters:
2525
- gocritic
2626
- godot
2727
- gofmt
28+
- gofumpt
2829
- goheader
2930
- goimports
3031
- gomoddirectives
@@ -88,7 +89,6 @@ linters:
8889
# - goconst
8990
# - gocyclo
9091
# - godox
91-
# - gofumpt
9292
# - goprintffuncname
9393
# - gosec
9494
# - gosimple

cmd/crictl/attach.go

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,6 @@ func CreateContainer(
782782
rClient internalapi.RuntimeService,
783783
opts createOptions,
784784
) (string, error) {
785-
786785
config, err := loadContainerConfig(opts.configPath)
787786
if err != nil {
788787
return "", err
@@ -1186,8 +1185,10 @@ func ListContainers(runtimeClient internalapi.RuntimeService, imageClient intern
11861185
image = orig
11871186
}
11881187
podName := getPodNameFromLabels(c.Labels)
1189-
display.AddRow([]string{id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
1190-
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName})
1188+
display.AddRow([]string{
1189+
id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
1190+
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName,
1191+
})
11911192
continue
11921193
}
11931194

cmd/crictl/container_stats.go

Lines changed: 4 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// fakeContainersWithCreatedAtDesc creates fake containers in the least recent order of the createdAt.
3030
func fakeContainersWithCreatedAtDesc(names ...string) []*pb.Container {
3131
containers := make([]*pb.Container, len(names), len(names))
32-
creationTime := time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC)
32+
creationTime := time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC)
3333
for i, name := range names {
3434
containers[i] = fakeContainer(name, creationTime.UnixNano())
3535
creationTime = creationTime.Truncate(time.Hour)
@@ -57,9 +57,9 @@ var _ = DescribeTable("getContainersList",
5757
},
5858
Entry("returns containers in order by createdAt desc",
5959
[]*pb.Container{
60-
fakeContainer("test0", time.Date(2023, 1, 2, 12, 00, 00, 00, time.UTC).UnixNano()),
61-
fakeContainer("test1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
62-
fakeContainer("test2", time.Date(2023, 1, 3, 12, 00, 00, 00, time.UTC).UnixNano()),
60+
fakeContainer("test0", time.Date(2023, 1, 2, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
61+
fakeContainer("test1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
62+
fakeContainer("test2", time.Date(2023, 1, 3, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
6363
},
6464
listOptions{},
6565
[]int{2, 0, 1},
@@ -71,7 +71,7 @@ var _ = DescribeTable("getContainersList",
7171
Name: "v0",
7272
},
7373
},
74-
fakeContainer("v1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
74+
fakeContainer("v1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
7575
},
7676
listOptions{},
7777
[]int{1, 0},

cmd/crictl/exec.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ import (
4242
"sigs.k8s.io/cri-tools/pkg/version"
4343
)
4444

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

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

cmd/crictl/portforward.go

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ const (
266266
attachEchoHelloWindowsOutput = "hello\r\n\r\nC:\\>"
267267
)
268268

269-
var (
270-
attachEchoHelloOutput string
271-
)
269+
var attachEchoHelloOutput string
272270

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

pkg/validate/container.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bufio"
2121
"context"
2222
"errors"
23-
2423
"os"
2524
"path/filepath"
2625
"regexp"

pkg/validate/container_linux.go

Lines changed: 3 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package validate
1818

1919
import (
2020
"context"
21-
2221
"os"
2322
"strings"
2423
"time"
@@ -132,7 +131,8 @@ func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (string, *
132131

133132
// createMultiContainerTestHttpdContainer creates an httpd container.
134133
func createMultiContainerTestHttpdContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix string,
135-
podID string, podConfig *runtimeapi.PodSandboxConfig) string {
134+
podID string, podConfig *runtimeapi.PodSandboxConfig,
135+
) string {
136136
containerName := prefix + framework.NewUUID()
137137
containerConfig := &runtimeapi.ContainerConfig{
138138
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
@@ -145,7 +145,8 @@ func createMultiContainerTestHttpdContainer(rc internalapi.RuntimeService, ic in
145145

146146
// createMultiContainerTestBusyboxContainer creates a busybox container.
147147
func createMultiContainerTestBusyboxContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService,
148-
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig) string {
148+
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig,
149+
) string {
149150
containerName := prefix + framework.NewUUID()
150151
containerConfig := &runtimeapi.ContainerConfig{
151152
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),

pkg/validate/pod.go

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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
})

0 commit comments

Comments
 (0)