github.com/opencontainers/runtime-tools@v0.9.0/specerror/config.go (about)

     1  package specerror
     2  
     3  import (
     4  	"fmt"
     5  
     6  	rfc2119 "github.com/opencontainers/runtime-tools/error"
     7  )
     8  
     9  // define error codes
    10  const (
    11  	// SpecVersionInSemVer represents "`ociVersion` (string, REQUIRED) MUST be in SemVer v2.0.0 format and specifies the version of the Open Container Initiative Runtime Specification with which the bundle complies."
    12  	SpecVersionInSemVer Code = 0xb001 + iota
    13  	// RootOnWindowsRequired represents "On Windows, for Windows Server Containers, this field is REQUIRED."
    14  	RootOnWindowsRequired
    15  	// RootOnHyperVNotSet represents "For Hyper-V Containers, this field MUST NOT be set."
    16  	RootOnHyperVNotSet
    17  	// RootOnNonWindowsRequired represents "On all other platforms, this field is REQUIRED."
    18  	RootOnNonWindowsRequired
    19  	// RootPathOnWindowsGUID represents "On Windows, `path` MUST be a volume GUID path."
    20  	RootPathOnWindowsGUID
    21  	// RootPathOnPosixConvention represents "The value SHOULD be the conventional `rootfs`."
    22  	RootPathOnPosixConvention
    23  	// RootPathExist represents "A directory MUST exist at the path declared by the field."
    24  	RootPathExist
    25  	// RootReadonlyImplement represents "`readonly` (bool, OPTIONAL) If true then the root filesystem MUST be read-only inside the container, defaults to false."
    26  	RootReadonlyImplement
    27  	// RootReadonlyOnWindowsFalse represents "* On Windows, this field MUST be omitted or false."
    28  	RootReadonlyOnWindowsFalse
    29  	// MountsInOrder represents "The runtime MUST mount entries in the listed order."
    30  	MountsInOrder
    31  	// MountsDestAbs represents "Destination of mount point: path inside container. This value MUST be an absolute path."
    32  	MountsDestAbs
    33  	// MountsDestOnWindowsNotNested represents "Windows: one mount destination MUST NOT be nested within another mount (e.g., c:\\foo and c:\\foo\\bar)."
    34  	MountsDestOnWindowsNotNested
    35  	// MountsOptionsOnWindowsROSupport represents "Windows: runtimes MUST support `ro`, mounting the filesystem read-only when `ro` is given."
    36  	MountsOptionsOnWindowsROSupport
    37  	// ProcRequiredAtStart represents "This property is REQUIRED when `start` is called."
    38  	ProcRequiredAtStart
    39  	// ProcConsoleSizeIgnore represents "Runtimes MUST ignore `consoleSize` if `terminal` is `false` or unset."
    40  	ProcConsoleSizeIgnore
    41  	// ProcCwdAbs represents "cwd (string, REQUIRED) is the working directory that will be set for the executable. This value MUST be an absolute path."
    42  	ProcCwdAbs
    43  	// ProcArgsOneEntryRequired represents "This specification extends the IEEE standard in that at least one entry is REQUIRED, and that entry is used with the same semantics as `execvp`'s *file*."
    44  	ProcArgsOneEntryRequired
    45  	// PosixProcRlimitsTypeGenError represents "The runtime MUST generate an error for any values which cannot be mapped to a relevant kernel interface."
    46  	PosixProcRlimitsTypeGenError
    47  	// PosixProcRlimitsTypeGet represents "For each entry in `rlimits`, a `getrlimit(3)` on `type` MUST succeed."
    48  	PosixProcRlimitsTypeGet
    49  	// PosixProcRlimitsTypeValueError represents "valid values are defined in the ... man page"
    50  	PosixProcRlimitsTypeValueError
    51  	// PosixProcRlimitsSoftMatchCur represents "`rlim.rlim_cur` MUST match the configured value."
    52  	PosixProcRlimitsSoftMatchCur
    53  	// PosixProcRlimitsHardMatchMax represents "`rlim.rlim_max` MUST match the configured value."
    54  	PosixProcRlimitsHardMatchMax
    55  	// PosixProcRlimitsErrorOnDup represents "If `rlimits` contains duplicated entries with same `type`, the runtime MUST generate an error."
    56  	PosixProcRlimitsErrorOnDup
    57  	// LinuxProcCapError represents "Any value which cannot be mapped to a relevant kernel interface MUST cause an error."
    58  	LinuxProcCapError
    59  	// LinuxProcOomScoreAdjSet represents "If `oomScoreAdj` is set, the runtime MUST set `oom_score_adj` to the given value."
    60  	LinuxProcOomScoreAdjSet
    61  	// LinuxProcOomScoreAdjNotSet represents "If `oomScoreAdj` is not set, the runtime MUST NOT change the value of `oom_score_adj`."
    62  	LinuxProcOomScoreAdjNotSet
    63  	// PlatformSpecConfOnWindowsSet represents "This MUST be set if the target platform of this spec is `windows`."
    64  	PlatformSpecConfOnWindowsSet
    65  	// PosixHooksPathAbs represents "This specification extends the IEEE standard in that `path` MUST be absolute."
    66  	PosixHooksPathAbs
    67  	// PosixHooksTimeoutPositive represents "If set, `timeout` MUST be greater than zero."
    68  	PosixHooksTimeoutPositive
    69  	// PosixHooksCalledInOrder represents "Hooks MUST be called in the listed order."
    70  	PosixHooksCalledInOrder
    71  	// PosixHooksStateToStdin represents "The state of the container MUST be passed to hooks over stdin so that they may do work appropriate to the current state of the container."
    72  	PosixHooksStateToStdin
    73  	// PrestartTiming represents "The pre-start hooks MUST be called after the `start` operation is called but before the user-specified program command is executed."
    74  	PrestartTiming
    75  	// PoststartTiming represents "The post-start hooks MUST be called after the user-specified process is executed but before the `start` operation returns."
    76  	PoststartTiming
    77  	// PoststopTiming represents "The post-stop hooks MUST be called after the container is deleted but before the `delete` operation returns."
    78  	PoststopTiming
    79  	// AnnotationsKeyValueMap represents "Annotations MUST be a key-value map."
    80  	AnnotationsKeyValueMap
    81  	// AnnotationsKeyString represents "Keys MUST be strings."
    82  	AnnotationsKeyString
    83  	// AnnotationsKeyRequired represents "Keys MUST NOT be an empty string."
    84  	AnnotationsKeyRequired
    85  	// AnnotationsKeyReversedDomain represents "Keys SHOULD be named using a reverse domain notation - e.g. `com.example.myKey`."
    86  	AnnotationsKeyReversedDomain
    87  	// AnnotationsKeyReservedNS represents "Keys using the `org.opencontainers` namespace are reserved and MUST NOT be used by subsequent specifications."
    88  	AnnotationsKeyReservedNS
    89  	// AnnotationsKeyIgnoreUnknown represents "Implementations that are reading/processing this configuration file MUST NOT generate an error if they encounter an unknown annotation key."
    90  	AnnotationsKeyIgnoreUnknown
    91  	// AnnotationsValueString represents "Values MUST be strings."
    92  	AnnotationsValueString
    93  	// ExtensibilityIgnoreUnknownProp represents "Runtimes that are reading or processing this configuration file MUST NOT generate an error if they encounter an unknown property."
    94  	ExtensibilityIgnoreUnknownProp
    95  	// ValidValues represents "Runtimes that are reading or processing this configuration file MUST generate an error when invalid or unsupported values are encountered."
    96  	ValidValues
    97  )
    98  
    99  var (
   100  	specificationVersionRef = func(version string) (reference string, err error) {
   101  		return fmt.Sprintf(referenceTemplate, version, "config.md#specification-version"), nil
   102  	}
   103  	rootRef = func(version string) (reference string, err error) {
   104  		return fmt.Sprintf(referenceTemplate, version, "config.md#root"), nil
   105  	}
   106  	mountsRef = func(version string) (reference string, err error) {
   107  		return fmt.Sprintf(referenceTemplate, version, "config.md#mounts"), nil
   108  	}
   109  	processRef = func(version string) (reference string, err error) {
   110  		return fmt.Sprintf(referenceTemplate, version, "config.md#process"), nil
   111  	}
   112  	posixProcessRef = func(version string) (reference string, err error) {
   113  		return fmt.Sprintf(referenceTemplate, version, "config.md#posix-process"), nil
   114  	}
   115  	linuxProcessRef = func(version string) (reference string, err error) {
   116  		return fmt.Sprintf(referenceTemplate, version, "config.md#linux-process"), nil
   117  	}
   118  	platformSpecificConfigurationRef = func(version string) (reference string, err error) {
   119  		return fmt.Sprintf(referenceTemplate, version, "config.md#platform-specific-configuration"), nil
   120  	}
   121  	posixPlatformHooksRef = func(version string) (reference string, err error) {
   122  		return fmt.Sprintf(referenceTemplate, version, "config.md#posix-platform-hooks"), nil
   123  	}
   124  	prestartRef = func(version string) (reference string, err error) {
   125  		return fmt.Sprintf(referenceTemplate, version, "config.md#prestart"), nil
   126  	}
   127  	poststartRef = func(version string) (reference string, err error) {
   128  		return fmt.Sprintf(referenceTemplate, version, "config.md#poststart"), nil
   129  	}
   130  	poststopRef = func(version string) (reference string, err error) {
   131  		return fmt.Sprintf(referenceTemplate, version, "config.md#poststop"), nil
   132  	}
   133  	annotationsRef = func(version string) (reference string, err error) {
   134  		return fmt.Sprintf(referenceTemplate, version, "config.md#annotations"), nil
   135  	}
   136  	extensibilityRef = func(version string) (reference string, err error) {
   137  		return fmt.Sprintf(referenceTemplate, version, "config.md#extensibility"), nil
   138  	}
   139  	validValuesRef = func(version string) (reference string, err error) {
   140  		return fmt.Sprintf(referenceTemplate, version, "config.md#valid-values"), nil
   141  	}
   142  )
   143  
   144  func init() {
   145  	register(SpecVersionInSemVer, rfc2119.Must, specificationVersionRef)
   146  	register(RootOnWindowsRequired, rfc2119.Required, rootRef)
   147  	register(RootOnHyperVNotSet, rfc2119.Must, rootRef)
   148  	register(RootOnNonWindowsRequired, rfc2119.Required, rootRef)
   149  	register(RootPathOnWindowsGUID, rfc2119.Must, rootRef)
   150  	register(RootPathOnPosixConvention, rfc2119.Should, rootRef)
   151  	register(RootPathExist, rfc2119.Must, rootRef)
   152  	register(RootReadonlyImplement, rfc2119.Must, rootRef)
   153  	register(RootReadonlyOnWindowsFalse, rfc2119.Must, rootRef)
   154  	register(MountsInOrder, rfc2119.Must, mountsRef)
   155  	register(MountsDestAbs, rfc2119.Must, mountsRef)
   156  	register(MountsDestOnWindowsNotNested, rfc2119.Must, mountsRef)
   157  	register(MountsOptionsOnWindowsROSupport, rfc2119.Must, mountsRef)
   158  	register(ProcRequiredAtStart, rfc2119.Required, processRef)
   159  	register(ProcConsoleSizeIgnore, rfc2119.Must, processRef)
   160  	register(ProcCwdAbs, rfc2119.Must, processRef)
   161  	register(ProcArgsOneEntryRequired, rfc2119.Required, processRef)
   162  	register(PosixProcRlimitsTypeGenError, rfc2119.Must, posixProcessRef)
   163  	register(PosixProcRlimitsTypeGet, rfc2119.Must, posixProcessRef)
   164  	register(PosixProcRlimitsTypeValueError, rfc2119.Should, posixProcessRef)
   165  	register(PosixProcRlimitsSoftMatchCur, rfc2119.Must, posixProcessRef)
   166  	register(PosixProcRlimitsHardMatchMax, rfc2119.Must, posixProcessRef)
   167  	register(PosixProcRlimitsErrorOnDup, rfc2119.Must, posixProcessRef)
   168  	register(LinuxProcCapError, rfc2119.Must, linuxProcessRef)
   169  	register(LinuxProcOomScoreAdjSet, rfc2119.Must, linuxProcessRef)
   170  	register(LinuxProcOomScoreAdjNotSet, rfc2119.Must, linuxProcessRef)
   171  	register(PlatformSpecConfOnWindowsSet, rfc2119.Must, platformSpecificConfigurationRef)
   172  	register(PosixHooksPathAbs, rfc2119.Must, posixPlatformHooksRef)
   173  	register(PosixHooksTimeoutPositive, rfc2119.Must, posixPlatformHooksRef)
   174  	register(PosixHooksCalledInOrder, rfc2119.Must, posixPlatformHooksRef)
   175  	register(PosixHooksStateToStdin, rfc2119.Must, posixPlatformHooksRef)
   176  	register(PrestartTiming, rfc2119.Must, prestartRef)
   177  	register(PoststartTiming, rfc2119.Must, poststartRef)
   178  	register(PoststopTiming, rfc2119.Must, poststopRef)
   179  	register(AnnotationsKeyValueMap, rfc2119.Must, annotationsRef)
   180  	register(AnnotationsKeyString, rfc2119.Must, annotationsRef)
   181  	register(AnnotationsKeyRequired, rfc2119.Must, annotationsRef)
   182  	register(AnnotationsKeyReversedDomain, rfc2119.Should, annotationsRef)
   183  	register(AnnotationsKeyReservedNS, rfc2119.Must, annotationsRef)
   184  	register(AnnotationsKeyIgnoreUnknown, rfc2119.Must, annotationsRef)
   185  	register(AnnotationsValueString, rfc2119.Must, annotationsRef)
   186  	register(ExtensibilityIgnoreUnknownProp, rfc2119.Must, extensibilityRef)
   187  	register(ValidValues, rfc2119.Must, validValuesRef)
   188  }