Skip to content

Commit

Permalink
support update daemon with home-dir and snapshotter.
Browse files Browse the repository at this point in the history
Signed-off-by: allen.wang <allen.wq@alipay.com>
  • Loading branch information
wangforthinker authored and rudyfly committed Jan 29, 2019
1 parent 9f28670 commit a1dc96c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cli/update_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type DaemonUpdateCommand struct {
iptables bool
ipforward bool
userlandProxy bool

homeDir string
snapshotter string
}

// Init initialize updatedaemon command.
Expand Down Expand Up @@ -77,6 +80,8 @@ func (udc *DaemonUpdateCommand) addFlags() {
flagSet.BoolVar(&udc.iptables, "iptables", true, "update daemon with iptables")
flagSet.BoolVar(&udc.ipforward, "ipforward", true, "udpate daemon with ipforward")
flagSet.BoolVar(&udc.userlandProxy, "userland-proxy", false, "update daemon with userland proxy")
flagSet.StringVar(&udc.homeDir, "home-dir", "", "update daemon home dir")
flagSet.StringVar(&udc.snapshotter, "snapshotter", "", "update daemon snapshotter")
}

// daemonUpdateRun is the entry of updatedaemon command.
Expand Down Expand Up @@ -166,6 +171,14 @@ func (udc *DaemonUpdateCommand) updateDaemonConfigFile() error {
daemonConfig.NetworkConfig.BridgeConfig.UserlandProxy = udc.userlandProxy
}

if flagSet.Changed("home-dir") {
daemonConfig.HomeDir = udc.homeDir
}

if flagSet.Changed("snapshotter") {
daemonConfig.Snapshotter = udc.snapshotter
}

// write config to file
fd, err := os.OpenFile(udc.configFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions test/z_cli_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/daemon"
"github.com/alibaba/pouch/test/environment"
Expand Down Expand Up @@ -702,3 +703,38 @@ func (suite *PouchDaemonSuite) TestContainerdPIDReuse(c *check.C) {
c.Assert(cfg.StartDaemon(), check.IsNil)
defer cfg.KillDaemon()
}

// TestUpdateDaemonWithHomeDirAndSnapshotter tests update daemon with home-dir and snapshotter
func (suite *PouchDaemonSuite) TestUpdateDaemonWithHomeDirAndSnapshotter(c *check.C) {
path := "/tmp/pouchconfig.json"
fd, err := os.Create(path)
c.Assert(err, check.IsNil)
fd.Close()
defer os.Remove(path)

cfg := daemon.NewConfig()
err = cfg.StartDaemon()
c.Assert(err, check.IsNil)

defer cfg.KillDaemon()

tmpHomeDir := "/tmp/pouch_dir"
snapshotter := "test_snapshotter"

RunWithSpecifiedDaemon(&cfg, "updatedaemon", "--config-file", path, "--offline=true", "--home-dir", tmpHomeDir, "--snapshotter", snapshotter).Assert(c, icmd.Success)

ret := RunWithSpecifiedDaemon(&cfg, "info")
ret.Assert(c, icmd.Success)

f, err := os.Open(path)
c.Assert(err, check.IsNil)
defer f.Close()

readConfig := config.Config{}

err = json.NewDecoder(f).Decode(&readConfig)
c.Assert(err, check.IsNil)

c.Assert(readConfig.HomeDir, check.Equals, tmpHomeDir)
c.Assert(readConfig.Snapshotter, check.Equals, snapshotter)
}

0 comments on commit a1dc96c

Please sign in to comment.