Remove unnecessary logging binary helpers and add godoc
Signed-off-by: Akshat Kumar <kshtku@amazon.com>
This commit is contained in:
parent
7a9fbec5fb
commit
4cc99e57a7
@ -18,26 +18,12 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Pipe struct {
|
// NewBinaryCmd returns a Cmd to be used to start a logging binary.
|
||||||
R *os.File
|
// The Cmd is generated from the provided uri, and the container ID and
|
||||||
W *os.File
|
// namespace are appended to the Cmd environment.
|
||||||
}
|
|
||||||
|
|
||||||
func NewPipe() (*Pipe, error) {
|
|
||||||
R, W, err := os.Pipe()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &Pipe{
|
|
||||||
R: R,
|
|
||||||
W: W,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBinaryCmd(binaryURI *url.URL, id, ns string) *exec.Cmd {
|
func NewBinaryCmd(binaryURI *url.URL, id, ns string) *exec.Cmd {
|
||||||
var args []string
|
var args []string
|
||||||
for k, vs := range binaryURI.Query() {
|
for k, vs := range binaryURI.Query() {
|
||||||
|
@ -78,13 +78,13 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
|
|||||||
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
||||||
|
|
||||||
// Create pipe to be used by logging binary for Stdout
|
// Create pipe to be used by logging binary for Stdout
|
||||||
out, err := runtime.NewPipe()
|
outR, outW, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stderr is created for logging binary but unused when terminal is true
|
// Stderr is created for logging binary but unused when terminal is true
|
||||||
serr, err := runtime.NewPipe()
|
serrR, _, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
||||||
}
|
}
|
||||||
@ -94,14 +94,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
cwg.Add(1)
|
cwg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
cwg.Done()
|
cwg.Done()
|
||||||
io.Copy(out.W, epollConsole)
|
io.Copy(outW, epollConsole)
|
||||||
out.W.Close()
|
outW.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -67,13 +67,13 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
|
|||||||
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
||||||
|
|
||||||
// Create pipe to be used by logging binary for Stdout
|
// Create pipe to be used by logging binary for Stdout
|
||||||
out, err := runtime.NewPipe()
|
outR, outW, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stderr is created for logging binary but unused when terminal is true
|
// Stderr is created for logging binary but unused when terminal is true
|
||||||
serr, err := runtime.NewPipe()
|
serrR, _, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
||||||
}
|
}
|
||||||
@ -83,14 +83,14 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
cwg.Add(1)
|
cwg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
cwg.Done()
|
cwg.Done()
|
||||||
io.Copy(out.W, console)
|
io.Copy(outW, console)
|
||||||
out.W.Close()
|
outW.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -102,13 +102,13 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
|
|||||||
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
||||||
|
|
||||||
// Create pipe to be used by logging binary for Stdout
|
// Create pipe to be used by logging binary for Stdout
|
||||||
out, err := runtime.NewPipe()
|
outR, outW, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stderr is created for logging binary but unused when terminal is true
|
// Stderr is created for logging binary but unused when terminal is true
|
||||||
serr, err := runtime.NewPipe()
|
serrR, _, err := os.Pipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
return nil, errors.Wrap(err, "failed to create stderr pipes")
|
||||||
}
|
}
|
||||||
@ -118,14 +118,14 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
cwg.Add(1)
|
cwg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
cwg.Done()
|
cwg.Done()
|
||||||
io.Copy(out.W, epollConsole)
|
io.Copy(outW, epollConsole)
|
||||||
out.W.Close()
|
outW.Close()
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user