diff --git a/cli/update_daemon.go b/cli/update_daemon.go index b767ebde4..bf0403a86 100644 --- a/cli/update_daemon.go +++ b/cli/update_daemon.go @@ -40,6 +40,9 @@ type DaemonUpdateCommand struct { iptables bool ipforward bool userlandProxy bool + + homeDir string + snapshotter string } // Init initialize updatedaemon command. @@ -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. @@ -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 { diff --git a/test/z_cli_daemon_test.go b/test/z_cli_daemon_test.go index bd20173bf..bb43ea1bb 100644 --- a/test/z_cli_daemon_test.go +++ b/test/z_cli_daemon_test.go @@ -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" @@ -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) +}