Skip to content

Commit 7594702

Browse files
committed
modify static check
fix format
1 parent b03a4ac commit 7594702

File tree

14 files changed

+87
-94
lines changed

14 files changed

+87
-94
lines changed

pkg/volume/util/device_util_linux_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,33 +258,33 @@ func TestFindSlaveDevicesOnMultipath(t *testing.T) {
258258
func TestGetISCSIPortalHostMapForTarget(t *testing.T) {
259259
mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{})
260260
portalHostMap, err := mockDeviceUtil.GetISCSIPortalHostMapForTarget("target1")
261-
if nil != err {
261+
if err != nil {
262262
t.Fatalf("error getting scsi hosts for target: %v", err)
263263
}
264-
if nil == portalHostMap {
264+
if portalHostMap == nil {
265265
t.Fatal("no portal host map returned")
266266
}
267-
if 1 != len(portalHostMap) {
267+
if len(portalHostMap) != 1 {
268268
t.Fatalf("wrong number of map entries in portal host map: %d", len(portalHostMap))
269269
}
270-
if 2 != portalHostMap["10.0.0.1:3260"] {
270+
if portalHostMap["10.0.0.1:3260"] != 2 {
271271
t.Fatalf("incorrect entry in portal host map: %v", portalHostMap)
272272
}
273273
}
274274

275275
func TestFindDevicesForISCSILun(t *testing.T) {
276276
mockDeviceUtil := NewDeviceHandler(&mockOsIOHandler{})
277277
devices, err := mockDeviceUtil.FindDevicesForISCSILun("target1", 1)
278-
if nil != err {
278+
if err != nil {
279279
t.Fatalf("error getting devices for lun: %v", err)
280280
}
281-
if nil == devices {
281+
if devices == nil {
282282
t.Fatal("no devices returned")
283283
}
284-
if 1 != len(devices) {
284+
if len(devices) != 1 {
285285
t.Fatalf("wrong number of devices: %d", len(devices))
286286
}
287-
if "sda" != devices[0] {
287+
if devices[0] != "sda" {
288288
t.Fatalf("incorrect device %v", devices)
289289
}
290290
}

pkg/volume/util/fsquota/common/quota_linux_common_impl.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func getXFSQuotaCmd() (string, error) {
116116
}
117117
}
118118
quotaCmdInitialized = true
119-
return "", fmt.Errorf("No xfs_quota program found")
119+
return "", fmt.Errorf("no xfs_quota program found")
120120
}
121121

122122
func doRunXFSQuotaCommand(mountpoint string, mountsFile, command string) (string, error) {
@@ -145,15 +145,15 @@ func doRunXFSQuotaCommand(mountpoint string, mountsFile, command string) (string
145145
func runXFSQuotaCommand(mountpoint string, command string) (string, error) {
146146
tmpMounts, err := ioutil.TempFile("", "mounts")
147147
if err != nil {
148-
return "", fmt.Errorf("Cannot create temporary mount file: %v", err)
148+
return "", fmt.Errorf("cannot create temporary mount file: %v", err)
149149
}
150150
tmpMountsFileName := tmpMounts.Name()
151151
defer tmpMounts.Close()
152152
defer os.Remove(tmpMountsFileName)
153153

154154
mounts, err := os.Open(MountsFile)
155155
if err != nil {
156-
return "", fmt.Errorf("Cannot open mounts file %s: %v", MountsFile, err)
156+
return "", fmt.Errorf("cannot open mounts file %s: %v", MountsFile, err)
157157
}
158158
defer mounts.Close()
159159

@@ -164,16 +164,16 @@ func runXFSQuotaCommand(mountpoint string, command string) (string, error) {
164164
mount := match[2]
165165
if mount == mountpoint {
166166
if _, err := tmpMounts.WriteString(fmt.Sprintf("%s\n", scanner.Text())); err != nil {
167-
return "", fmt.Errorf("Cannot write temporary mounts file: %v", err)
167+
return "", fmt.Errorf("cannot write temporary mounts file: %v", err)
168168
}
169169
if err := tmpMounts.Sync(); err != nil {
170-
return "", fmt.Errorf("Cannot sync temporary mounts file: %v", err)
170+
return "", fmt.Errorf("cannot sync temporary mounts file: %v", err)
171171
}
172172
return doRunXFSQuotaCommand(mountpoint, tmpMountsFileName, command)
173173
}
174174
}
175175
}
176-
return "", fmt.Errorf("Cannot run xfs_quota: cannot find mount point %s in %s", mountpoint, MountsFile)
176+
return "", fmt.Errorf("cannot run xfs_quota: cannot find mount point %s in %s", mountpoint, MountsFile)
177177
}
178178

179179
// SupportsQuotas determines whether the filesystem supports quotas.
@@ -215,14 +215,14 @@ func (v linuxVolumeQuotaApplier) GetQuotaOnDir(path string) (QuotaID, error) {
215215
}
216216
match := lsattrParseRegexp.FindStringSubmatch(string(data))
217217
if match == nil {
218-
return BadQuotaID, fmt.Errorf("Unable to parse lsattr -pd %s output %s", path, string(data))
218+
return BadQuotaID, fmt.Errorf("unable to parse lsattr -pd %s output %s", path, string(data))
219219
}
220220
if match[2] != path {
221-
return BadQuotaID, fmt.Errorf("Mismatch between supplied and returned path (%s != %s)", path, match[2])
221+
return BadQuotaID, fmt.Errorf("mismatch between supplied and returned path (%s != %s)", path, match[2])
222222
}
223223
projid, err := strconv.ParseInt(match[1], 10, 32)
224224
if err != nil {
225-
return BadQuotaID, fmt.Errorf("Unable to parse project ID from %s (%v)", match[1], err)
225+
return BadQuotaID, fmt.Errorf("unable to parse project ID from %s (%v)", match[1], err)
226226
}
227227
return QuotaID(projid), nil
228228
}
@@ -244,18 +244,18 @@ func (v linuxVolumeQuotaApplier) SetQuotaOnDir(path string, id QuotaID, bytes in
244244
func getQuantity(mountpoint string, id QuotaID, xfsQuotaArg string, multiplier int64, allowEmptyOutput bool) (int64, error) {
245245
data, err := runXFSQuotaCommand(mountpoint, fmt.Sprintf("quota -p -N -n -v %s %v", xfsQuotaArg, id))
246246
if err != nil {
247-
return 0, fmt.Errorf("Unable to run xfs_quota: %v", err)
247+
return 0, fmt.Errorf("unable to run xfs_quota: %v", err)
248248
}
249249
if data == "" && allowEmptyOutput {
250250
return 0, nil
251251
}
252252
match := quotaParseRegexp.FindStringSubmatch(data)
253253
if match == nil {
254-
return 0, fmt.Errorf("Unable to parse quota output '%s'", data)
254+
return 0, fmt.Errorf("unable to parse quota output '%s'", data)
255255
}
256256
size, err := strconv.ParseInt(match[1], 10, 64)
257257
if err != nil {
258-
return 0, fmt.Errorf("Unable to parse data size '%s' from '%s': %v", match[1], data, err)
258+
return 0, fmt.Errorf("unable to parse data size '%s' from '%s': %v", match[1], data, err)
259259
}
260260
klog.V(4).Infof("getQuantity %s %d %s %d => %d %v", mountpoint, id, xfsQuotaArg, multiplier, size, err)
261261
return size * multiplier, nil

pkg/volume/util/fsquota/project.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ func findAvailableQuota(path string, idMap map[common.QuotaID]bool) (common.Quot
179179
}
180180
}
181181
}
182-
return common.BadQuotaID, fmt.Errorf("Cannot find available quota ID")
182+
return common.BadQuotaID, fmt.Errorf("cannot find available quota ID")
183183
}
184184

185185
func addDirToProject(path string, id common.QuotaID, list *projectsList) (common.QuotaID, bool, error) {
186186
idMap := make(map[common.QuotaID]bool)
187187
for _, project := range list.projects {
188188
if project.data == path {
189189
if id != project.id {
190-
return common.BadQuotaID, false, fmt.Errorf("Attempt to reassign project ID for %s", path)
190+
return common.BadQuotaID, false, fmt.Errorf("attempt to reassign project ID for %s", path)
191191
}
192192
// Trying to reassign a directory to the project it's
193193
// already in. Maybe this should be an error, but for
@@ -223,16 +223,16 @@ func addDirToProject(path string, id common.QuotaID, list *projectsList) (common
223223

224224
func removeDirFromProject(path string, id common.QuotaID, list *projectsList) (bool, error) {
225225
if id == common.BadQuotaID {
226-
return false, fmt.Errorf("Attempt to remove invalid quota ID from %s", path)
226+
return false, fmt.Errorf("attempt to remove invalid quota ID from %s", path)
227227
}
228228
foundAt := -1
229229
countByID := make(map[common.QuotaID]int)
230230
for i, project := range list.projects {
231231
if project.data == path {
232232
if id != project.id {
233-
return false, fmt.Errorf("Attempting to remove quota ID %v from path %s, but expecting ID %v", id, path, project.id)
233+
return false, fmt.Errorf("attempting to remove quota ID %v from path %s, but expecting ID %v", id, path, project.id)
234234
} else if foundAt != -1 {
235-
return false, fmt.Errorf("Found multiple quota IDs for path %s", path)
235+
return false, fmt.Errorf("found multiple quota IDs for path %s", path)
236236
}
237237
// Faster and easier than deleting an element
238238
list.projects[i].isValid = false
@@ -241,7 +241,7 @@ func removeDirFromProject(path string, id common.QuotaID, list *projectsList) (b
241241
countByID[project.id]++
242242
}
243243
if foundAt == -1 {
244-
return false, fmt.Errorf("Cannot find quota associated with path %s", path)
244+
return false, fmt.Errorf("cannot find quota associated with path %s", path)
245245
}
246246
if countByID[id] <= 1 {
247247
// Removing the last entry means that we're no longer using
@@ -314,7 +314,7 @@ func writeProjectFiles(fProjects *os.File, fProjid *os.File, writeProjid bool, l
314314
}
315315
os.Remove(tmpProjects)
316316
}
317-
return fmt.Errorf("Unable to write project files: %v", err)
317+
return fmt.Errorf("unable to write project files: %v", err)
318318
}
319319

320320
func createProjectID(path string, ID common.QuotaID) (common.QuotaID, error) {

pkg/volume/util/fsquota/quota_linux.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ func getFSInfo(m mount.Interface, path string) (string, string, error) {
170170
if !okMountpoint {
171171
mountpoint, err = detectMountpoint(m, path)
172172
if err != nil {
173-
return "", "", fmt.Errorf("Cannot determine mountpoint for %s: %v", path, err)
173+
return "", "", fmt.Errorf("cannot determine mountpoint for %s: %v", path, err)
174174
}
175175
}
176176

177177
backingDev, okBackingDev := backingDevMap[path]
178178
if !okBackingDev {
179179
backingDev, err = detectBackingDev(m, mountpoint)
180180
if err != nil {
181-
return "", "", fmt.Errorf("Cannot determine backing device for %s: %v", path, err)
181+
return "", "", fmt.Errorf("cannot determine backing device for %s: %v", path, err)
182182
}
183183
}
184184
mountpointMap[path] = mountpoint
@@ -306,11 +306,11 @@ func SupportsQuotas(m mount.Interface, path string) (bool, error) {
306306
//lint:ignore SA4009 poduid is overwritten by design, see comment below
307307
func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error {
308308
if bytes == nil {
309-
return fmt.Errorf("Attempting to assign null quota to %s", path)
309+
return fmt.Errorf("attempting to assign null quota to %s", path)
310310
}
311311
ibytes := bytes.Value()
312312
if ok, err := SupportsQuotas(m, path); !ok {
313-
return fmt.Errorf("Quotas not supported on %s: %v", path, err)
313+
return fmt.Errorf("quotas not supported on %s: %v", path, err)
314314
}
315315
quotaLock.Lock()
316316
defer quotaLock.Unlock()
@@ -321,20 +321,20 @@ func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resour
321321
// one quota per volume, we can rip all of the pod code out.
322322
poduid = types.UID(uuid.NewUUID())
323323
if pod, ok := dirPodMap[path]; ok && pod != poduid {
324-
return fmt.Errorf("Requesting quota on existing directory %s but different pod %s %s", path, pod, poduid)
324+
return fmt.Errorf("requesting quota on existing directory %s but different pod %s %s", path, pod, poduid)
325325
}
326326
oid, ok := podQuotaMap[poduid]
327327
if ok {
328328
if quotaSizeMap[oid] != ibytes {
329-
return fmt.Errorf("Requesting quota of different size: old %v new %v", quotaSizeMap[oid], bytes)
329+
return fmt.Errorf("requesting quota of different size: old %v new %v", quotaSizeMap[oid], bytes)
330330
}
331331
} else {
332332
oid = common.BadQuotaID
333333
}
334334
id, err := createProjectID(path, oid)
335335
if err == nil {
336336
if oid != common.BadQuotaID && oid != id {
337-
return fmt.Errorf("Attempt to reassign quota %v to %v", oid, id)
337+
return fmt.Errorf("attempt to reassign quota %v to %v", oid, id)
338338
}
339339
// When enforcing quotas are enabled, we'll condition this
340340
// on their being disabled also.
@@ -353,7 +353,7 @@ func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resour
353353
}
354354
removeProjectID(path, id)
355355
}
356-
return fmt.Errorf("Assign quota FAILED %v", err)
356+
return fmt.Errorf("assign quota FAILED %v", err)
357357
}
358358

359359
// GetConsumption -- retrieve the consumption (in bytes) of the directory
@@ -396,7 +396,7 @@ func GetInodes(path string) (*resource.Quantity, error) {
396396
func ClearQuota(m mount.Interface, path string) error {
397397
klog.V(3).Infof("ClearQuota %s", path)
398398
if !enabledQuotasForMonitoring() {
399-
return fmt.Errorf("ClearQuota called, but quotas disabled")
399+
return fmt.Errorf("clearQuota called, but quotas disabled")
400400
}
401401
quotaLock.Lock()
402402
defer quotaLock.Unlock()
@@ -413,7 +413,7 @@ func ClearQuota(m mount.Interface, path string) error {
413413
}
414414
_, ok = podQuotaMap[poduid]
415415
if !ok {
416-
return fmt.Errorf("ClearQuota: No quota available for %s", path)
416+
return fmt.Errorf("clearQuota: No quota available for %s", path)
417417
}
418418
projid, err := getQuotaOnDir(m, path)
419419
if err != nil {
@@ -422,7 +422,7 @@ func ClearQuota(m mount.Interface, path string) error {
422422
klog.V(3).Infof("Attempt to check quota ID %v on dir %s failed: %v", dirQuotaMap[path], path, err)
423423
}
424424
if projid != dirQuotaMap[path] {
425-
return fmt.Errorf("Expected quota ID %v on dir %s does not match actual %v", dirQuotaMap[path], path, projid)
425+
return fmt.Errorf("expected quota ID %v on dir %s does not match actual %v", dirQuotaMap[path], path, projid)
426426
}
427427
count, ok := podDirCountMap[poduid]
428428
if count <= 1 || !ok {
@@ -446,7 +446,7 @@ func ClearQuota(m mount.Interface, path string) error {
446446
delete(supportsQuotasMap, path)
447447
clearApplier(path)
448448
if err != nil {
449-
return fmt.Errorf("Unable to clear quota for %s: %v", path, err)
449+
return fmt.Errorf("unable to clear quota for %s: %v", path, err)
450450
}
451451
return nil
452452
}

pkg/volume/util/hostutil/hostutil_linux_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,7 @@ func TestGetFileType(t *testing.T) {
304304
}
305305

306306
func isOperationNotPermittedError(err error) bool {
307-
if strings.Contains(err.Error(), "Operation not permitted") {
308-
return true
309-
}
310-
return false
307+
return strings.Contains(err.Error(), "Operation not permitted")
311308
}
312309

313310
func writeFile(content string) (string, string, error) {

pkg/volume/util/nested_volumes.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func getNestedMountpoints(name, baseDir string, pod v1.Pod) ([]string, error) {
4848
for _, myMountPoint := range myMountPoints {
4949
if strings.HasPrefix(myMountPoint, parentPrefix) {
5050
// Don't let a container trick us into creating directories outside of its rootfs
51-
return fmt.Errorf("Invalid container mount point %v", myMountPoint)
51+
return fmt.Errorf("invalid container mount point %v", myMountPoint)
5252
}
5353
myMPSlash := myMountPoint + string(os.PathSeparator)
5454
// The previously found nested mountpoint (or "" if none found yet)
@@ -75,10 +75,7 @@ func getNestedMountpoints(name, baseDir string, pod v1.Pod) ([]string, error) {
7575
var retErr error
7676
podutil.VisitContainers(&pod.Spec, podutil.AllFeatureEnabledContainers(), func(c *v1.Container, containerType podutil.ContainerType) bool {
7777
retErr = checkContainer(c)
78-
if retErr != nil {
79-
return false
80-
}
81-
return true
78+
return retErr == nil
8279
})
8380
if retErr != nil {
8481
return nil, retErr
@@ -96,7 +93,7 @@ func MakeNestedMountpoints(name, baseDir string, pod v1.Pod) error {
9693
for _, dir := range dirs {
9794
err := os.MkdirAll(filepath.Join(baseDir, dir), 0755)
9895
if err != nil {
99-
return fmt.Errorf("Unable to create nested volume mountpoints: %v", err)
96+
return fmt.Errorf("unable to create nested volume mountpoints: %v", err)
10097
}
10198
}
10299
return nil

pkg/volume/util/nestedpendingoperations/nestedpendingoperations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (grm *nestedPendingOperations) getOperation(key operationKey) (uint, error)
240240
}
241241
}
242242

243-
return 0, fmt.Errorf("Operation %+v not found", key)
243+
return 0, fmt.Errorf("operation %+v not found", key)
244244
}
245245

246246
func (grm *nestedPendingOperations) deleteOperation(key operationKey) {

0 commit comments

Comments
 (0)