Merge pull request #16117 from alexlarsson/container-terminal-helper

Add and use libpod/Container.Terminal() helper
This commit is contained in:
OpenShift Merge Robot
2022-10-11 16:18:02 -04:00
committed by GitHub
6 changed files with 17 additions and 13 deletions

View File

@ -680,6 +680,14 @@ func (c *Container) WorkingDir() string {
return "/"
}
// Terminal returns true if the container has a terminal
func (c *Container) Terminal() bool {
if c.config.Spec != nil && c.config.Spec.Process != nil {
return c.config.Spec.Process.Terminal
}
return false
}
// State Accessors
// Require locking

View File

@ -274,7 +274,7 @@ func (c *Container) Attach(streams *define.AttachStreams, keys string, resize <-
// Send a SIGWINCH after attach succeeds so that most programs will
// redraw the screen for the new attach session.
attachRdy := make(chan bool, 1)
if c.config.Spec.Process != nil && c.config.Spec.Process.Terminal {
if c.Terminal() {
go func() {
<-attachRdy
if err := c.ociRuntime.KillContainer(c, uint(signal.SIGWINCH), false); err != nil {

View File

@ -698,7 +698,7 @@ func containerToV1Container(ctx context.Context, c *Container) (v1.Container, []
// container.EnvFromSource =
kubeContainer.SecurityContext = kubeSec
kubeContainer.StdinOnce = false
kubeContainer.TTY = c.config.Spec.Process.Terminal
kubeContainer.TTY = c.Terminal()
if c.config.Spec.Linux != nil &&
c.config.Spec.Linux.Resources != nil {

View File

@ -493,10 +493,7 @@ func socketCloseWrite(conn *net.UnixConn) error {
// Returns any errors that occurred, and whether the connection was successfully
// hijacked before that error occurred.
func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.ResponseWriter, streams *HTTPAttachStreams, detachKeys *string, cancel <-chan bool, hijackDone chan<- bool, streamAttach, streamLogs bool) (deferredErr error) {
isTerminal := false
if ctr.config.Spec.Process != nil {
isTerminal = ctr.config.Spec.Process.Terminal
}
isTerminal := ctr.Terminal()
if streams != nil {
if !streams.Stdin && !streams.Stdout && !streams.Stderr {
@ -1038,7 +1035,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
args = append(args, fmt.Sprintf("--sdnotify-socket=%s", ctr.config.SdNotifySocket))
}
if ctr.config.Spec.Process.Terminal {
if ctr.Terminal() {
args = append(args, "-t")
} else if ctr.config.Stdin {
args = append(args, "-i")
@ -1135,7 +1132,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if ctr.config.Spec.Process.Terminal {
if ctr.Terminal() {
cmd.Stderr = &stderrBuf
}

View File

@ -1690,10 +1690,8 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
return nil, err
}
conf := c.Config()
if conf.Spec != nil && conf.Spec.Process != nil && conf.Spec.Process.Terminal { // if we do not pass term, running ctrs exit
spec.Terminal = true
}
// if we do not pass term, running ctrs exit
spec.Terminal = c.Terminal()
// Print warnings
if len(out) > 0 {

View File

@ -49,7 +49,8 @@ func StartAttachCtr(ctx context.Context, ctr *libpod.Container, stdout, stderr,
// Check if we are attached to a terminal. If we are, generate resize
// events, and set the terminal to raw mode
if haveTerminal && ctr.Spec().Process.Terminal {
if haveTerminal && ctr.Terminal() {
cancel, oldTermState, err := handleTerminalAttach(ctx, resize)
if err != nil {
return err