Skip to content

Commit ed2112e

Browse files
author
zhouhao
committed
validate: Code optimization
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent 2b007bc commit ed2112e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

validate/validate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ func (v *Validator) CheckLinux() (errs error) {
560560

561561
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
562562
ns := v.spec.Linux.Namespaces[index]
563-
if !v.namespaceValid(ns) {
564-
errs = multierror.Append(errs, fmt.Errorf("namespace %v is invalid", ns))
563+
if err := v.namespaceValid(ns); err != nil {
564+
errs = multierror.Append(errs, err)
565565
}
566566

567567
tmpItem := nsTypeList[ns.Type]
@@ -885,7 +885,7 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
885885
return
886886
}
887887

888-
func (v *Validator) namespaceValid(ns rspec.LinuxNamespace) bool {
888+
func (v *Validator) namespaceValid(ns rspec.LinuxNamespace) error {
889889
switch ns.Type {
890890
case rspec.PIDNamespace:
891891
case rspec.NetworkNamespace:
@@ -895,14 +895,14 @@ func (v *Validator) namespaceValid(ns rspec.LinuxNamespace) bool {
895895
case rspec.UserNamespace:
896896
case rspec.CgroupNamespace:
897897
default:
898-
return false
898+
return fmt.Errorf("invalid namespace type %s", ns.Type)
899899
}
900900

901901
if ns.Path != "" && !osFilepath.IsAbs(v.platform, ns.Path) {
902-
return false
902+
return fmt.Errorf("path %v of namespace %v is not absolute path", ns.Path, ns)
903903
}
904904

905-
return true
905+
return nil
906906
}
907907

908908
func deviceValid(d rspec.LinuxDevice) bool {

0 commit comments

Comments
 (0)