Get dependency status based on docker service and docker container#429
Merged
Get dependency status based on docker service and docker container#429
Conversation
ilgooz
suggested changes
Sep 6, 2018
Contributor
ilgooz
left a comment
There was a problem hiding this comment.
and we can always add some more tests to inc branch coverage :)
|
|
||
| // containerExists return true if the docker service can be found, return false otherwise and return | ||
| // any errors that are not `NotFound` errors | ||
| func (c *Container) containerExists(namespace []string) (bool, error) { |
Contributor
There was a problem hiding this comment.
// containerExists checks if container with namespace can be found.
| // presenceHandling handle the error the check the presence of a docker resource. | ||
| // It returns any error that are not docker `NotFound` errors | ||
| // It returns a boolean that says if the docker resource exists | ||
| func presenceHandling(err error) (bool, error) { |
Contributor
There was a problem hiding this comment.
// presenceHandling checks err to see if it's a Docker NotFound error and if not
// it'll return the err back.
|
|
||
| // serviceExists return true if the docker container can be found, return false otherwise and return | ||
| // any errors that are not `NotFound` errors | ||
| func (c *Container) serviceExists(namespace []string) (bool, error) { |
Contributor
There was a problem hiding this comment.
// serviceExists checks if corresponding container for service namespace can be found.
| // - RUNNING: When the container is running in docker (whatever the status of the service) | ||
| // - STARTING: When the service is running but the container is not yet started | ||
| // - STOPPED: When neither the container nor the service are running in docker | ||
| func (c *Container) Status(namespace []string) (StatusType, error) { |
Contributor
There was a problem hiding this comment.
// status returns the status of the container based on the docker container and docker service.
// if any error occurs during the status check, status will be shown as UNKNOWN.
// otherwise the following rules will be applied to determine a status:
// - RUNNING: when the container is running in docker regardless of the status of the service.
// - STARTING: when the service is running but the container is not yet started.
// - STOPPED: when the container and the service is not running in docker.
| func (c *Container) containerExists(namespace []string) (bool, error) { | ||
| container, err := c.FindContainer(namespace) | ||
| if err == nil && container.State != nil && | ||
| xstrings.SliceContains([]string{"exited", "dead"}, container.State.Status) { |
Contributor
There was a problem hiding this comment.
return !xstrings.SliceContains([]string{"exited", "dead"}, container.State.Status), nil ?
available statuses:
created, restarting, running, removing, paused, exited, dead
krhubert
approved these changes
Sep 11, 2018
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull request based on this one #411