github.com/opencontainers/runtime-tools@v0.9.0/specerror/runtime.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 // EntityOperSameContainer represents "The entity using a runtime to create a container MUST be able to use the operations defined in this specification against that same container." 12 EntityOperSameContainer Code = 0xe001 + iota 13 // StateIDUniq represents "`id` (string, REQUIRED) is the container's ID. This MUST be unique across all containers on this host." 14 StateIDUniq 15 // StateNewStatus represents "Additional values MAY be defined by the runtime, however, they MUST be used to represent new runtime states not defined above." 16 StateNewStatus 17 // DefaultStateJSONPattern represents "When serialized in JSON, the format MUST adhere to the default pattern." 18 DefaultStateJSONPattern 19 // EnvCreateImplement represents "The container's runtime environment MUST be created according to the configuration in `config.json`." 20 EnvCreateImplement 21 // EnvCreateError represents "If the runtime is unable to create the environment specified in the `config.json`, it MUST generate an error." 22 EnvCreateError 23 // ProcNotRunAtResRequest represents "While the resources requested in the `config.json` MUST be created, the user-specified program (from `process`) MUST NOT be run at this time." 24 ProcNotRunAtResRequest 25 // ConfigUpdatesWithoutAffect represents "Any updates to `config.json` after this step MUST NOT affect the container." 26 ConfigUpdatesWithoutAffect 27 // PrestartHooksInvoke represents "The prestart hooks MUST be invoked by the runtime." 28 PrestartHooksInvoke 29 // PrestartHookFailGenError represents "If any prestart hook fails, the runtime MUST generate an error, stop the container, and continue the lifecycle at step 9." 30 PrestartHookFailGenError 31 // ProcImplement represents "The runtime MUST run the user-specified program, as specified by `process`." 32 ProcImplement 33 // PoststartHooksInvoke represents "The poststart hooks MUST be invoked by the runtime." 34 PoststartHooksInvoke 35 // PoststartHookFailGenWarn represents "If any poststart hook fails, the runtime MUST log a warning, but the remaining hooks and lifecycle continue as if the hook had succeeded." 36 PoststartHookFailGenWarn 37 // UndoCreateSteps represents "The container MUST be destroyed by undoing the steps performed during create phase (step 2)." 38 UndoCreateSteps 39 // PoststopHooksInvoke represents "The poststop hooks MUST be invoked by the runtime." 40 PoststopHooksInvoke 41 // PoststopHookFailGenWarn represents "If any poststop hook fails, the runtime MUST log a warning, but the remaining hooks and lifecycle continue as if the hook had succeeded." 42 PoststopHookFailGenWarn 43 // ErrorsLeaveStateUnchange represents "Unless otherwise stated, generating an error MUST leave the state of the environment as if the operation were never attempted - modulo any possible trivial ancillary changes such as logging." 44 ErrorsLeaveStateUnchange 45 // WarnsLeaveFlowUnchange represents "Unless otherwise stated, logging a warning does not change the flow of the operation; it MUST continue as if the warning had not been logged." 46 WarnsLeaveFlowUnchange 47 // DefaultOperations represents "Unless otherwise stated, runtimes MUST support the default operations." 48 DefaultOperations 49 // QueryWithoutIDGenError represents "This operation MUST generate an error if it is not provided the ID of a container." 50 QueryWithoutIDGenError 51 // QueryNonExistGenError represents "Attempting to query a container that does not exist MUST generate an error." 52 QueryNonExistGenError 53 // QueryStateImplement represents "This operation MUST return the state of a container as specified in the State section." 54 QueryStateImplement 55 // CreateWithBundlePathAndID represents "This operation MUST generate an error if it is not provided a path to the bundle and the container ID to associate with the container." 56 CreateWithBundlePathAndID 57 // CreateWithUniqueID represents "If the ID provided is not unique across all containers within the scope of the runtime, or is not valid in any other way, the implementation MUST generate an error and a new container MUST NOT be created." 58 CreateWithUniqueID 59 // CreateNewContainer represents "This operation MUST create a new container." 60 CreateNewContainer 61 // PropsApplyExceptProcOnCreate represents "All of the properties configured in `config.json` except for `process` MUST be applied." 62 PropsApplyExceptProcOnCreate 63 // ProcArgsApplyUntilStart represents `process.args` MUST NOT be applied until triggered by the `start` operation." 64 ProcArgsApplyUntilStart 65 // PropApplyFailGenError represents "If the runtime cannot apply a property as specified in the configuration, it MUST generate an error." 66 PropApplyFailGenError 67 // PropApplyFailNotCreate represents "If the runtime cannot apply a property as specified in the configuration, a new container MUST NOT be created." 68 PropApplyFailNotCreate 69 // StartWithoutIDGenError represents "`start` operation MUST generate an error if it is not provided the container ID." 70 StartWithoutIDGenError 71 // StartNotCreatedHaveNoEffect represents "Attempting to `start` a container that is not `created` MUST have no effect on the container." 72 StartNotCreatedHaveNoEffect 73 // StartNotCreatedGenError represents "Attempting to `start` a container that is not `created` MUST generate an error." 74 StartNotCreatedGenError 75 // StartProcImplement represents "`start` operation MUST run the user-specified program as specified by `process`." 76 StartProcImplement 77 // StartWithProcUnsetGenError represents "`start` operation MUST generate an error if `process` was not set." 78 StartWithProcUnsetGenError 79 // KillWithoutIDGenError represents "`kill` operation MUST generate an error if it is not provided the container ID." 80 KillWithoutIDGenError 81 // KillNonCreateRunHaveNoEffect represents "Attempting to send a signal to a container that is neither `created` nor `running` MUST have no effect on the container." 82 KillNonCreateRunHaveNoEffect 83 // KillNonCreateRunGenError represents "Attempting to send a signal to a container that is neither `created` nor `running` MUST generate an error." 84 KillNonCreateRunGenError 85 // KillSignalImplement represents "`kill` operation MUST send the specified signal to the container process." 86 KillSignalImplement 87 // DeleteWithoutIDGenError represents "`delete` operation MUST generate an error if it is not provided the container ID." 88 DeleteWithoutIDGenError 89 // DeleteNonStopHaveNoEffect represents "Attempting to `delete` a container that is not `stopped` MUST have no effect on the container." 90 DeleteNonStopHaveNoEffect 91 // DeleteNonStopGenError represents "Attempting to `delete` a container that is not `stopped` MUST generate an error." 92 DeleteNonStopGenError 93 // DeleteResImplement represents "Deleting a container MUST delete the resources that were created during the `create` step." 94 DeleteResImplement 95 // DeleteOnlyCreatedRes represents "Note that resources associated with the container, but not created by this container, MUST NOT be deleted." 96 DeleteOnlyCreatedRes 97 ) 98 99 var ( 100 scopeOfAContainerRef = func(version string) (reference string, err error) { 101 return fmt.Sprintf(referenceTemplate, version, "runtime.md#scope-of-a-container"), nil 102 } 103 stateRef = func(version string) (reference string, err error) { 104 return fmt.Sprintf(referenceTemplate, version, "runtime.md#state"), nil 105 } 106 lifecycleRef = func(version string) (reference string, err error) { 107 return fmt.Sprintf(referenceTemplate, version, "runtime.md#lifecycle"), nil 108 } 109 errorsRef = func(version string) (reference string, err error) { 110 return fmt.Sprintf(referenceTemplate, version, "runtime.md#errors"), nil 111 } 112 warningsRef = func(version string) (reference string, err error) { 113 return fmt.Sprintf(referenceTemplate, version, "runtime.md#warnings"), nil 114 } 115 operationsRef = func(version string) (reference string, err error) { 116 return fmt.Sprintf(referenceTemplate, version, "runtime.md#operations"), nil 117 } 118 queryStateRef = func(version string) (reference string, err error) { 119 return fmt.Sprintf(referenceTemplate, version, "runtime.md#query-state"), nil 120 } 121 createRef = func(version string) (reference string, err error) { 122 return fmt.Sprintf(referenceTemplate, version, "runtime.md#create"), nil 123 } 124 startRef = func(version string) (reference string, err error) { 125 return fmt.Sprintf(referenceTemplate, version, "runtime.md#start"), nil 126 } 127 killRef = func(version string) (reference string, err error) { 128 return fmt.Sprintf(referenceTemplate, version, "runtime.md#kill"), nil 129 } 130 deleteRef = func(version string) (reference string, err error) { 131 return fmt.Sprintf(referenceTemplate, version, "runtime.md#delete"), nil 132 } 133 ) 134 135 func init() { 136 register(EntityOperSameContainer, rfc2119.Must, scopeOfAContainerRef) 137 register(StateIDUniq, rfc2119.Must, stateRef) 138 register(StateNewStatus, rfc2119.Must, stateRef) 139 register(DefaultStateJSONPattern, rfc2119.Must, stateRef) 140 register(EnvCreateImplement, rfc2119.Must, lifecycleRef) 141 register(EnvCreateError, rfc2119.Must, lifecycleRef) 142 register(ProcNotRunAtResRequest, rfc2119.Must, lifecycleRef) 143 register(ConfigUpdatesWithoutAffect, rfc2119.Must, lifecycleRef) 144 register(PrestartHooksInvoke, rfc2119.Must, lifecycleRef) 145 register(PrestartHookFailGenError, rfc2119.Must, lifecycleRef) 146 register(ProcImplement, rfc2119.Must, lifecycleRef) 147 register(PoststartHooksInvoke, rfc2119.Must, lifecycleRef) 148 register(PoststartHookFailGenWarn, rfc2119.Must, lifecycleRef) 149 register(UndoCreateSteps, rfc2119.Must, lifecycleRef) 150 register(PoststopHooksInvoke, rfc2119.Must, lifecycleRef) 151 register(PoststopHookFailGenWarn, rfc2119.Must, lifecycleRef) 152 register(ErrorsLeaveStateUnchange, rfc2119.Must, errorsRef) 153 register(WarnsLeaveFlowUnchange, rfc2119.Must, warningsRef) 154 register(DefaultOperations, rfc2119.Must, operationsRef) 155 register(QueryWithoutIDGenError, rfc2119.Must, queryStateRef) 156 register(QueryNonExistGenError, rfc2119.Must, queryStateRef) 157 register(QueryStateImplement, rfc2119.Must, queryStateRef) 158 register(CreateWithBundlePathAndID, rfc2119.Must, createRef) 159 register(CreateWithUniqueID, rfc2119.Must, createRef) 160 register(CreateNewContainer, rfc2119.Must, createRef) 161 register(PropsApplyExceptProcOnCreate, rfc2119.Must, createRef) 162 register(ProcArgsApplyUntilStart, rfc2119.Must, createRef) 163 register(PropApplyFailGenError, rfc2119.Must, createRef) 164 register(PropApplyFailNotCreate, rfc2119.Must, createRef) 165 register(StartWithoutIDGenError, rfc2119.Must, startRef) 166 register(StartNotCreatedHaveNoEffect, rfc2119.Must, startRef) 167 register(StartNotCreatedGenError, rfc2119.Must, startRef) 168 register(StartProcImplement, rfc2119.Must, startRef) 169 register(StartWithProcUnsetGenError, rfc2119.Must, startRef) 170 register(KillWithoutIDGenError, rfc2119.Must, killRef) 171 register(KillNonCreateRunHaveNoEffect, rfc2119.Must, killRef) 172 register(KillNonCreateRunGenError, rfc2119.Must, killRef) 173 register(KillSignalImplement, rfc2119.Must, killRef) 174 register(DeleteWithoutIDGenError, rfc2119.Must, deleteRef) 175 register(DeleteNonStopHaveNoEffect, rfc2119.Must, deleteRef) 176 register(DeleteNonStopGenError, rfc2119.Must, deleteRef) 177 register(DeleteResImplement, rfc2119.Must, deleteRef) 178 register(DeleteOnlyCreatedRes, rfc2119.Must, deleteRef) 179 }