Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure daemon start successfully after update damon offline #1743

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cli/update_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (udc *DaemonUpdateCommand) updateDaemonConfigFile() error {
}

daemonConfig := &config.Config{}
if err = json.NewDecoder(bytes.NewReader(contents)).Decode(daemonConfig); err != nil {
return errors.Wrap(err, "failed to decode json: %s")
// do not return error if config file is empty
if err := json.NewDecoder(bytes.NewReader(contents)).Decode(daemonConfig); err != nil && err != io.EOF {
return errors.Wrapf(err, "failed to decode json: %s", udc.configFile)
}

flagSet := udc.cmd.Flags()
Expand Down
5 changes: 3 additions & 2 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ type Config struct {
// add a resolution later if it needed.
Runtimes map[string]types.Runtime `json:"add-runtime,omitempty"`

// Namespace is passed to containerd
Namespace string
// Namespace is passed to containerd, Namespace is not a daemon flag,
// do not marshal this field to config file.
Namespace string `json:"-"`
}

// Validate validates the user input config.
Expand Down
21 changes: 21 additions & 0 deletions test/z_cli_daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ func (suite *PouchDaemonSuite) TestDaemonWithMultiRuntimes(c *check.C) {
dcfg2.KillDaemon()
}

// TestUpdateDaemonWithLabels tests update daemon online with labels updated
func (suite *PouchDaemonSuite) TestUpdateDaemonWithLabels(c *check.C) {
cfg := daemon.NewConfig()
err := cfg.StartDaemon()
Expand All @@ -485,3 +486,23 @@ func (suite *PouchDaemonSuite) TestUpdateDaemonWithLabels(c *check.C) {
updated := strings.Contains(ret.Stdout(), "aaa=bbb")
c.Assert(updated, check.Equals, true)
}

// TestUpdateDaemonWithLabels tests update daemon offline
func (suite *PouchDaemonSuite) TestUpdateDaemonOffline(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()

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

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