Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,19 @@ func validateDefaultSymlinks(spec *rspec.Spec) error {
return err
}
if fi.Mode()&os.ModeSymlink != os.ModeSymlink {
return fmt.Errorf("%v is not a symbolic link as expected", symlink)
return specerror.NewError(specerror.DefaultRuntimeLinuxSymlinks,
fmt.Errorf("%v is not a symbolic link as expected", symlink),
rspec.Version)
}
realDest, err := os.Readlink(symlink)
if err != nil {
return err
}
if realDest != dest {
return fmt.Errorf("link destation of %v expected is %v, actual is %v", symlink, dest, realDest)
return specerror.NewError(specerror.DefaultRuntimeLinuxSymlinks,
fmt.Errorf("link destation of %v expected is %v, actual is %v",
symlink, dest, realDest),
rspec.Version)
}
}

Expand All @@ -447,12 +452,16 @@ func validateDefaultDevices(spec *rspec.Spec) error {
fi, err := os.Stat(device)
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("device node %v not found", device)
return specerror.NewError(specerror.DefaultDevices,
fmt.Errorf("device node %v not found", device),
rspec.Version)
}
return err
}
if fi.Mode()&os.ModeDevice != os.ModeDevice {
return fmt.Errorf("file %v is not a device as expected", device)
return specerror.NewError(specerror.DefaultDevices,
fmt.Errorf("file %v is not a device as expected", device),
rspec.Version)
}
}

