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
33 changes: 7 additions & 26 deletions internal/oci/oci.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package oci

import (
"bytes"
"fmt"
"io"
"sync"
Expand All @@ -10,6 +9,7 @@ import (

"github.com/cri-o/cri-o/pkg/annotations"
"github.com/cri-o/cri-o/pkg/config"
types "github.com/cri-o/cri-o/server/cri/types"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"

Expand Down Expand Up @@ -51,9 +51,9 @@ type Runtime struct {
type RuntimeImpl interface {
CreateContainer(*Container, string) error
StartContainer(*Container) error
ExecContainer(*Container, []string, io.Reader, io.WriteCloser, io.WriteCloser,
ExecContainer(context.Context, *Container, []string, io.Reader, io.WriteCloser, io.WriteCloser,
bool, <-chan remotecommand.TerminalSize) error
ExecSyncContainer(*Container, []string, int64) (*ExecSyncResponse, error)
ExecSyncContainer(context.Context, *Container, []string, int64) (*types.ExecSyncResponse, error)
UpdateContainer(*Container, *rspec.LinuxResources) error
StopContainer(context.Context, *Container, int64) error
DeleteContainer(*Container) error
Expand Down Expand Up @@ -305,23 +305,23 @@ func (r *Runtime) StartContainer(c *Container) error {
}

// ExecContainer prepares a streaming endpoint to execute a command in the container.
func (r *Runtime) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
func (r *Runtime) ExecContainer(ctx context.Context, c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error {
impl, err := r.RuntimeImpl(c)
if err != nil {
return err
}

return impl.ExecContainer(c, cmd, stdin, stdout, stderr, tty, resize)
return impl.ExecContainer(ctx, c, cmd, stdin, stdout, stderr, tty, resize)
}

// ExecSyncContainer execs a command in a container and returns it's stdout, stderr and return code.
func (r *Runtime) ExecSyncContainer(c *Container, command []string, timeout int64) (*ExecSyncResponse, error) {
func (r *Runtime) ExecSyncContainer(ctx context.Context, c *Container, command []string, timeout int64) (*types.ExecSyncResponse, error) {
impl, err := r.RuntimeImpl(c)
if err != nil {
return nil, err
}

return impl.ExecSyncContainer(c, command, timeout)
return impl.ExecSyncContainer(ctx, c, command, timeout)
}

// UpdateContainer updates container resources
Expand Down Expand Up @@ -445,22 +445,3 @@ func (r *Runtime) ReopenContainerLog(c *Container) error {

return impl.ReopenContainerLog(c)
}

// ExecSyncResponse is returned from ExecSync.
type ExecSyncResponse struct {
Stdout []byte
Stderr []byte
ExitCode int32
}

// ExecSyncError wraps command's streams, exit code and error on ExecSync error.
type ExecSyncError struct {
Stdout bytes.Buffer
Stderr bytes.Buffer
ExitCode int32
Err error
}

func (e *ExecSyncError) Error() string {
return fmt.Sprintf("command error: %+v, stdout: %s, stderr: %s, exit code %d", e.Err, e.Stdout.Bytes(), e.Stderr.Bytes(), e.ExitCode)
}
13 changes: 0 additions & 13 deletions internal/oci/oci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,4 @@ var _ = t.Describe("Oci", func() {
Expect(allowed).To(Equal(true))
})
})

t.Describe("ExecSyncError", func() {
It("should succeed to get the exec sync error", func() {
// Given
sut := oci.ExecSyncError{}

// When
result := sut.Error()

// Then
Expect(result).To(ContainSubstring("error"))
})
})
})
Loading