Skip to content
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

Get dependency status based on docker service and docker container #429

Merged
merged 32 commits into from
Sep 11, 2018

Conversation

antho1404
Copy link
Member

Pull request based on this one #411

@antho1404 antho1404 requested review from a team, krhubert and NicolasMahe September 5, 2018 10:09
@antho1404 antho1404 added this to the v1.2.0 milestone Sep 5, 2018
Copy link
Contributor

@ilgooz ilgooz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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) {
Copy link
Contributor

@ilgooz ilgooz Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// serviceExists checks if corresponding container for service namespace can be found.

// Otherwise the following status will be applied:
// - 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) {
Copy link
Contributor

@ilgooz ilgooz Sep 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return !xstrings.SliceContains([]string{"exited", "dead"}, container.State.Status), nil ?

available statuses:
created, restarting, running, removing, paused, exited, dead

@antho1404 antho1404 changed the base branch from daemon-status to dev September 11, 2018 07:22
@antho1404 antho1404 requested a review from a team September 11, 2018 09:23
@antho1404 antho1404 merged commit c1ac6c4 into dev Sep 11, 2018
@antho1404 antho1404 deleted the daemon-status-fix branch September 11, 2018 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants