Skip to content

Commit

Permalink
Merge pull request #6246 from baude/v2remoterun
Browse files Browse the repository at this point in the history
v2 podman remote attach, start, and run
  • Loading branch information
openshift-merge-robot authored May 15, 2020
2 parents e601101 + ce56202 commit 59dd341
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/podman/containers/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ func attachFlags(flags *pflag.FlagSet) {

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: attachCommand,
})
flags := attachCommand.Flags()
attachFlags(flags)

registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerAttachCommand,
Parent: containerCmd,
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ func runFlags(flags *pflag.FlagSet) {
}
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: runCommand,
})
flags := runCommand.Flags()
runFlags(flags)

registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerRunCommand,
Parent: containerCmd,
})
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ func startFlags(flags *pflag.FlagSet) {
}
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: startCommand,
})
flags := startCommand.Flags()
startFlags(flags)

registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode},
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
Command: containerStartCommand,
Parent: containerCmd,
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/compat/containers_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package compat
import (
"net/http"

"github.com/sirupsen/logrus"

"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/api/handlers/utils"
"github.com/gorilla/schema"
"github.com/pkg/errors"
)

func StartContainer(w http.ResponseWriter, r *http.Request) {
Expand All @@ -23,8 +24,7 @@ func StartContainer(w http.ResponseWriter, r *http.Request) {
}
if len(query.DetachKeys) > 0 {
// TODO - start does not support adding detach keys
utils.BadRequest(w, "detachKeys", query.DetachKeys, errors.New("the detachKeys parameter is not supported yet"))
return
logrus.Info("the detach keys parameter is not supported on start container")
}
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
Expand Down
48 changes: 45 additions & 3 deletions pkg/domain/infra/tunnel/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/bindings"
"github.com/containers/libpod/pkg/bindings/containers"
"github.com/containers/libpod/pkg/domain/entities"
"github.com/containers/libpod/pkg/specgen"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func (ic *ContainerEngine) ContainerRunlabel(ctx context.Context, label string, image string, args []string, options entities.ContainerRunlabelOptions) error {
Expand Down Expand Up @@ -324,23 +326,63 @@ func (ic *ContainerEngine) ContainerLogs(ctx context.Context, containers []strin
}

func (ic *ContainerEngine) ContainerAttach(ctx context.Context, nameOrId string, options entities.AttachOptions) error {
return errors.New("not implemented")
return containers.Attach(ic.ClientCxt, nameOrId, &options.DetachKeys, nil, bindings.PTrue, options.Stdin, options.Stdout, options.Stderr)
}

func (ic *ContainerEngine) ContainerExec(ctx context.Context, nameOrId string, options entities.ExecOptions) (int, error) {
return 125, errors.New("not implemented")
}

func startAndAttach(ic *ContainerEngine, name string, detachKeys *string, input, output, errput *os.File) error { //nolint
attachErr := make(chan error)
go func() {
err := containers.Attach(ic.ClientCxt, name, detachKeys, bindings.PFalse, bindings.PTrue, input, output, errput)
attachErr <- err
}()

if err := containers.Start(ic.ClientCxt, name, detachKeys); err != nil {
return err
}
return <-attachErr
}

func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
return nil, errors.New("not implemented")
var reports []*entities.ContainerStartReport
for _, name := range namesOrIds {
report := entities.ContainerStartReport{Id: name}
if options.Attach {
report.Err = startAndAttach(ic, name, &options.DetachKeys, options.Stdin, options.Stdout, options.Stderr)
reports = append(reports, &report)
return reports, nil
}
report.Err = containers.Start(ic.ClientCxt, name, &options.DetachKeys)
reports = append(reports, &report)
}
return reports, nil
}

func (ic *ContainerEngine) ContainerList(ctx context.Context, options entities.ContainerListOptions) ([]entities.ListContainer, error) {
return containers.List(ic.ClientCxt, options.Filters, &options.All, &options.Last, &options.Pod, &options.Size, &options.Sync)
}

func (ic *ContainerEngine) ContainerRun(ctx context.Context, opts entities.ContainerRunOptions) (*entities.ContainerRunReport, error) {
return nil, errors.New("not implemented")
if opts.Rm {
logrus.Info("the remote client does not support --rm yet")
}
con, err := containers.CreateWithSpec(ic.ClientCxt, opts.Spec)
if err != nil {
return nil, err
}
report := entities.ContainerRunReport{Id: con.ID}
// Attach
if !opts.Detach {
err = startAndAttach(ic, con.ID, &opts.DetachKeys, opts.InputStream, opts.OutputStream, opts.ErrorStream)

} else {
err = containers.Start(ic.ClientCxt, con.ID, nil)
}
report.ExitCode = define.ExitCode(err)
return &report, err
}

func (ic *ContainerEngine) ContainerDiff(ctx context.Context, nameOrId string, _ entities.DiffOptions) (*entities.DiffReport, error) {
Expand Down

0 comments on commit 59dd341

Please sign in to comment.