Expand Down Expand Up @@ -512,7 +521,7 @@ func validateOOMScoreAdj(spec *rspec.Spec) error {
return err
}
if actual != expected {
return fmt.Errorf("oomScoreAdj expected: %v, actual: %v", expected, actual)
return specerror.NewError(specerror.LinuxProcOomScoreAdjSet, fmt.Errorf("oomScoreAdj expected: %v, actual: %v", expected, actual), rspec.Version)
}
}
}
Expand Down Expand Up @@ -667,14 +676,21 @@ func validateMounts(spec *rspec.Spec) error {
if found {
mountErrs = multierror.Append(
mountErrs,
fmt.Errorf(
"mounts[%d] %v mounted before mounts[%d] %v",
i,
configMount,
highestMatchedConfig,
spec.Mounts[highestMatchedConfig]))
specerror.NewError(specerror.MountsInOrder,
fmt.Errorf(
"mounts[%d] %v mounted before mounts[%d] %v",
i,
configMount,
highestMatchedConfig,
spec.Mounts[highestMatchedConfig]),
rspec.Version))
} else {
mountErrs = multierror.Append(mountErrs, fmt.Errorf("mounts[%d] %v does not exist", i, configMount))
mountErrs = multierror.Append(
mountErrs,
specerror.NewError(specerror.MountsInOrder, fmt.Errorf(
"mounts[%d] %v does not exist",
i,
configMount), rspec.Version))
}
}
}
Expand Down
61 changes: 51 additions & 10 deletions validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (v *Validator) CheckAll() error {
func JSONSchemaURL(version string) (url string, err error) {
ver, err := semver.Parse(version)
if err != nil {
return "", err
return "", specerror.NewError(specerror.SpecVersionInSemVer, err, rspec.Version)
}
configRenamedToConfigSchemaVersion, err := semver.Parse("1.0.0-rc2") // config.json became config-schema.json in 1.0.0-rc2
if ver.Compare(configRenamedToConfigSchemaVersion) == -1 {
Expand Down Expand Up @@ -276,7 +276,12 @@ func (v *Validator) CheckHooks() (errs error) {
func (v *Validator) checkEventHooks(hookType string, hooks []rspec.Hook, hostSpecific bool) (errs error) {
for i, hook := range hooks {
if !osFilepath.IsAbs(v.platform, hook.Path) {
errs = multierror.Append(errs, fmt.Errorf("hooks.%s[%d].path %v: is not absolute path", hookType, i, hook.Path))
errs = multierror.Append(errs,
specerror.NewError(
specerror.PosixHooksPathAbs,
fmt.Errorf("hooks.%s[%d].path %v: is not absolute path",
hookType, i, hook.Path),
rspec.Version))
}

if hostSpecific {
Expand Down Expand Up @@ -309,7 +314,11 @@ func (v *Validator) CheckProcess() (errs error) {

process := v.spec.Process
if !osFilepath.IsAbs(v.platform, process.Cwd) {
errs = multierror.Append(errs, fmt.Errorf("cwd %q is not an absolute path", process.Cwd))
errs = multierror.Append(errs,
specerror.NewError(
specerror.ProcCwdAbs,
fmt.Errorf("cwd %q is not an absolute path", process.Cwd),
rspec.Version))
}

for _, env := range process.Env {
Expand All @@ -319,7 +328,11 @@ func (v *Validator) CheckProcess() (errs error) {
}

if len(process.Args) == 0 {
errs = multierror.Append(errs, fmt.Errorf("args must not be empty"))
errs = multierror.Append(errs,
specerror.NewError(
specerror.ProcArgsOneEntryRequired,
fmt.Errorf("args must not be empty"),
rspec.Version))
} else {
if filepath.IsAbs(process.Args[0]) {
var rootfsPath string
Expand Down Expand Up @@ -432,7 +445,12 @@ func (v *Validator) CheckRlimits() (errs error) {
for index, rlimit := range process.Rlimits {
for i := index + 1; i < len(process.Rlimits); i++ {
if process.Rlimits[index].Type == process.Rlimits[i].Type {
errs = multierror.Append(errs, fmt.Errorf("rlimit can not contain the same type %q", process.Rlimits[index].Type))
errs = multierror.Append(errs,
specerror.NewError(
specerror.PosixProcRlimitsErrorOnDup,
fmt.Errorf("rlimit can not contain the same type %q",
process.Rlimits[index].Type),
rspec.Version))
}
}
errs = multierror.Append(errs, v.rlimitValid(rlimit))
Expand Down Expand Up @@ -497,7 +515,13 @@ func (v *Validator) CheckMounts() (errs error) {
errs = multierror.Append(errs, fmt.Errorf("unsupported mount type %q", mountA.Type))
}
if !osFilepath.IsAbs(v.platform, mountA.Destination) {
errs = multierror.Append(errs, fmt.Errorf("mounts[%d].destination %q is not absolute", i, mountA.Destination))
errs = multierror.Append(errs,
specerror.NewError(
specerror.MountsDestAbs,
fmt.Errorf("mounts[%d].destination %q is not absolute",
i,
mountA.Destination),
rspec.Version))
}
for j, mountB := range v.spec.Mounts {
if i == j {
Expand All @@ -511,7 +535,12 @@ func (v *Validator) CheckMounts() (errs error) {
}
if nested {
if v.platform == "windows" && i < j {
errs = multierror.Append(errs, fmt.Errorf("on Windows, %v nested within %v is forbidden", mountB.Destination, mountA.Destination))
errs = multierror.Append(errs,
specerror.NewError(
specerror.MountsDestOnWindowsNotNested,
fmt.Errorf("on Windows, %v nested within %v is forbidden",
mountB.Destination, mountA.Destination),
rspec.Version))
}
if i > j {
logrus.Warnf("%v will be covered by %v", mountB.Destination, mountA.Destination)
Expand All @@ -534,7 +563,11 @@ func (v *Validator) CheckPlatform() (errs error) {

if v.platform == "windows" {
if v.spec.Windows == nil {
errs = multierror.Append(errs, errors.New("'windows' MUST be set when platform is `windows`"))
errs = multierror.Append(errs,
specerror.NewError(
specerror.PlatformSpecConfOnWindowsSet,
fmt.Errorf("'windows' MUST be set when platform is `windows`"),
rspec.Version))
}
}

Expand Down Expand Up @@ -705,13 +738,21 @@ func (v *Validator) CheckLinux() (errs error) {

for _, maskedPath := range v.spec.Linux.MaskedPaths {
if !strings.HasPrefix(maskedPath, "/") {
errs = multierror.Append(errs, fmt.Errorf("maskedPath %v is not an absolute path", maskedPath))
errs = multierror.Append(errs,
specerror.NewError(
specerror.MaskedPathsAbs,
fmt.Errorf("maskedPath %v is not an absolute path", maskedPath),
rspec.Version))
}
}

for _, readonlyPath := range v.spec.Linux.ReadonlyPaths {
if !strings.HasPrefix(readonlyPath, "/") {
errs = multierror.Append(errs, fmt.Errorf("readonlyPath %v is not an absolute path", readonlyPath))
errs = multierror.Append(errs,
specerror.NewError(
specerror.ReadonlyPathsAbs,
fmt.Errorf("readonlyPath %v is not an absolute path", readonlyPath),
rspec.Version))
}
}

Expand Down
2 changes: 1 addition & 1 deletion validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestJSONSchema(t *testing.T) {
}{
{
config: &rspec.Spec{},
error: "Version string empty",
error: "1 error occurred:\n\n* Version string empty\nRefer to: https://github.com/opencontainers/runtime-spec/blob/v1.0.0/config.md#specification-version",
},
{
config: &rspec.Spec{
Expand Down