-
Notifications
You must be signed in to change notification settings - Fork 7
fix: make app failed if a container is stopped #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giulio93
wants to merge
9
commits into
main
Choose a base branch
from
add_stopped_state_to_app_status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−8
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4105b65
add status stopped
giulio93 99354fd
Apply suggestion from @lucarin91
giulio93 a09d652
Add state failed
giulio93 c9deb5f
States
giulio93 25d90c6
revert
giulio93 906154a
containerState struct with Status and StatusMessage
giulio93 fe0cced
handle ct state in helpers
giulio93 76faefe
add status message to
giulio93 acba544
check function in status
giulio93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -17,8 +17,11 @@ package orchestrator | |||
|
|
||||
| import ( | ||||
| "fmt" | ||||
| "regexp" | ||||
| "strconv" | ||||
|
|
||||
| "github.com/docker/docker/api/types/container" | ||||
| "go.bug.st/f" | ||||
| ) | ||||
|
|
||||
| type Status string | ||||
|
|
@@ -31,18 +34,24 @@ const ( | |||
| StatusFailed Status = "failed" | ||||
| ) | ||||
|
|
||||
| func StatusFromDockerState(s container.ContainerState) Status { | ||||
| func StatusFromDockerState(s container.ContainerState, statusMessage string) Status { | ||||
| switch s { | ||||
| case container.StateRunning: | ||||
| return StatusRunning | ||||
| case container.StateRestarting: | ||||
| return StatusStarting | ||||
| case container.StateRemoving: | ||||
| return StatusStopping | ||||
| case container.StateCreated, container.StateExited, container.StatePaused: | ||||
| case container.StateCreated, container.StatePaused: | ||||
| return StatusStopped | ||||
| case container.StateExited: | ||||
| if !isExitBySignal(statusMessage) { | ||||
| return StatusFailed | ||||
| } | ||||
| return StatusStopped | ||||
| case container.StateDead: | ||||
| return StatusFailed | ||||
|
|
||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| default: | ||||
| panic("unreachable") | ||||
| } | ||||
|
|
@@ -65,3 +74,17 @@ func (s Status) Validate() error { | |||
| func (s Status) AllowedStatuses() []Status { | ||||
| return []Status{StatusStarting, StatusRunning, StatusStopping, StatusStopped, StatusFailed} | ||||
| } | ||||
|
|
||||
| func isExitBySignal(statusMessage string) bool { | ||||
| var exitCodeRegex = regexp.MustCompile(`Exited \((\d+)\)`) | ||||
| matches := exitCodeRegex.FindStringSubmatch(statusMessage) | ||||
| if len(matches) < 2 { | ||||
| // not matching an exit code | ||||
| return false | ||||
| } | ||||
| exitCode := f.Must(strconv.Atoi(matches[1])) | ||||
|
|
||||
| // posix exit code greater than 128+n means terminated by signal https://tldp.org/LDP/abs/html/exitcodes.html | ||||
| return exitCode > 128 | ||||
|
|
||||
| } | ||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.