Allow additional arguments to be passed into hooks
If a packager wants to be able to support addititional arguments on his hook this will allow them to setup the configuration with these arguments. For example this would allow a hook developer to add support for a --debug flag to change the level of debugging in his hook. In order to complete this task, I had to vendor in the latest github.com://opencontainers/runtime-tools, which caused me to have to fix a Mount and Capability interface calls Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
41aaf4e3d8
commit
23d20c9db5
45 changed files with 7145 additions and 672 deletions
113
vendor/github.com/opencontainers/runtime-tools/specerror/error.go
generated
vendored
113
vendor/github.com/opencontainers/runtime-tools/specerror/error.go
generated
vendored
|
@ -13,46 +13,13 @@ const referenceTemplate = "https://github.com/opencontainers/runtime-spec/blob/v
|
|||
|
||||
// Code represents the spec violation, enumerating both
|
||||
// configuration violations and runtime violations.
|
||||
type Code int
|
||||
type Code int64
|
||||
|
||||
const (
|
||||
// NonError represents that an input is not an error
|
||||
NonError Code = iota
|
||||
NonError Code = 0x1a001 + iota
|
||||
// NonRFCError represents that an error is not a rfc2119 error
|
||||
NonRFCError
|
||||
|
||||
// ConfigFileExistence represents the error code of 'config.json' existence test
|
||||
ConfigFileExistence
|
||||
// ArtifactsInSingleDir represents the error code of artifacts place test
|
||||
ArtifactsInSingleDir
|
||||
|
||||
// SpecVersion represents the error code of specfication version test
|
||||
SpecVersion
|
||||
|
||||
// RootOnNonHyperV represents the error code of root setting test on non hyper-v containers
|
||||
RootOnNonHyperV
|
||||
// RootOnHyperV represents the error code of root setting test on hyper-v containers
|
||||
RootOnHyperV
|
||||
// PathFormatOnWindows represents the error code of the path format test on Window
|
||||
PathFormatOnWindows
|
||||
// PathName represents the error code of the path name test
|
||||
PathName
|
||||
// PathExistence represents the error code of the path existence test
|
||||
PathExistence
|
||||
// ReadonlyFilesystem represents the error code of readonly test
|
||||
ReadonlyFilesystem
|
||||
// ReadonlyOnWindows represents the error code of readonly setting test on Windows
|
||||
ReadonlyOnWindows
|
||||
|
||||
// DefaultFilesystems represents the error code of default filesystems test
|
||||
DefaultFilesystems
|
||||
|
||||
// CreateWithID represents the error code of 'create' lifecyle test with 'id' provided
|
||||
CreateWithID
|
||||
// CreateWithUniqueID represents the error code of 'create' lifecyle test with unique 'id' provided
|
||||
CreateWithUniqueID
|
||||
// CreateNewContainer represents the error code 'create' lifecyle test that creates new container
|
||||
CreateNewContainer
|
||||
)
|
||||
|
||||
type errorTemplate struct {
|
||||
|
@ -69,52 +36,24 @@ type Error struct {
|
|||
Code Code
|
||||
}
|
||||
|
||||
var (
|
||||
containerFormatRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "bundle.md#container-format"), nil
|
||||
}
|
||||
specVersionRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#specification-version"), nil
|
||||
}
|
||||
rootRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config.md#root"), nil
|
||||
}
|
||||
defaultFSRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "config-linux.md#default-filesystems"), nil
|
||||
}
|
||||
runtimeCreateRef = func(version string) (reference string, err error) {
|
||||
return fmt.Sprintf(referenceTemplate, version, "runtime.md#create"), nil
|
||||
}
|
||||
)
|
||||
// LevelErrors represents Errors filtered into fatal and warnings.
|
||||
type LevelErrors struct {
|
||||
// Warnings holds Errors that were below a compliance-level threshold.
|
||||
Warnings []*Error
|
||||
|
||||
var ociErrors = map[Code]errorTemplate{
|
||||
// Bundle.md
|
||||
// Container Format
|
||||
ConfigFileExistence: {Level: rfc2119.Must, Reference: containerFormatRef},
|
||||
ArtifactsInSingleDir: {Level: rfc2119.Must, Reference: containerFormatRef},
|
||||
// Error holds errors that were at or above a compliance-level
|
||||
// threshold, as well as errors that are not Errors.
|
||||
Error *multierror.Error
|
||||
}
|
||||
|
||||
// Config.md
|
||||
// Specification Version
|
||||
SpecVersion: {Level: rfc2119.Must, Reference: specVersionRef},
|
||||
// Root
|
||||
RootOnNonHyperV: {Level: rfc2119.Required, Reference: rootRef},
|
||||
RootOnHyperV: {Level: rfc2119.Must, Reference: rootRef},
|
||||
// TODO: add tests for 'PathFormatOnWindows'
|
||||
PathFormatOnWindows: {Level: rfc2119.Must, Reference: rootRef},
|
||||
PathName: {Level: rfc2119.Should, Reference: rootRef},
|
||||
PathExistence: {Level: rfc2119.Must, Reference: rootRef},
|
||||
ReadonlyFilesystem: {Level: rfc2119.Must, Reference: rootRef},
|
||||
ReadonlyOnWindows: {Level: rfc2119.Must, Reference: rootRef},
|
||||
var ociErrors = map[Code]errorTemplate{}
|
||||
|
||||
// Config-Linux.md
|
||||
// Default Filesystems
|
||||
DefaultFilesystems: {Level: rfc2119.Should, Reference: defaultFSRef},
|
||||
func register(code Code, level rfc2119.Level, ref func(versiong string) (string, error)) {
|
||||
if _, ok := ociErrors[code]; ok {
|
||||
panic(fmt.Sprintf("should not regist a same code twice: %v", code))
|
||||
}
|
||||
|
||||
// Runtime.md
|
||||
// Create
|
||||
CreateWithID: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
CreateWithUniqueID: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
CreateNewContainer: {Level: rfc2119.Must, Reference: runtimeCreateRef},
|
||||
ociErrors[code] = errorTemplate{Level: level, Reference: ref}
|
||||
}
|
||||
|
||||
// Error returns the error message with specification reference.
|
||||
|
@ -168,3 +107,23 @@ func FindError(err error, code Code) Code {
|
|||
}
|
||||
return NonRFCError
|
||||
}
|
||||
|
||||
// SplitLevel removes RFC 2119 errors with a level less than 'level'
|
||||
// from the source error. If the source error is not a multierror, it
|
||||
// is returned unchanged.
|
||||
func SplitLevel(errIn error, level rfc2119.Level) (levelErrors LevelErrors, errOut error) {
|
||||
merr, ok := errIn.(*multierror.Error)
|
||||
if !ok {
|
||||
return levelErrors, errIn
|
||||
}
|
||||
for _, err := range merr.Errors {
|
||||
e, ok := err.(*Error)
|
||||
if ok && e.Err.Level < level {
|
||||
fmt.Println(e)
|
||||
levelErrors.Warnings = append(levelErrors.Warnings, e)
|
||||
continue
|
||||
}
|
||||
levelErrors.Error = multierror.Append(levelErrors.Error, err)
|
||||
}
|
||||
return levelErrors, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue