These matches were overwriting the previous "match", so reversing the
order in which they're tried so that we can return early.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -146,33 +146,37 @@ const ( |
| 146 | 146 |
// container. It returns an errdefs error (either errdefs.ErrInvalidParameter |
| 147 | 147 |
// or errdefs.ErrUnknown). |
| 148 | 148 |
func translateContainerdStartErr(setExitCode func(exitStatus), err error) error {
|
| 149 |
+ if err == nil {
|
|
| 150 |
+ return nil |
|
| 151 |
+ } |
|
| 149 | 152 |
errDesc := status.Convert(err).Message() |
| 150 | 153 |
contains := func(s1, s2 string) bool {
|
| 151 | 154 |
return strings.Contains(strings.ToLower(s1), s2) |
| 152 | 155 |
} |
| 153 |
- var retErr = errdefs.Unknown(errors.New(errDesc)) |
|
| 154 |
- // if we receive an internal error from the initial start of a container then lets |
|
| 155 |
- // return it instead of entering the restart loop |
|
| 156 |
- // set to 127 for container cmd not found/does not exist. |
|
| 157 |
- if isInvalidCommand(errDesc) {
|
|
| 158 |
- setExitCode(exitCmdNotFound) |
|
| 159 |
- retErr = startInvalidConfigError(errDesc) |
|
| 160 |
- } |
|
| 156 |
+ |
|
| 161 | 157 |
// set to 126 for container cmd can't be invoked errors |
| 162 | 158 |
if contains(errDesc, syscall.EACCES.Error()) {
|
| 163 | 159 |
setExitCode(exitEaccess) |
| 164 |
- retErr = startInvalidConfigError(errDesc) |
|
| 160 |
+ return startInvalidConfigError(errDesc) |
|
| 165 | 161 |
} |
| 166 | 162 |
|
| 167 | 163 |
// attempted to mount a file onto a directory, or a directory onto a file, maybe from user specified bind mounts |
| 168 | 164 |
if contains(errDesc, syscall.ENOTDIR.Error()) {
|
| 169 | 165 |
errDesc += ": Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type" |
| 170 | 166 |
setExitCode(exitCmdNotFound) |
| 171 |
- retErr = startInvalidConfigError(errDesc) |
|
| 167 |
+ return startInvalidConfigError(errDesc) |
|
| 168 |
+ } |
|
| 169 |
+ |
|
| 170 |
+ // if we receive an internal error from the initial start of a container then lets |
|
| 171 |
+ // return it instead of entering the restart loop |
|
| 172 |
+ // set to 127 for container cmd not found/does not exist. |
|
| 173 |
+ if isInvalidCommand(errDesc) {
|
|
| 174 |
+ setExitCode(exitCmdNotFound) |
|
| 175 |
+ return startInvalidConfigError(errDesc) |
|
| 172 | 176 |
} |
| 173 | 177 |
|
| 174 | 178 |
// TODO: it would be nice to get some better errors from containerd so we can return better errors here |
| 175 |
- return retErr |
|
| 179 |
+ return errdefs.Unknown(errors.New(errDesc)) |
|
| 176 | 180 |
} |
| 177 | 181 |
|
| 178 | 182 |
// isInvalidCommand tries to detect if the reason the container failed to start |