From fae32223e62c9af795c2f42868fcbc4955d7f8a8 Mon Sep 17 00:00:00 2001 From: Eugene Yakubovich Date: Thu, 22 Jan 2015 11:45:42 -0800 Subject: [PATCH] net: add --private-net to run cmd --- build | 2 +- rkt/run.go | 5 ++++- stage0/run.go | 12 ++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/build b/build index f72e4b0..a62380b 100755 --- a/build +++ b/build @@ -24,7 +24,7 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then echo "Building init (stage1)..." go build -o $GOBIN/init ${REPO_PATH}/stage1/init - echo "Copying network plugins to stage1" + # symlink plugin binaries into stage1 rootfs mkdir -p stage1/rootfs/net-plugins/bin for d in networking/plugins/*; do plugin=$(basename $d) diff --git a/rkt/run.go b/rkt/run.go index d692f7f..549ffa5 100644 --- a/rkt/run.go +++ b/rkt/run.go @@ -34,6 +34,7 @@ var ( flagStage1Init string flagStage1Rootfs string flagVolumes volumeMap + flagPrivateNet bool cmdRun = &Command{ Name: "run", Summary: "Run image(s) in an application container in rocket", @@ -49,6 +50,7 @@ func init() { cmdRun.Flags.StringVar(&flagStage1Init, "stage1-init", "", "path to stage1 binary override") cmdRun.Flags.StringVar(&flagStage1Rootfs, "stage1-rootfs", "", "path to stage1 rootfs tarball override") cmdRun.Flags.Var(&flagVolumes, "volume", "volumes to mount into the shared container environment") + cmdRun.Flags.BoolVar(&flagPrivateNet, "private-net", false, "give container a private network") flagVolumes = volumeMap{} } @@ -136,13 +138,14 @@ func runRun(args []string) (exit int) { Stage1Rootfs: flagStage1Rootfs, Images: imgs, Volumes: flagVolumes, + PrivateNet: flagPrivateNet, } cdir, err := stage0.Setup(cfg) if err != nil { fmt.Fprintf(os.Stderr, "run: error setting up stage0: %v\n", err) return 1 } - stage0.Run(cdir, cfg.Debug) // execs, never returns + stage0.Run(cfg, cdir) // execs, never returns return 1 } diff --git a/stage0/run.go b/stage0/run.go index c2a2073..ca9aa64 100644 --- a/stage0/run.go +++ b/stage0/run.go @@ -64,8 +64,9 @@ type Config struct { Stage1Rootfs string // compressed bundle containing a rootfs for stage1 Debug bool // TODO(jonboulle): These images are partially-populated hashes, this should be clarified. - Images []types.Hash // application images - Volumes map[string]string // map of volumes that rocket can provide to applications + Images []types.Hash // application images + Volumes map[string]string // map of volumes that rocket can provide to applications + PrivateNet bool // container should have its own network stack } func init() { @@ -195,7 +196,7 @@ func Setup(cfg Config) (string, error) { // Run actually runs the container by exec()ing the stage1 init inside // the container filesystem. -func Run(dir string, debug bool) { +func Run(cfg Config, dir string) { log.Printf("Pivoting to filesystem %s", dir) if err := os.Chdir(dir); err != nil { log.Fatalf("failed changing to dir: %v", err) @@ -203,9 +204,12 @@ func Run(dir string, debug bool) { log.Printf("Execing %s", initPath) args := []string{initPath} - if debug { + if cfg.Debug { args = append(args, "--debug") } + if cfg.PrivateNet { + args = append(args, "--private-net") + } if err := syscall.Exec(initPath, args, os.Environ()); err != nil { log.Fatalf("error execing init: %v", err) }