Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
Made changes to handle pause container so that k8s can use runnc (min…
Browse files Browse the repository at this point in the history
…us network) (#34)

* Made changes so that k8s can use runnc (minus network)

Signed-off-by: Brandon Lum <[email protected]>

* Updated travis to use proper golint path

Signed-off-by: Brandon Lum <[email protected]>
  • Loading branch information
lumjjb authored Oct 12, 2018
1 parent db99d2c commit 1e8765d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ before_install:
- echo "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
- sudo apt-get -qq update
- sudo apt-get install -y libseccomp-dev/trusty-backports genisoimage
- go get -u github.com/golang/lint/golint
- go get -u golang.org/x/lint/golint
- go get -u github.com/vbatts/git-validation
- go get -u github.com/golang/dep/cmd/dep
- env | grep TRAVIS_
Expand Down
35 changes: 31 additions & 4 deletions libcontainer/factory_nabla.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
const (
stateFilename = "state.json"
execFifoFilename = "exec.fifo"
pauseNablaName = "pause.nabla"
)

var (
Expand Down Expand Up @@ -68,6 +69,19 @@ type NablaFactory struct {
Root string
}

func isPauseContainer(config *configs.Config) bool {
return len(config.Args) == 1 && config.Args[0] == "/pause"
}

func applyPauseHack(config *configs.Config, containerRoot string) (*configs.Config, error) {
if !isPauseContainer(config) {
return nil, errors.New("Trying to make pause changes on non-pause container")
}

config.Args = []string{pauseNablaName}
return config, nil
}

func createRootfsISO(config *configs.Config, containerRoot string) (string, error) {
rootfsPath := config.Rootfs
targetISOPath := filepath.Join(containerRoot, "rootfs.iso")
Expand All @@ -93,6 +107,7 @@ func (l *NablaFactory) Create(id string, config *configs.Config) (Container, err
if err := l.validateID(id); err != nil {
return nil, err
}

//if err := l.Validator.Validate(config); err != nil {
// return nil, err
//}
Expand Down Expand Up @@ -128,14 +143,26 @@ func (l *NablaFactory) Create(id string, config *configs.Config) (Container, err
return nil, err
}

fsPath, err := createRootfsISO(config, containerRoot)
if err != nil {
return nil, err
// If it is a pause container for kubernetes, set config so that init
// will just pause instead of executing a nabla
fsPath := ""
if isPauseContainer(config) {
config, err = applyPauseHack(config, containerRoot)
if err != nil {
return nil, err
}
} else {
fsPath, err = createRootfsISO(config, containerRoot)
if err != nil {
return nil, err
}
}

err = network.CreateTapInterface(nablaTapName(id), nil, nil)
if err != nil {
os.Remove(fsPath)
if fsPath != "" {
os.Remove(fsPath)
}
return nil, fmt.Errorf("Unable to create tap interface: %v", err)
}

Expand Down
7 changes: 6 additions & 1 deletion libcontainer/init_nabla.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func nablaRunArgs(cfg *initConfig) ([]string, error) {
args = append(args, "--")
args = append(args, cfg.Args[1:]...)

fmt.Printf("Running with args: %v", args)
fmt.Fprintf(os.Stderr, "Running with args: %v", args)
return args, nil
}

Expand Down Expand Up @@ -108,6 +108,11 @@ func initNabla() error {
syscall.Close(fd)
syscall.Close(rootfd)

// Check if it is a pause container, if it is, just pause
if len(config.Args) == 1 && config.Args[0] == pauseNablaName {
select {}
}

runArgs, err := nablaRunArgs(config)
if err != nil {
return newSystemErrorWithCause(err, "Unable to construct nabla run args")
Expand Down
7 changes: 4 additions & 3 deletions nabla-lib/storage/storage_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package storage

import (
"github.com/pkg/errors"
"io/ioutil"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -52,20 +53,20 @@ func CreateIso(dir string, target *string) (string, error) {
var err error
fname, err = filepath.Abs(*target)
if err != nil {
return "", err
return "", errors.Wrap(err, "Unable to resolve abs target path")
}
}

absDir, err := filepath.Abs(dir)
if err != nil {
return "", err
return "", errors.Wrap(err, "Unable to resolve abs dir path")
}

cmd := exec.Command("genisoimage", "-m", "dev", "-m", "sys",
"-m", "proc", "-l", "-r", "-o", fname, absDir)
err = cmd.Run()
if err != nil {
return "", err
return "", errors.Wrap(err, "Unable to run geniso command")
}

return fname, nil
Expand Down
7 changes: 7 additions & 0 deletions runnc-cli/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"os"
"path/filepath"
"strings"
)

// fatal prints the error's details if it is a libcontainer specific error type
Expand All @@ -44,6 +46,11 @@ func setupSpec(context *cli.Context) (*specs.Spec, error) {
if err != nil {
return nil, err
}

if spec.Root != nil && !strings.HasPrefix(spec.Root.Path, "/") {
spec.Root.Path = filepath.Join(bundle, spec.Root.Path)
}

notifySocket := os.Getenv("NOTIFY_SOCKET")
if notifySocket != "" {
setupSdNotify(spec, notifySocket)
Expand Down

0 comments on commit 1e8765d

Please sign in to comment.