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

Revert "gcs: Support routing container stdio to sidecar" #2023

Merged
merged 1 commit into from Feb 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 2 additions & 69 deletions internal/guest/runtime/runc/container.go
Expand Up @@ -5,7 +5,6 @@ package runc

import (
"encoding/json"
"fmt"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -327,7 +326,7 @@ func (c *container) runExecCommand(processDef *oci.Process, stdioSet *stdio.Conn

args := []string{"exec"}
args = append(args, "-d", "--process", filepath.Join(tempProcessDir, "process.json"))
return c.startProcess(tempProcessDir, processDef.Terminal, stdioSet, nil, args...)
return c.startProcess(tempProcessDir, processDef.Terminal, stdioSet, args...)
}

// startProcess performs the operations necessary to start a container process
Expand All @@ -338,9 +337,7 @@ func (c *container) runExecCommand(processDef *oci.Process, stdioSet *stdio.Conn
func (c *container) startProcess(
tempProcessDir string,
hasTerminal bool,
stdioSet *stdio.ConnectionSet,
annotations map[string]string,
initialArgs ...string,
stdioSet *stdio.ConnectionSet, initialArgs ...string,
) (p *process, err error) {
args := initialArgs

Expand Down Expand Up @@ -392,70 +389,6 @@ func (c *container) startProcess(
}
}

// This is for enabling container logging via side car feature. This is in experimental stage now and need to be revisited.
var stdoutFifoPipe, stderrFifoPipe *os.File
if annotations != nil {
pipeNameSuffix, exists := annotations["io.microsoft.bmc.logging.pipelocation"]
if exists {
if hasTerminal {
return nil, fmt.Errorf("logging via side car and TTY are not supported together")
}
pipeDirectory := "/run/gcs/containerlogs/"
stdoutPipeName := pipeDirectory + pipeNameSuffix + "-stdout"
stderrPipeName := pipeDirectory + pipeNameSuffix + "-stderr"
err = os.MkdirAll(pipeDirectory, 0755)
if err != nil {
return nil, fmt.Errorf("error creating log directory %s for logging pipe fifo: %w", pipeDirectory, err)
}

_, err = os.Stat(stdoutPipeName)
if err != nil {
// fifo pipe does not exist, create one
err = syscall.Mkfifo(stdoutPipeName, 0666)
if err != nil {
return nil, fmt.Errorf("error creating fifo %s: %w", stdoutPipeName, err)
}
}

_, err = os.Stat(stderrPipeName)
if err != nil {
// fifo pipe does not exist, create one
err = syscall.Mkfifo(stderrPipeName, 0666)
if err != nil {
return nil, fmt.Errorf("error creating fifo %s: %w", stderrPipeName, err)
}
}

// pipe either exist before hand or we have created one above
stdoutFifoPipe, err = os.OpenFile(stdoutPipeName, os.O_RDWR|os.O_APPEND, os.ModeNamedPipe)
if err != nil {
return nil, fmt.Errorf("error opening fifo %s: %w", stdoutPipeName, err)
}

stderrFifoPipe, err = os.OpenFile(stderrPipeName, os.O_RDWR|os.O_APPEND, os.ModeNamedPipe)
if err != nil {
return nil, fmt.Errorf("error opening fifo %s: %w", stderrPipeName, err)
}
}

isLoggingSideCarContainerStr, exists := annotations["io.microsoft.bmc.logging.isLoggingSideCarContainer"]
if exists {
isLoggingSideCarContainer, err := strconv.ParseBool(isLoggingSideCarContainerStr)
if err != nil {
return nil, fmt.Errorf("error parsing flag isLoggingSideCarContainer: %w", err)
}
if !isLoggingSideCarContainer {
// workload container needs to redirect stdout and stderr to fifo pipe.
cmd.Stdout = stdoutFifoPipe
cmd.Stderr = stderrFifoPipe
} else {
// logging side car container needs to know the pipe fd.
cmd.Args = append(cmd.Args, "--preserve-fds", "2")
cmd.ExtraFiles = []*os.File{stdoutFifoPipe, stderrFifoPipe}
}
}
}

if err := cmd.Run(); err != nil {
runcErr := getRuncLogError(logPath)
return nil, errors.Wrapf(runcErr, "failed to run runc create/exec call for container %s with %v", c.id, err)
Expand Down
3 changes: 1 addition & 2 deletions internal/guest/runtime/runc/runc.go
Expand Up @@ -193,8 +193,7 @@ func (r *runcRuntime) runCreateCommand(id string, bundlePath string, stdioSet *s
}

args := []string{"create", "-b", bundlePath, "--no-pivot"}

p, err := c.startProcess(tempProcessDir, spec.Process.Terminal, stdioSet, spec.Annotations, args...)
p, err := c.startProcess(tempProcessDir, spec.Process.Terminal, stdioSet, args...)
if err != nil {
return nil, err
}
Expand Down