@@ -57,16 +57,19 @@ var (
5757 }
5858)
5959
60+ // Validator represents a validator for runtime bundle
6061type Validator struct {
6162 spec * rspec.Spec
6263 bundlePath string
6364 HostSpecific bool
6465}
6566
67+ // NewValidator creates a Validator
6668func NewValidator (spec * rspec.Spec , bundlePath string , hostSpecific bool ) Validator {
6769 return Validator {spec : spec , bundlePath : bundlePath , HostSpecific : hostSpecific }
6870}
6971
72+ // NewValidatorFromPath creates a Validator with specified bundle path
7073func NewValidatorFromPath (bundlePath string , hostSpecific bool ) (Validator , error ) {
7174 if bundlePath == "" {
7275 return Validator {}, fmt .Errorf ("Bundle path shouldn't be empty" )
@@ -92,6 +95,7 @@ func NewValidatorFromPath(bundlePath string, hostSpecific bool) (Validator, erro
9295 return NewValidator (& spec , bundlePath , hostSpecific ), nil
9396}
9497
98+ // CheckAll checks all parts of runtime bundle
9599func (v * Validator ) CheckAll () (msgs []string ) {
96100 msgs = append (msgs , v .CheckRootfsPath ()... )
97101 msgs = append (msgs , v .CheckMandatoryFields ()... )
@@ -105,6 +109,7 @@ func (v *Validator) CheckAll() (msgs []string) {
105109 return
106110}
107111
112+ // CheckRootfsPath checks status of v.spec.Root.Path
108113func (v * Validator ) CheckRootfsPath () (msgs []string ) {
109114 logrus .Debugf ("check rootfs path" )
110115
@@ -124,6 +129,8 @@ func (v *Validator) CheckRootfsPath() (msgs []string) {
124129 return
125130
126131}
132+
133+ // CheckSemVer checks v.spec.Version
127134func (v * Validator ) CheckSemVer () (msgs []string ) {
128135 logrus .Debugf ("check semver" )
129136
@@ -139,6 +146,7 @@ func (v *Validator) CheckSemVer() (msgs []string) {
139146 return
140147}
141148
149+ // CheckPlatform checks v.spec.Platform
142150func (v * Validator ) CheckPlatform () (msgs []string ) {
143151 logrus .Debugf ("check platform" )
144152
@@ -169,6 +177,7 @@ func (v *Validator) CheckPlatform() (msgs []string) {
169177 return
170178}
171179
180+ // CheckHooks check v.spec.Hooks
172181func (v * Validator ) CheckHooks () (msgs []string ) {
173182 logrus .Debugf ("check hooks" )
174183
@@ -205,6 +214,7 @@ func checkEventHooks(hookType string, hooks []rspec.Hook, hostSpecific bool) (ms
205214 return
206215}
207216
217+ // CheckProcess checks v.spec.Process
208218func (v * Validator ) CheckProcess () (msgs []string ) {
209219 logrus .Debugf ("check process" )
210220
@@ -308,6 +318,7 @@ func supportedMountTypes(OS string, hostSpecific bool) (map[string]bool, error)
308318 return nil , nil
309319}
310320
321+ // CheckMounts checks v.spec.Mounts
311322func (v * Validator ) CheckMounts () (msgs []string ) {
312323 logrus .Debugf ("check mounts" )
313324
@@ -332,7 +343,7 @@ func (v *Validator) CheckMounts() (msgs []string) {
332343 return
333344}
334345
335- //Linux only
346+ // CheckLinux checks v.spec.Linux
336347func (v * Validator ) CheckLinux () (msgs []string ) {
337348 logrus .Debugf ("check linux" )
338349
@@ -426,6 +437,7 @@ func (v *Validator) CheckLinux() (msgs []string) {
426437 return
427438}
428439
440+ // CheckLinuxResources checks v.spec.Linux.Resources
429441func (v * Validator ) CheckLinuxResources () (msgs []string ) {
430442 logrus .Debugf ("check linux resources" )
431443
@@ -442,6 +454,7 @@ func (v *Validator) CheckLinuxResources() (msgs []string) {
442454 return
443455}
444456
457+ // CheckSeccomp checkc v.spec.Linux.Seccomp
445458func (v * Validator ) CheckSeccomp () (msgs []string ) {
446459 logrus .Debugf ("check linux seccomp" )
447460
@@ -480,6 +493,7 @@ func (v *Validator) CheckSeccomp() (msgs []string) {
480493 return
481494}
482495
496+ // CapValid checks whether a capability is valid
483497func CapValid (c string , hostSpecific bool ) error {
484498 isValid := false
485499
@@ -502,6 +516,7 @@ func CapValid(c string, hostSpecific bool) error {
502516 return nil
503517}
504518
519+ // LastCap return last cap of system
505520func LastCap () capability.Cap {
506521 last := capability .CAP_LAST_CAP
507522 // hack for RHEL6 which has no /proc/sys/kernel/cap_last_cap
@@ -529,15 +544,15 @@ func envValid(env string) bool {
529544}
530545
531546func rlimitValid (rlimit rspec.Rlimit ) error {
547+ if rlimit .Hard < rlimit .Soft {
548+ return fmt .Errorf ("hard limit of rlimit %s should not be less than soft limit" , rlimit .Type )
549+ }
532550 for _ , val := range defaultRlimits {
533551 if val == rlimit .Type {
534- if rlimit .Hard < rlimit .Soft {
535- return fmt .Errorf ("hard limit of rlimit %s should not be less than soft limit." , rlimit .Type )
536- }
537552 return nil
538553 }
539554 }
540- return fmt .Errorf ("rlimit type %q is invalid. " , rlimit .Type )
555+ return fmt .Errorf ("rlimit type %q is invalid" , rlimit .Type )
541556}
542557
543558func namespaceValid (ns rspec.Namespace ) bool {
@@ -685,6 +700,7 @@ func checkMandatory(obj interface{}) (msgs []string) {
685700 return
686701}
687702
703+ // CheckMandatoryFields checks mandatory field of container's config file
688704func (v * Validator ) CheckMandatoryFields () []string {
689705 logrus .Debugf ("check mandatory fields" )
690706
0 commit comments