Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
shim: invoke kata shim if asked
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Tao <[email protected]>
  • Loading branch information
bergwolf committed Feb 11, 2018
1 parent aaf9e73 commit 691cf49
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cli/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strings"
"sync"
"syscall"

Expand All @@ -20,6 +21,8 @@ import (
"github.com/urfave/cli"
)

const KataShimBinary = "/usr/libexec/kata-containers/kata-shim"

var shimCommand = cli.Command{
Name: "shim",
Usage: "[internal command] proxy operations(io, signal ...) to the container/process",
Expand Down Expand Up @@ -153,6 +156,20 @@ func forwardAllSignals(h agent.SandboxAgent, container, process string) chan os.
return sigc
}

func prepareKataShim(options runvOptions, container, process string, terminal bool) (string, []string, error) {
args := []string{"kata-shim"}
if options.GlobalBool("debug") {
args = append(args, "--log", "debug")
}
agentAddr := filepath.Join(options.GlobalString("root"), container, "sandbox", "kata-agent.sock")
args = append(args, "--agent", agentAddr, "--container", container, "--exec-id", process)
if terminal {
args = append(args, "--terminal")
}

return KataShimBinary, args, nil
}

func prepareRunvShim(options runvOptions, container, process string, terminal bool) (string, []string, error) {
path, err := osext.Executable()
if err != nil {
Expand Down Expand Up @@ -194,10 +211,19 @@ func createShim(options runvOptions, container, process string, spec *specs.Proc
ptymaster.Close()
}

path, args, err := prepareRunvShim(options, container, process, spec.Terminal)
var (
path string
args []string
)
if options.GlobalString("agent") != "kata" {
path, args, err = prepareRunvShim(options, container, process, spec.Terminal)
} else {
path, args, err = prepareKataShim(options, container, process, spec.Terminal)
}
if err != nil {
return nil, err
}
glog.V(3).Infof("starting shim with args %s", strings.Join(args, " "))

cmd := exec.Cmd{
Path: path,
Expand Down

0 comments on commit 691cf49

Please sign in to comment.