Skip to content

Commit 17ea264

Browse files
author
zhouhao
committed
validate: Code optimization
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
1 parent 11703a7 commit 17ea264

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
@@ -568,8 +568,8 @@ func (v *Validator) CheckLinux() (errs error) {
568568

569569
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
570570
ns := v.spec.Linux.Namespaces[index]
571-
if !namespaceValid(ns) {
572-
errs = multierror.Append(errs, fmt.Errorf("namespace %v is invalid", ns))
571+
if err := namespaceValid(ns); err != nil {
572+
errs = multierror.Append(errs, err)
573573
}
574574

575575
tmpItem := nsTypeList[ns.Type]
@@ -893,7 +893,7 @@ func (v *Validator) rlimitValid(rlimit rspec.POSIXRlimit) (errs error) {
893893
return
894894
}
895895

896-
func namespaceValid(ns rspec.LinuxNamespace) bool {
896+
func namespaceValid(ns rspec.LinuxNamespace) error {
897897
switch ns.Type {
898898
case rspec.PIDNamespace:
899899
case rspec.NetworkNamespace:
@@ -903,14 +903,14 @@ func namespaceValid(ns rspec.LinuxNamespace) bool {
903903
case rspec.UserNamespace:
904904
case rspec.CgroupNamespace:
905905
default:
906-
return false
906+
return fmt.Errorf("invalid namespace type %s", ns.Type)
907907
}
908908

909909
if ns.Path != "" && !filepath.IsAbs(ns.Path) {
910-
return false
910+
return fmt.Errorf("%v is not an absolute path", ns.Path)
911911
}
912912

913-
return true
913+
return nil
914914
}
915915

916916
func pathValid(os, path string) error {

0 commit comments

Comments
 (0)