Skip to content

Commit c990087

Browse files
author
Zhou Hao
authored
Merge pull request #443 from Mashimiao/validate-bug-fix
validate/validate.go: fix duplicated variable bug
2 parents bcf89dd + 90cd35e commit c990087

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

validate/validate.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (v *Validator) CheckLinux() (msgs []string) {
443443
return
444444
}
445445

446-
var typeList = map[rspec.LinuxNamespaceType]struct {
446+
var nsTypeList = map[rspec.LinuxNamespaceType]struct {
447447
num int
448448
newExist bool
449449
}{
@@ -462,7 +462,7 @@ func (v *Validator) CheckLinux() (msgs []string) {
462462
msgs = append(msgs, fmt.Sprintf("namespace %v is invalid.", ns))
463463
}
464464

465-
tmpItem := typeList[ns.Type]
465+
tmpItem := nsTypeList[ns.Type]
466466
tmpItem.num = tmpItem.num + 1
467467
if tmpItem.num > 1 {
468468
msgs = append(msgs, fmt.Sprintf("duplicated namespace %q", ns.Type))
@@ -471,10 +471,10 @@ func (v *Validator) CheckLinux() (msgs []string) {
471471
if len(ns.Path) == 0 {
472472
tmpItem.newExist = true
473473
}
474-
typeList[ns.Type] = tmpItem
474+
nsTypeList[ns.Type] = tmpItem
475475
}
476476

477-
if (len(v.spec.Linux.UIDMappings) > 0 || len(v.spec.Linux.GIDMappings) > 0) && !typeList[rspec.UserNamespace].newExist {
477+
if (len(v.spec.Linux.UIDMappings) > 0 || len(v.spec.Linux.GIDMappings) > 0) && !nsTypeList[rspec.UserNamespace].newExist {
478478
msgs = append(msgs, "UID/GID mappings requires a new User namespace to be specified as well")
479479
} else if len(v.spec.Linux.UIDMappings) > 5 {
480480
msgs = append(msgs, "Only 5 UID mappings are allowed (linux kernel restriction).")
@@ -483,23 +483,23 @@ func (v *Validator) CheckLinux() (msgs []string) {
483483
}
484484

485485
for k := range v.spec.Linux.Sysctl {
486-
if strings.HasPrefix(k, "net.") && !typeList[rspec.NetworkNamespace].newExist {
486+
if strings.HasPrefix(k, "net.") && !nsTypeList[rspec.NetworkNamespace].newExist {
487487
msgs = append(msgs, fmt.Sprintf("Sysctl %v requires a new Network namespace to be specified as well", k))
488488
}
489489
if strings.HasPrefix(k, "fs.mqueue.") {
490-
if !typeList[rspec.MountNamespace].newExist || !typeList[rspec.IPCNamespace].newExist {
490+
if !nsTypeList[rspec.MountNamespace].newExist || !nsTypeList[rspec.IPCNamespace].newExist {
491491
msgs = append(msgs, fmt.Sprintf("Sysctl %v requires a new IPC namespace and Mount namespace to be specified as well", k))
492492
}
493493
}
494494
}
495495

496-
if v.platform == "linux" && !typeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
496+
if v.platform == "linux" && !nsTypeList[rspec.UTSNamespace].newExist && v.spec.Hostname != "" {
497497
msgs = append(msgs, fmt.Sprintf("On Linux, hostname requires a new UTS namespace to be specified as well"))
498498
}
499499

500500
// Linux devices validation
501501
devList := make(map[string]bool)
502-
typeList := make(map[string]bool)
502+
devTypeList := make(map[string]bool)
503503
for index := 0; index < len(v.spec.Linux.Devices); index++ {
504504
device := v.spec.Linux.Devices[index]
505505
if !deviceValid(device) {
@@ -582,10 +582,10 @@ func (v *Validator) CheckLinux() (msgs []string) {
582582
devID = fmt.Sprintf("%s:%d:%d", device.Type, device.Major, device.Minor)
583583
}
584584

585-
if _, exists := typeList[devID]; exists {
585+
if _, exists := devTypeList[devID]; exists {
586586
logrus.Warnf("type:%s, major:%d and minor:%d for linux devices is duplicated", device.Type, device.Major, device.Minor)
587587
} else {
588-
typeList[devID] = true
588+
devTypeList[devID] = true
589589
}
590590
}
591591

0 commit comments

Comments
 (0)