configs/validate: audit all returned errors
All the errors returned from Validate should tell about a configuration
error. Some were lacking a context, so add it.
While at it, fix abusing fmt.Errorf and logrus.Warnf where the argument
do not contain %-style formatting.
@@ -52,7 +52,7 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
}
for _, c := range warns {
if err := c(config); err != nil {
- logrus.WithError(err).Warnf("invalid configuration")
+ logrus.WithError(err).Warn("invalid configuration")
}
}
return nil
@@ -62,20 +62,17 @@ func (v *ConfigValidator) Validate(config *configs.Config) error {
// to the container's root filesystem.
func (v *ConfigValidator) rootfs(config *configs.Config) error {
if _, err := os.Stat(config.Rootfs); err != nil {
- if os.IsNotExist(err) {
- return fmt.Errorf("rootfs (%s) does not exist", config.Rootfs)
- }
- return err
+ return fmt.Errorf("invalid rootfs: %w", err)
}
cleaned, err := filepath.Abs(config.Rootfs)
if err != nil {
- return err
+ return fmt.Errorf("invalid rootfs: %w", err)
}
if cleaned, err = filepath.EvalSymlinks(cleaned); err != nil {
- return err
+ return fmt.Errorf("invalid rootfs: %w", err)
}
if filepath.Clean(config.Rootfs) != cleaned {
- return fmt.Errorf("%s is not an absolute path or is a symlink", config.Rootfs)
+ return errors.New("invalid rootfs: not an absolute path, or a symlink")
}
return nil
}
@@ -176,7 +173,7 @@ func (v *ConfigValidator) sysctl(config *configs.Config) error {
hostnet, hostnetErr = isHostNetNS(path)
})
if hostnetErr != nil {
- return hostnetErr
+ return fmt.Errorf("invalid netns path: %w", hostnetErr)
}
if hostnet {
return fmt.Errorf("sysctl %q not allowed in host network namespace", s)
