Skip to content

Commit 0e15add

Browse files
authored
Merge pull request #1523 from saschagrunert/unnamedResult
Fix `unnamedResult` linter
2 parents f725fe6 + 55588a6 commit 0e15add

File tree

7 files changed

+44
-44
lines changed

7 files changed

+44
-44
lines changed

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ linters-settings:
186186
- typeUnparen
187187
- uncheckedInlineErr
188188
- unlabelStmt
189+
- unnamedResult
189190
- unnecessaryBlock
190191
- unnecessaryDefer
191192
- weakCond
193+
- whyNoLint
192194
- yodaStyleExpr
193195
# - hugeParam
194-
# - unnamedResult
195-
# - whyNoLint

cmd/crictl/image.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ func ouputImageFsInfoTable(r *pb.ImageFsInfoResponse) {
566566
tablePrintFileSystem("Image", r.ImageFilesystems)
567567
}
568568

569-
func parseCreds(creds string) (string, string, error) {
569+
func parseCreds(creds string) (username, password string, err error) {
570570
if creds == "" {
571571
return "", "", errors.New("credentials can't be empty")
572572
}
@@ -638,7 +638,7 @@ func normalizeRepoTagPair(repoTags []string, imageName string) (repoTagPairs [][
638638
return
639639
}
640640

641-
func normalizeRepoDigest(repoDigests []string) (string, string) {
641+
func normalizeRepoDigest(repoDigests []string) (repo, digest string) {
642642
if len(repoDigests) == 0 {
643643
return "<none>", "<none>"
644644
}

pkg/validate/container.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -504,11 +504,11 @@ func verifyExecSyncOutput(c internalapi.RuntimeService, containerID string, comm
504504
}
505505

506506
// createHostPath creates the hostPath and flagFile for volume.
507-
func createHostPath(podID string) (string, string) {
507+
func createHostPath(podID string) (hostPath, flagFile string) {
508508
hostPath, err := os.MkdirTemp("", "test"+podID)
509509
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
510510

511-
flagFile := "testVolume.file"
511+
flagFile = "testVolume.file"
512512
_, err = os.Create(filepath.Join(hostPath, flagFile))
513513
framework.ExpectNoError(err, "failed to create volume file %q: %v", flagFile, err)
514514

@@ -544,7 +544,7 @@ func createVolumeContainer(rc internalapi.RuntimeService, ic internalapi.ImageMa
544544
}
545545

546546
// createLogContainer creates a container with log and the prefix of containerName.
547-
func createLogContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix, podID string, podConfig *runtimeapi.PodSandboxConfig) (string, string) {
547+
func createLogContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix, podID string, podConfig *runtimeapi.PodSandboxConfig) (logPath, containerID string) {
548548
By("create a container with log and name")
549549
containerName := prefix + framework.NewUUID()
550550
path := containerName + ".log"
@@ -558,7 +558,7 @@ func createLogContainer(rc internalapi.RuntimeService, ic internalapi.ImageManag
558558
}
559559

560560
// createKeepLoggingContainer creates a container keeps logging defaultLog to output.
561-
func createKeepLoggingContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix, podID string, podConfig *runtimeapi.PodSandboxConfig) (string, string) {
561+
func createKeepLoggingContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix, podID string, podConfig *runtimeapi.PodSandboxConfig) (logPath, containerID string) {
562562
By("create a container with log and name")
563563
containerName := prefix + framework.NewUUID()
564564
path := containerName + ".log"

pkg/validate/container_linux.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ var _ = framework.KubeDescribe("Container OOM", func() {
168168
})
169169

170170
// createHostPath creates the hostPath for mount propagation test.
171-
func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.MountPropagation) (string, string, string, func()) {
171+
func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.MountPropagation) (mntSource, propagationSrcDir, propagationMntPoint string, clearHostPath func()) {
172172
hostPath, err := os.MkdirTemp("", "test"+podID)
173173
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
174174

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

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

@@ -203,7 +203,7 @@ func createHostPathForMountPropagation(podID string, propagationOpt runtimeapi.M
203203
framework.ExpectNoError(err, "failed to set \"mntSource\" to \"rprivate\": %v", err)
204204
}
205205

206-
clearHostPath := func() {
206+
clearHostPath = func() {
207207
By("clean up the TempDir")
208208
err := unix.Unmount(propagationMntPoint, unix.MNT_DETACH)
209209
framework.ExpectNoError(err, "failed to unmount \"propagationMntPoint\": %v", err)
@@ -429,7 +429,7 @@ func runtimeSupportsRRO(rc internalapi.RuntimeService, runtimeHandlerName string
429429
// createHostPathForRROMount creates the hostPath for RRO mount test.
430430
//
431431
// hostPath contains a "tmpfs" directory with tmpfs mounted on it.
432-
func createHostPathForRROMount(podID string) (string, func()) {
432+
func createHostPathForRROMount(podID string) (hostPath string, clearHostPath func()) {
433433
hostPath, err := os.MkdirTemp("", "test"+podID)
434434
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
435435

@@ -440,7 +440,7 @@ func createHostPathForRROMount(podID string) (string, func()) {
440440
err = unix.Mount("none", tmpfsMntPoint, "tmpfs", 0, "")
441441
framework.ExpectNoError(err, "failed to mount tmpfs on dir %q: %v", tmpfsMntPoint, err)
442442

443-
clearHostPath := func() {
443+
clearHostPath = func() {
444444
By("clean up the TempDir")
445445
err := unix.Unmount(tmpfsMntPoint, unix.MNT_DETACH)
446446
framework.ExpectNoError(err, "failed to unmount \"tmpfsMntPoint\": %v", err)

pkg/validate/multi_container_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ var _ = framework.KubeDescribe("Multiple Containers [Conformance]", func() {
108108
})
109109

110110
// createMultiContainerTestPodSandbox creates a sandbox with log directory and a container port for httpd container.
111-
func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (string, *runtimeapi.PodSandboxConfig, string) {
111+
func createMultiContainerTestPodSandbox(c internalapi.RuntimeService) (sandboxID string, podConfig *runtimeapi.PodSandboxConfig, logDir string) {
112112
podSandboxName := "PodSandbox-for-multi-container-test-" + framework.NewUUID()
113113
uid := framework.DefaultUIDPrefix + framework.NewUUID()
114114
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()
115115
logDir, podLogPath := createLogTempDir(podSandboxName)
116-
podConfig := &runtimeapi.PodSandboxConfig{
116+
podConfig = &runtimeapi.PodSandboxConfig{
117117
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
118118
LogDirectory: podLogPath,
119119
PortMappings: []*runtimeapi.PortMapping{

pkg/validate/pod.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,25 @@ func listPodSandbox(c internalapi.RuntimeService, filter *runtimeapi.PodSandboxF
158158
}
159159

160160
// createLogTempDir creates the log temp directory for podSandbox.
161-
func createLogTempDir(podSandboxName string) (string, string) {
161+
func createLogTempDir(podSandboxName string) (hostPath, podLogPath string) {
162162
hostPath, err := os.MkdirTemp("", "podLogTest")
163163
framework.ExpectNoError(err, "failed to create TempDir %q: %v", hostPath, err)
164-
podLogPath := filepath.Join(hostPath, podSandboxName)
164+
podLogPath = filepath.Join(hostPath, podSandboxName)
165165
err = os.MkdirAll(podLogPath, 0o777)
166166
framework.ExpectNoError(err, "failed to create host path %s: %v", podLogPath, err)
167167

168168
return hostPath, podLogPath
169169
}
170170

171171
// createPodSandboxWithLogDirectory creates a PodSandbox with log directory.
172-
func createPodSandboxWithLogDirectory(c internalapi.RuntimeService) (string, *runtimeapi.PodSandboxConfig, string) {
172+
func createPodSandboxWithLogDirectory(c internalapi.RuntimeService) (sandboxID string, podConfig *runtimeapi.PodSandboxConfig, hostPath string) {
173173
By("create a PodSandbox with log directory")
174174
podSandboxName := "PodSandbox-with-log-directory-" + framework.NewUUID()
175175
uid := framework.DefaultUIDPrefix + framework.NewUUID()
176176
namespace := framework.DefaultNamespacePrefix + framework.NewUUID()
177177

178178
hostPath, podLogPath := createLogTempDir(podSandboxName)
179-
podConfig := &runtimeapi.PodSandboxConfig{
179+
podConfig = &runtimeapi.PodSandboxConfig{
180180
Metadata: framework.BuildPodSandboxMetadata(podSandboxName, uid, namespace, framework.DefaultAttempt),
181181
LogDirectory: podLogPath,
182182
Linux: &runtimeapi.LinuxPodSandboxConfig{

pkg/validate/security_context_linux.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ var _ = framework.KubeDescribe("Security Context", func() {
9090

9191
By("create nginx container")
9292
prefix := "nginx-container-"
93-
containerName := prefix + framework.NewUUID()
94-
containerID, nginxContainerName, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, nginxContainerImage, namespaceOption, nil, "")
93+
nginxContainerName := prefix + framework.NewUUID()
94+
containerID, _ := createNamespaceContainer(rc, ic, podID, podConfig, nginxContainerName, nginxContainerImage, namespaceOption, nil, "")
9595

9696
By("start container")
9797
startContainer(rc, containerID)
@@ -108,8 +108,8 @@ var _ = framework.KubeDescribe("Security Context", func() {
108108
By("create busybox container with hostPID")
109109
command = []string{"sh", "-c", "sleep 1000"}
110110
prefix = "container-with-HostPID-test-"
111-
containerName = prefix + framework.NewUUID()
112-
containerID, _, _ = createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOption, command, "")
111+
containerName := prefix + framework.NewUUID()
112+
containerID, _ = createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOption, command, "")
113113

114114
By("start container")
115115
startContainer(rc, containerID)
@@ -150,7 +150,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
150150
By("create a default container with namespace")
151151
prefix := "namespace-container-"
152152
containerName := prefix + framework.NewUUID()
153-
containerID, _, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOption, pauseCmd, "")
153+
containerID, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOption, pauseCmd, "")
154154

155155
By("start container")
156156
startContainer(rc, containerID)
@@ -190,7 +190,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
190190
By("create nginx container")
191191
prefix := "nginx-container-"
192192
containerName := prefix + framework.NewUUID()
193-
containerID, _, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, nginxContainerImage, namespaceOption, nil, "")
193+
containerID, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, nginxContainerImage, namespaceOption, nil, "")
194194

195195
By("start container")
196196
startContainer(rc, containerID)
@@ -216,7 +216,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
216216
By("create nginx container")
217217
prefix := "nginx-container-"
218218
containerName := prefix + framework.NewUUID()
219-
containerID, _, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, nginxContainerImage, namespaceOption, nil, "")
219+
containerID, _ := createNamespaceContainer(rc, ic, podID, podConfig, containerName, nginxContainerImage, namespaceOption, nil, "")
220220

221221
By("start container")
222222
startContainer(rc, containerID)
@@ -375,7 +375,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
375375

376376
By("create container with ReadOnlyRootfs_false")
377377
readOnlyRootfs := false
378-
logPath, containerID := createReadOnlyRootfsContainer(rc, ic, podID, podConfig, "container-with-ReadOnlyRootfs-false-test-", readOnlyRootfs)
378+
containerID, logPath := createReadOnlyRootfsContainer(rc, ic, podID, podConfig, "container-with-ReadOnlyRootfs-false-test-", readOnlyRootfs)
379379

380380
By("start container")
381381
startContainer(rc, containerID)
@@ -393,7 +393,7 @@ var _ = framework.KubeDescribe("Security Context", func() {
393393

394394
By("create container with ReadOnlyRootfs_true")
395395
readOnlyRootfs := true
396-
logPath, containerID := createReadOnlyRootfsContainer(rc, ic, podID, podConfig, "container-with-ReadOnlyRootfs-true-test-", readOnlyRootfs)
396+
containerID, logPath := createReadOnlyRootfsContainer(rc, ic, podID, podConfig, "container-with-ReadOnlyRootfs-true-test-", readOnlyRootfs)
397397

398398
By("start container")
399399
startContainer(rc, containerID)
@@ -1118,11 +1118,11 @@ func matchContainerOutputRe(podConfig *runtimeapi.PodSandboxConfig, name, patter
11181118
}
11191119

11201120
// createRunAsUserContainer creates the container with specified RunAsUser in ContainerConfig.
1121-
func createRunAsUserContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string) (string, string) {
1121+
func createRunAsUserContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string) (containerID, expectedLogMessage string) {
11221122
By("create RunAsUser container")
11231123
var uidV runtimeapi.Int64Value
11241124
uidV.Value = 1001
1125-
expectedLogMessage := "1001\n"
1125+
expectedLogMessage = "1001\n"
11261126

11271127
By("create a container with RunAsUser")
11281128
containerName := prefix + framework.NewUUID()
@@ -1141,10 +1141,10 @@ func createRunAsUserContainer(rc internalapi.RuntimeService, ic internalapi.Imag
11411141
}
11421142

11431143
// createRunAsUserNameContainer creates the container with specified RunAsUserName in ContainerConfig.
1144-
func createRunAsUserNameContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string) (string, string) {
1144+
func createRunAsUserNameContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string) (containerID, expectedLogMessage string) {
11451145
By("create RunAsUserName container")
11461146
userName := "nobody"
1147-
expectedLogMessage := userName + "\n"
1147+
expectedLogMessage = userName + "\n"
11481148

11491149
By("create a container with RunAsUserName")
11501150
containerName := prefix + framework.NewUUID()
@@ -1162,12 +1162,12 @@ func createRunAsUserNameContainer(rc internalapi.RuntimeService, ic internalapi.
11621162
}
11631163

11641164
// createRunAsGroupContainer creates the container with specified RunAsGroup in ContainerConfig.
1165-
func createRunAsGroupContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, containerName string) (string, string) {
1165+
func createRunAsGroupContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, containerName string) (containerID, expectedLogMessage string) {
11661166
By("create RunAsGroup container")
11671167
var uidV, gidV runtimeapi.Int64Value
11681168
uidV.Value = 1001
11691169
gidV.Value = 1002
1170-
expectedLogMessage := "1001:1002\n"
1170+
expectedLogMessage = "1001:1002\n"
11711171

11721172
By("create a container with RunAsUser and RunAsGroup")
11731173
containerConfig := &runtimeapi.ContainerConfig{
@@ -1229,7 +1229,7 @@ func createNamespacePodSandbox(rc internalapi.RuntimeService, podSandboxNamespac
12291229
}
12301230

12311231
// createNamespaceContainer creates container with different NamespaceOption config.
1232-
func createNamespaceContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, containerName, image string, containerNamespace *runtimeapi.NamespaceOption, command []string, path string) (string, string, string) {
1232+
func createNamespaceContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, containerName, image string, containerNamespace *runtimeapi.NamespaceOption, command []string, path string) (containerID, logPath string) {
12331233
By("create NamespaceOption container")
12341234
containerConfig := &runtimeapi.ContainerConfig{
12351235
Metadata: framework.BuildContainerMetadata(containerName, framework.DefaultAttempt),
@@ -1243,11 +1243,11 @@ func createNamespaceContainer(rc internalapi.RuntimeService, ic internalapi.Imag
12431243
LogPath: path,
12441244
}
12451245

1246-
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig), containerName, containerConfig.LogPath
1246+
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig), containerConfig.LogPath
12471247
}
12481248

12491249
// createReadOnlyRootfsContainer creates the container with specified ReadOnlyRootfs in ContainerConfig.
1250-
func createReadOnlyRootfsContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string, readonly bool) (string, string) {
1250+
func createReadOnlyRootfsContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, podID string, podConfig *runtimeapi.PodSandboxConfig, prefix string, readonly bool) (containerID, logPath string) {
12511251
By("create ReadOnlyRootfs container")
12521252
containerName := prefix + framework.NewUUID()
12531253
path := containerName + ".log"
@@ -1263,7 +1263,7 @@ func createReadOnlyRootfsContainer(rc internalapi.RuntimeService, ic internalapi
12631263
LogPath: path,
12641264
}
12651265

1266-
return containerConfig.LogPath, framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
1266+
return framework.CreateContainer(rc, ic, containerConfig, podID, podConfig), containerConfig.LogPath
12671267
}
12681268

12691269
// checkRootfs checks whether the rootfs parameter of the ContainerConfig is working properly.
@@ -1370,7 +1370,7 @@ func createAndCheckHostNetwork(rc internalapi.RuntimeService, ic internalapi.Ima
13701370
command := []string{"sh", "-c", "netstat -ln"}
13711371
containerName := "container-with-HostNetwork-test-" + framework.NewUUID()
13721372
path := containerName + ".log"
1373-
containerID, _, logPath := createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOptions, command, path)
1373+
containerID, logPath := createNamespaceContainer(rc, ic, podID, podConfig, containerName, framework.TestContext.TestImageList.DefaultTestContainerImage, namespaceOptions, command, path)
13741374

13751375
By("start container")
13761376
startContainer(rc, containerID)
@@ -1417,7 +1417,7 @@ func createSeccompProfile(profileContents, profileName, hostPath string) (string
14171417
}
14181418

14191419
// seccompTestContainer creates and starts a seccomp sandbox and a container.
1420-
func seccompTestContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, profile *runtimeapi.SecurityProfile) (string, string) {
1420+
func seccompTestContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, profile *runtimeapi.SecurityProfile) (podID, containerID string) {
14211421
By("create seccomp sandbox")
14221422
podSandboxName := "seccomp-sandbox-" + framework.NewUUID()
14231423
uid := framework.DefaultUIDPrefix + framework.NewUUID()
@@ -1432,7 +1432,7 @@ func seccompTestContainer(rc internalapi.RuntimeService, ic internalapi.ImageMan
14321432
},
14331433
Labels: framework.DefaultPodLabels,
14341434
}
1435-
podID := framework.RunPodSandbox(rc, podConfig)
1435+
podID = framework.RunPodSandbox(rc, podConfig)
14361436

14371437
By("create container")
14381438
containerNamePrefix := "seccomp-container-" + framework.NewUUID()
@@ -1447,7 +1447,7 @@ func seccompTestContainer(rc internalapi.RuntimeService, ic internalapi.ImageMan
14471447
},
14481448
},
14491449
}
1450-
containerID := framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
1450+
containerID = framework.CreateContainer(rc, ic, containerConfig, podID, podConfig)
14511451

14521452
By("start container")
14531453
startContainer(rc, containerID)

0 commit comments

Comments
 (0)