Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1514 from saschagrunert/gofumpt
Browse files Browse the repository at this point in the history
Fix and enable `gofumpt` linter
  • Loading branch information
k8s-ci-robot authored Jul 23, 2024
2 parents 77f4a60 + 53b0b53 commit 8d1ccce
Show file tree
Hide file tree
Showing 26 changed files with 42 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ linters:
- gocritic
- godot
- gofmt
- gofumpt
- goheader
- goimports
- gomoddirectives
Expand Down Expand Up @@ -88,7 +89,6 @@ linters:
# - goconst
# - gocyclo
# - godox
# - gofumpt
# - goprintffuncname
# - gosec
# - gosimple
Expand Down
4 changes: 1 addition & 3 deletions cmd/crictl/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ var runtimeAttachCommand = &cli.Command{
ctx, cancel := context.WithCancel(c.Context)
defer cancel()

var opts = attachOptions{
opts := attachOptions{
id: id,
tty: c.Bool("tty"),
stdin: c.Bool("stdin"),
}
if err = Attach(ctx, runtimeClient, opts); err != nil {
return fmt.Errorf("attaching running container failed: %w", err)

}
return nil
},
Expand All @@ -86,7 +85,6 @@ var runtimeAttachCommand = &cli.Command{
func Attach(ctx context.Context, client internalapi.RuntimeService, opts attachOptions) error {
if opts.id == "" {
return errors.New("ID cannot be empty")

}
request := &pb.AttachRequest{
ContainerId: opts.id,
Expand Down
1 change: 0 additions & 1 deletion cmd/crictl/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func zshCompletion(c *cli.Context) error {

fmt.Fprintln(c.App.Writer, fmt.Sprintf(zshCompletionTemplate, strings.Join(subcommands, "' '"), strings.Join(opts, "' '")))
return nil

}

func fishCompletion(c *cli.Context) error {
Expand Down
7 changes: 4 additions & 3 deletions cmd/crictl/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,6 @@ func CreateContainer(
rClient internalapi.RuntimeService,
opts createOptions,
) (string, error) {

config, err := loadContainerConfig(opts.configPath)
if err != nil {
return "", err
Expand Down Expand Up @@ -1185,8 +1184,10 @@ func ListContainers(runtimeClient internalapi.RuntimeService, imageClient intern
image = orig
}
podName := getPodNameFromLabels(c.Labels)
display.AddRow([]string{id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName})
display.AddRow([]string{
id, image, ctm, convertContainerState(c.State), c.Metadata.Name,
strconv.FormatUint(uint64(c.Metadata.Attempt), 10), podID, podName,
})
continue
}

Expand Down
6 changes: 4 additions & 2 deletions cmd/crictl/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ func (d containerStatsDisplayer) displayStats(ctx context.Context, client intern
}
cpuPerc = float64(cpu-old.GetCpu().GetUsageCoreNanoSeconds().GetValue()) / float64(duration) * 100
}
d.display.AddRow([]string{id, name, fmt.Sprintf("%.2f", cpuPerc), units.HumanSize(float64(mem)),
units.HumanSize(float64(disk)), strconv.FormatUint(inodes, 10)})
d.display.AddRow([]string{
id, name, fmt.Sprintf("%.2f", cpuPerc), units.HumanSize(float64(mem)),
units.HumanSize(float64(disk)), strconv.FormatUint(inodes, 10),
})

}
d.display.ClearScreen()
Expand Down
10 changes: 5 additions & 5 deletions cmd/crictl/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// fakeContainersWithCreatedAtDesc creates fake containers in the least recent order of the createdAt.
func fakeContainersWithCreatedAtDesc(names ...string) []*pb.Container {
containers := make([]*pb.Container, len(names), len(names))
creationTime := time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC)
creationTime := time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC)
for i, name := range names {
containers[i] = fakeContainer(name, creationTime.UnixNano())
creationTime = creationTime.Truncate(time.Hour)
Expand Down Expand Up @@ -56,9 +56,9 @@ var _ = DescribeTable("getContainersList",
},
Entry("returns containers in order by createdAt desc",
[]*pb.Container{
fakeContainer("test0", time.Date(2023, 1, 2, 12, 00, 00, 00, time.UTC).UnixNano()),
fakeContainer("test1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
fakeContainer("test2", time.Date(2023, 1, 3, 12, 00, 00, 00, time.UTC).UnixNano()),
fakeContainer("test0", time.Date(2023, 1, 2, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
fakeContainer("test1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
fakeContainer("test2", time.Date(2023, 1, 3, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
},
listOptions{},
[]int{2, 0, 1},
Expand All @@ -70,7 +70,7 @@ var _ = DescribeTable("getContainersList",
Name: "v0",
},
},
fakeContainer("v1", time.Date(2023, 1, 1, 12, 00, 00, 00, time.UTC).UnixNano()),
fakeContainer("v1", time.Date(2023, 1, 1, 12, 0o0, 0o0, 0o0, time.UTC).UnixNano()),
},
listOptions{},
[]int{1, 0},
Expand Down
2 changes: 1 addition & 1 deletion cmd/crictl/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var runtimeExecCommand = &cli.Command{
return err
}

var opts = execOptions{
opts := execOptions{
id: c.Args().First(),
timeout: c.Int64("timeout"),
tty: c.Bool("tty"),
Expand Down
6 changes: 4 additions & 2 deletions cmd/crictl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import (
"sigs.k8s.io/cri-tools/pkg/version"
)

const defaultTimeout = 2 * time.Second
const defaultTimeoutWindows = 200 * time.Second
const (
defaultTimeout = 2 * time.Second
defaultTimeoutWindows = 200 * time.Second
)

var (
// RuntimeEndpoint is CRI server runtime endpoint.
Expand Down
3 changes: 1 addition & 2 deletions cmd/crictl/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var runtimePortForwardCommand = &cli.Command{
return err
}

var opts = portforwardOptions{
opts := portforwardOptions{
id: c.Args().Get(0),
ports: c.Args().Tail(),
transport: c.String(transportFlag),
Expand All @@ -72,7 +72,6 @@ var runtimePortForwardCommand = &cli.Command{
func PortForward(client internalapi.RuntimeService, opts portforwardOptions) error {
if opts.id == "" {
return errors.New("ID cannot be empty")

}
request := &pb.PortForwardRequest{
PodSandboxId: opts.id,
Expand Down
2 changes: 1 addition & 1 deletion cmd/crictl/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func tmplExecuteRawJSON(tmplStr string, rawJSON string) (string, error) {
return "", fmt.Errorf("failed to decode json: %w", err)
}

var o = new(bytes.Buffer)
o := new(bytes.Buffer)
tmpl, err := template.New("tmplExecuteRawJSON").Funcs(builtinTmplFuncs()).Parse(tmplStr)
if err != nil {
return "", fmt.Errorf("failed to generate go-template: %w", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/crictl/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func TestOutputStatusData(t *testing.T) {
}
return nil
})

if err != nil {
Expect(err).To(BeNil())
}
Expand Down
1 change: 0 additions & 1 deletion pkg/benchmark/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ var _ = framework.KubeDescribe("Container", func() {
rc.StopPodSandbox(context.TODO(), podID)
By(fmt.Sprintf("delete PodSandbox %d", idx))
rc.RemovePodSandbox(context.TODO(), podID)

}, samplingConfig)

// Send nil and give the manager a minute to process any already-queued results:
Expand Down
3 changes: 1 addition & 2 deletions pkg/benchmark/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var defaultImageListingBenchmarkImagesAmd64 = []string{
defaultImageListingPrefix + "busybox:1-glibc",
defaultImageListingPrefix + "busybox:1-musl",
}

var defaultImageListingBenchmarkImages = []string{
defaultImageListingPrefix + "busybox:1",
defaultImageListingPrefix + "busybox:1-glibc",
Expand Down Expand Up @@ -158,7 +159,6 @@ var _ = framework.KubeDescribe("Image", func() {
MetaInfo: map[string]string{"imageId": imageId},
}
lifecycleResultsChannel <- &res

}, samplingConfig)

// Send nil and give the manager a minute to process any already-queued results:
Expand Down Expand Up @@ -232,7 +232,6 @@ var _ = framework.KubeDescribe("Image", func() {
MetaInfo: nil,
}
imagesResultsChannel <- &res

}, samplingConfig)

// Send nil and give the manager a minute to process any already-queued results:
Expand Down
1 change: 0 additions & 1 deletion pkg/benchmark/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ var _ = framework.KubeDescribe("PodSandbox", func() {
MetaInfo: map[string]string{"podId": podID, "podSandboxName": podSandboxName},
}
resultsChannel <- &res

}, samplingConfig)

// Send nil and give the manager a minute to process any already-queued results:
Expand Down
2 changes: 1 addition & 1 deletion pkg/benchmark/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (lbrm *LifecycleBenchmarksResultsManager) WriteResultsFile(filepath string)

data, err := json.MarshalIndent(lbrm.resultsSet, "", " ")
if err == nil {
err = os.WriteFile(filepath, data, 0644)
err = os.WriteFile(filepath, data, 0o644)
if err != nil {
return fmt.Errorf("Failed to write benchmarks results to file: %v", filepath)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ func setConfigOption(configName, configValue string, yamlData *yaml.Node) {
Tag: "!!map",
}
}
var contentLen = 0
var foundOption = false
contentLen := 0
foundOption := false
if yamlData.Content[0].Content != nil {
contentLen = len(yamlData.Content[0].Content)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func LoadCRIClient() (*InternalAPIClient, error) {
return nil, err
}

var imageServiceAddr = TestContext.ImageServiceAddr
imageServiceAddr := TestContext.ImageServiceAddr
if imageServiceAddr == "" {
// Fallback to runtime service endpoint
imageServiceAddr = TestContext.RuntimeServiceAddr
Expand Down
4 changes: 1 addition & 3 deletions pkg/validate/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,7 @@ const (
attachEchoHelloWindowsOutput = "hello\r\n\r\nC:\\>"
)

var (
attachEchoHelloOutput string
)
var attachEchoHelloOutput string

var _ = framework.AddBeforeSuiteCallback(func() {
if runtime.GOOS != "windows" || framework.TestContext.IsLcow {
Expand Down
6 changes: 3 additions & 3 deletions pkg/validate/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.M

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

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

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

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

err = unix.Mount("none", tmpfsMntPoint, "tmpfs", 0, "")
Expand Down
6 changes: 4 additions & 2 deletions pkg/validate/multi_container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (string, *

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

// createMultiContainerTestBusyboxContainer creates a busybox container.
func createMultiContainerTestBusyboxContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService,
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig) string {
prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig,
) string {
containerName := prefix + framework.NewUUID()
containerConfig := &runtimeapi.ContainerConfig{
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func createLogTempDir(podSandboxName string) (string, string) {
hostPath, err := os.MkdirTemp("", "podLogTest")
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
podLogPath := filepath.Join(hostPath, podSandboxName)
err = os.MkdirAll(podLogPath, 0777)
err = os.MkdirAll(podLogPath, 0o777)
framework.ExpectNoError(err, "failed to create host path %s: %v", podLogPath, err)

return hostPath, podLogPath
Expand Down
11 changes: 5 additions & 6 deletions pkg/validate/security_context_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ var _ = framework.KubeDescribe("Security Context", func() {
if !strings.Contains(pids, nginxPid) {
framework.Failf("nginx's pid should be seen by hostpid containers")
}

})

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

matchContainerOutputRe(podConfig, containerName, `\s+0\s+1000\s+100000\n`)
})

})

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

return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig), containerName, containerConfig.LogPath

}

// createReadOnlyRootfsContainer creates the container with specified ReadOnlyRootfs in ContainerConfig.
Expand Down Expand Up @@ -1316,7 +1313,7 @@ func createSeccompProfileDir() (string, error) {
// createSeccompProfile creates a seccomp test profile with profileContents.
func createSeccompProfile(profileContents string, profileName string, hostPath string) (string, error) {
profilePath := filepath.Join(hostPath, profileName)
err := os.WriteFile(profilePath, []byte(profileContents), 0644)
err := os.WriteFile(profilePath, []byte(profileContents), 0o644)
if err != nil {
return "", fmt.Errorf("create %s: %w", profilePath, err)
}
Expand Down Expand Up @@ -1387,7 +1384,8 @@ func createSeccompContainer(rc internalapi.RuntimeService,
profile *runtimeapi.SecurityProfile,
caps []string,
privileged bool,
expectContainerCreateToPass bool) string {
expectContainerCreateToPass bool,
) string {
By("create " + profile.GetProfileType().String() + " Seccomp container")
containerName := prefix + framework.NewUUID()
containerConfig := &runtimeapi.ContainerConfig{
Expand Down Expand Up @@ -1418,7 +1416,8 @@ func createContainerWithExpectation(rc internalapi.RuntimeService,
config *runtimeapi.ContainerConfig,
podID string,
podConfig *runtimeapi.PodSandboxConfig,
expectContainerCreateToPass bool) string {
expectContainerCreateToPass bool,
) string {
// Pull the image if it does not exist. (don't fail for inability to pull image)
imageName := config.Image.Image
if !strings.Contains(imageName, ":") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/validate/selinux_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var _ = framework.KubeDescribe("SELinux", func() {
var sandboxID string
var sandboxConfig *runtimeapi.PodSandboxConfig

var sandboxTests = func(privileged bool) {
sandboxTests := func(privileged bool) {
It("should work with just selinux level set", func() {
options := &runtimeapi.SELinuxOption{
Level: "s0",
Expand Down
1 change: 0 additions & 1 deletion pkg/validate/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ var _ = framework.KubeDescribe("Streaming", func() {
By("check the output of portforward")
checkPortForward(rc, req, webServerHostPortForPortForward, webServerContainerPort)
})

})
})

Expand Down
1 change: 0 additions & 1 deletion pkg/validate/streaming_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,5 @@ var _ = framework.KubeDescribe("Streaming", func() {
By("check the output of portforward")
checkPortForward(rc, req, webServerHostPortForHostNetPortFroward, webServerHostNetContainerPort)
})

})
})
1 change: 0 additions & 1 deletion test/e2e/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

// The actual test suite.
var _ = t.Describe("help", func() {

const helpMessageIdentifier = "crictl - client for CRI"

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

0 comments on commit 8d1ccce

Please sign in to comment.