@@ -47,15 +47,21 @@ type Validator struct {
4747 spec * rspec.Spec
4848 bundlePath string
4949 HostSpecific bool
50+ platform string
5051}
5152
5253// NewValidator creates a Validator
53- func NewValidator (spec * rspec.Spec , bundlePath string , hostSpecific bool ) Validator {
54- return Validator {spec : spec , bundlePath : bundlePath , HostSpecific : hostSpecific }
54+ func NewValidator (spec * rspec.Spec , bundlePath string , hostSpecific bool , platform string ) Validator {
55+ return Validator {
56+ spec : spec ,
57+ bundlePath : bundlePath ,
58+ HostSpecific : hostSpecific ,
59+ platform : platform ,
60+ }
5561}
5662
5763// NewValidatorFromPath creates a Validator with specified bundle path
58- func NewValidatorFromPath (bundlePath string , hostSpecific bool ) (Validator , error ) {
64+ func NewValidatorFromPath (bundlePath string , hostSpecific bool , platform string ) (Validator , error ) {
5965 if bundlePath == "" {
6066 return Validator {}, fmt .Errorf ("Bundle path shouldn't be empty" )
6167 }
@@ -77,18 +83,17 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool) (Validator, erro
7783 return Validator {}, err
7884 }
7985
80- return NewValidator (& spec , bundlePath , hostSpecific ), nil
86+ return NewValidator (& spec , bundlePath , hostSpecific , platform ), nil
8187}
8288
8389// CheckAll checks all parts of runtime bundle
8490func (v * Validator ) CheckAll () (msgs []string ) {
91+ msgs = append (msgs , v .CheckPlatform ()... )
8592 msgs = append (msgs , v .CheckRootfsPath ()... )
8693 msgs = append (msgs , v .CheckMandatoryFields ()... )
8794 msgs = append (msgs , v .CheckSemVer ()... )
8895 msgs = append (msgs , v .CheckMounts ()... )
89- msgs = append (msgs , v .CheckPlatform ()... )
9096 msgs = append (msgs , v .CheckProcess ()... )
91- msgs = append (msgs , v .CheckOS ()... )
9297 msgs = append (msgs , v .CheckHooks ()... )
9398 if v .spec .Linux != nil {
9499 msgs = append (msgs , v .CheckLinux ()... )
@@ -131,9 +136,9 @@ func (v *Validator) CheckRootfsPath() (msgs []string) {
131136 msgs = append (msgs , fmt .Sprintf ("root.path is %q, but it MUST be a child of %q" , v .spec .Root .Path , absBundlePath ))
132137 }
133138
134- if v .spec . Platform . OS == "windows" {
139+ if v .platform == "windows" {
135140 if v .spec .Root .Readonly {
136- msgs = append (msgs , "root.readonly field MUST be omitted or false when platform.os is windows" )
141+ msgs = append (msgs , "root.readonly field MUST be omitted or false when target platform is windows" )
137142 }
138143 }
139144
@@ -156,37 +161,6 @@ func (v *Validator) CheckSemVer() (msgs []string) {
156161 return
157162}
158163
159- // CheckPlatform checks v.spec.Platform
160- func (v * Validator ) CheckPlatform () (msgs []string ) {
161- logrus .Debugf ("check platform" )
162-
163- validCombins := map [string ][]string {
164- "android" : {"arm" },
165- "darwin" : {"386" , "amd64" , "arm" , "arm64" },
166- "dragonfly" : {"amd64" },
167- "freebsd" : {"386" , "amd64" , "arm" },
168- "linux" : {"386" , "amd64" , "arm" , "arm64" , "mips" , "mips64" , "mips64le" , "mipsle" , "ppc64" , "ppc64le" , "s390x" },
169- "netbsd" : {"386" , "amd64" , "arm" },
170- "openbsd" : {"386" , "amd64" , "arm" },
171- "plan9" : {"386" , "amd64" },
172- "solaris" : {"amd64" },
173- "windows" : {"386" , "amd64" }}
174- platform := v .spec .Platform
175- for os , archs := range validCombins {
176- if os == platform .OS {
177- for _ , arch := range archs {
178- if arch == platform .Arch {
179- return nil
180- }
181- }
182- msgs = append (msgs , fmt .Sprintf ("Combination of %q and %q is invalid." , platform .OS , platform .Arch ))
183- }
184- }
185- msgs = append (msgs , fmt .Sprintf ("Operation system %q of the bundle is not supported yet." , platform .OS ))
186-
187- return
188- }
189-
190164// CheckHooks check v.spec.Hooks
191165func (v * Validator ) CheckHooks () (msgs []string ) {
192166 logrus .Debugf ("check hooks" )
@@ -271,8 +245,7 @@ func (v *Validator) CheckProcess() (msgs []string) {
271245 }
272246 msgs = append (msgs , v .CheckRlimits ()... )
273247
274- if v .spec .Platform .OS == "linux" {
275-
248+ if v .platform == "linux" {
276249 if len (process .ApparmorProfile ) > 0 {
277250 profilePath := filepath .Join (v .bundlePath , v .spec .Root .Path , "/etc/apparmor.d" , process .ApparmorProfile )
278251 _ , err := os .Stat (profilePath )
@@ -288,7 +261,7 @@ func (v *Validator) CheckProcess() (msgs []string) {
288261// CheckCapabilities checks v.spec.Process.Capabilities
289262func (v * Validator ) CheckCapabilities () (msgs []string ) {
290263 process := v .spec .Process
291- if v .spec . Platform . OS == "linux" {
264+ if v .platform == "linux" {
292265 var effective , permitted , inheritable , ambient bool
293266 caps := make (map [string ][]string )
294267
@@ -336,7 +309,7 @@ func (v *Validator) CheckCapabilities() (msgs []string) {
336309 }
337310 }
338311 } else {
339- logrus .Warnf ("process.capabilities validation not yet implemented for OS %q" , v .spec . Platform . OS )
312+ logrus .Warnf ("process.capabilities validation not yet implemented for OS %q" , v .platform )
340313 }
341314
342315 return
@@ -402,7 +375,7 @@ func supportedMountTypes(OS string, hostSpecific bool) (map[string]bool, error)
402375func (v * Validator ) CheckMounts () (msgs []string ) {
403376 logrus .Debugf ("check mounts" )
404377
405- supportedTypes , err := supportedMountTypes (v .spec . Platform . OS , v .HostSpecific )
378+ supportedTypes , err := supportedMountTypes (v .platform , v .HostSpecific )
406379 if err != nil {
407380 msgs = append (msgs , err .Error ())
408381 return
@@ -423,25 +396,30 @@ func (v *Validator) CheckMounts() (msgs []string) {
423396 return
424397}
425398
426- // CheckOS checks v.spec.Platform.OS
427- func (v * Validator ) CheckOS () (msgs []string ) {
428- logrus .Debugf ("check os" )
399+ // CheckPlatform checks v.platform
400+ func (v * Validator ) CheckPlatform () (msgs []string ) {
401+ logrus .Debugf ("check platform" )
402+
403+ if v .platform != "linux" && v .platform != "solaris" && v .platform != "windows" {
404+ msgs = append (msgs , fmt .Sprintf ("platform %q is not supported" , v .platform ))
405+ return
406+ }
429407
430- if v .spec . Platform . OS != "linux" {
408+ if v .platform != "linux" {
431409 if v .spec .Linux != nil {
432- msgs = append (msgs , fmt .Sprintf ("'linux' MUST NOT be set when platform.os is %q" , v .spec . Platform . OS ))
410+ msgs = append (msgs , fmt .Sprintf ("'linux' MUST NOT be set when target platform is %q" , v .platform ))
433411 }
434412 }
435413
436- if v .spec . Platform . OS != "solaris" {
414+ if v .platform != "solaris" {
437415 if v .spec .Solaris != nil {
438- msgs = append (msgs , fmt .Sprintf ("'solaris' MUST NOT be set when platform.os is %q" , v .spec . Platform . OS ))
416+ msgs = append (msgs , fmt .Sprintf ("'solaris' MUST NOT be set when target platform is %q" , v .platform ))
439417 }
440418 }
441419
442- if v .spec . Platform . OS != "windows" {
420+ if v .platform != "windows" {
443421 if v .spec .Windows != nil {
444- msgs = append (msgs , fmt .Sprintf ("'windows' MUST NOT be set when platform.os is %q" , v .spec . Platform . OS ))
422+ msgs = append (msgs , fmt .Sprintf ("'windows' MUST NOT be set when target platform is %q" , v .platform ))
445423 }
446424 }
447425
@@ -502,7 +480,7 @@ func (v *Validator) CheckLinux() (msgs []string) {
502480 }
503481 }
504482
505- if v .spec . Platform . OS == "linux" && ! typeList [rspec .UTSNamespace ].newExist && v .spec .Hostname != "" {
483+ if v .platform == "linux" && ! typeList [rspec .UTSNamespace ].newExist && v .spec .Hostname != "" {
506484 msgs = append (msgs , fmt .Sprintf ("On Linux, hostname requires a new UTS namespace to be specified as well" ))
507485 }
508486
@@ -684,15 +662,15 @@ func (v *Validator) rlimitValid(rlimit rspec.LinuxRlimit) (msgs []string) {
684662 msgs = append (msgs , fmt .Sprintf ("hard limit of rlimit %s should not be less than soft limit" , rlimit .Type ))
685663 }
686664
687- if v .spec . Platform . OS == "linux" {
665+ if v .platform == "linux" {
688666 for _ , val := range defaultRlimits {
689667 if val == rlimit .Type {
690668 return
691669 }
692670 }
693671 msgs = append (msgs , fmt .Sprintf ("rlimit type %q is invalid" , rlimit .Type ))
694672 } else {
695- logrus .Warnf ("process.rlimits validation not yet implemented for OS %q" , v .spec . Platform . OS )
673+ logrus .Warnf ("process.rlimits validation not yet implemented for platform %q" , v .platform )
696674 }
697675
698676 return
0 commit comments