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 (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
type Pipe struct {
|
||||
R *os.File
|
||||
W *os.File
|
||||
}
|
||||
|
||||
func NewPipe() (*Pipe, error) {
|
||||
R, W, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Pipe{
|
||||
R: R,
|
||||
W: W,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewBinaryCmd returns a Cmd to be used to start a logging binary.
|
||||
// The Cmd is generated from the provided uri, and the container ID and
|
||||
// namespace are appended to the Cmd environment.
|
||||
func NewBinaryCmd(binaryURI *url.URL, id, ns string) *exec.Cmd {
|
||||
var args []string
|
||||
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)
|
||||
|
||||
// Create pipe to be used by logging binary for Stdout
|
||||
out, err := runtime.NewPipe()
|
||||
outR, outW, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||
}
|
||||
|
||||
// Stderr is created for logging binary but unused when terminal is true
|
||||
serr, err := runtime.NewPipe()
|
||||
serrR, _, err := os.Pipe()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||
|
||||
wg.Add(1)
|
||||
cwg.Add(1)
|
||||
go func() {
|
||||
cwg.Done()
|
||||
io.Copy(out.W, epollConsole)
|
||||
out.W.Close()
|
||||
io.Copy(outW, epollConsole)
|
||||
outW.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
|
@ -67,13 +67,13 @@ func (p *unixPlatform) CopyConsole(ctx context.Context, console console.Console,
|
||||
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
||||
|
||||
// Create pipe to be used by logging binary for Stdout
|
||||
out, err := runtime.NewPipe()
|
||||
outR, outW, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||
}
|
||||
|
||||
// Stderr is created for logging binary but unused when terminal is true
|
||||
serr, err := runtime.NewPipe()
|
||||
serrR, _, err := os.Pipe()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||
|
||||
wg.Add(1)
|
||||
cwg.Add(1)
|
||||
go func() {
|
||||
cwg.Done()
|
||||
io.Copy(out.W, console)
|
||||
out.W.Close()
|
||||
io.Copy(outW, console)
|
||||
outW.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
|
@ -102,13 +102,13 @@ func (p *linuxPlatform) CopyConsole(ctx context.Context, console console.Console
|
||||
cmd := runtime.NewBinaryCmd(uri, id, ns)
|
||||
|
||||
// Create pipe to be used by logging binary for Stdout
|
||||
out, err := runtime.NewPipe()
|
||||
outR, outW, err := os.Pipe()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create stdout pipes")
|
||||
}
|
||||
|
||||
// Stderr is created for logging binary but unused when terminal is true
|
||||
serr, err := runtime.NewPipe()
|
||||
serrR, _, err := os.Pipe()
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, out.R, serr.R, w)
|
||||
cmd.ExtraFiles = append(cmd.ExtraFiles, outR, serrR, w)
|
||||
|
||||
wg.Add(1)
|
||||
cwg.Add(1)
|
||||
go func() {
|
||||
cwg.Done()
|
||||
io.Copy(out.W, epollConsole)
|
||||
out.W.Close()
|
||||
io.Copy(outW, epollConsole)
|
||||
outW.Close()
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user