Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions internal/oci/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,9 @@ func (c *Container) exitFilePath() string {

// IsAlive is a function that checks if a container's init PID exists.
// It is used to check a container state when we don't want a `$runtime state` call
func (c *Container) IsAlive() bool {
func (c *Container) IsAlive() error {
_, err := c.pid()
if err != nil {
logrus.Errorf("checking if PID of %s is running failed: %v", c.id, err)
return false
}

return true
return errors.Wrapf(err, "checking if PID of %s is running failed", c.id)
Copy link
Member

Choose a reason for hiding this comment

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

Are we missing the return nil case?

Copy link
Member Author

Choose a reason for hiding this comment

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

if the supplied err is nil, wrapf returns nil
https://godoc.org/github.com/pkg/errors#Wrap

}

// Pid returns the container's init PID.
Expand Down
6 changes: 3 additions & 3 deletions internal/oci/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ var _ = t.Describe("Container", func() {
err := sut.IsAlive()

// Then
Expect(err).To(Equal(false))
Expect(err).NotTo(BeNil())
})
It("should succeed if pid is running", func() {
// Given
Expand All @@ -318,7 +318,7 @@ var _ = t.Describe("Container", func() {
err := sut.IsAlive()

// Then
Expect(err).To(Equal(true))
Expect(err).To(BeNil())
})
It("should be false if pid is not running", func() {
// Given
Expand All @@ -331,7 +331,7 @@ var _ = t.Describe("Container", func() {
err := sut.IsAlive()

// Then
Expect(err).To(Equal(false))
Expect(err).NotTo(BeNil())
})
})
t.Describe("Pid", func() {
Expand Down
9 changes: 4 additions & 5 deletions server/container_execsync.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package server

import (
"fmt"

"github.com/pkg/errors"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -16,13 +15,13 @@ func (s *Server) ExecSync(ctx context.Context, req *pb.ExecSyncRequest) (*pb.Exe
return nil, status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err)
}

if !c.IsAlive() {
return nil, fmt.Errorf("container is not created or running")
if err := c.IsAlive(); err != nil {
return nil, status.Errorf(codes.NotFound, "container is not created or running: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

Can you include the container id as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's included in the return value of IsAlive()

Copy link
Member Author

Choose a reason for hiding this comment

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

should I move that up a level?

Copy link
Member

Choose a reason for hiding this comment

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

No, it's fine!

}

cmd := req.Cmd
if cmd == nil {
return nil, fmt.Errorf("exec command cannot be empty")
return nil, errors.New("exec command cannot be empty")
}

execResp, err := s.Runtime().ExecSyncContainer(c, cmd, req.Timeout)
Expand Down