Repository: hashicorp/nomad
File: command/agent/command.go (Go)

Code before:
		c.agent.logger.Debug("starting reload of server config")
		sconf, err := convertServerConfig(newConf)
		if err != nil {
			c.agent.logger.Error("failed to convert server config", "error", err)
			return nil
		}

		// Finalize the config to get the agent objects injected in
		c.agent.finalizeServerConfig(sconf)

		// Reload the config
		if err := s.Reload(sconf); err != nil {
			c.agent.logger.Error("reloading server config failed", "error", err)
			return fmt.Errorf("reloading server config failed: %w", err)
		}
	}

	if client := c.agent.Client(); client != nil {
		c.agent.logger.Debug("starting reload of client config")
		clientConfig, err := convertClientConfig(newConf)
		if err != nil {
			c.agent.logger.Error("failed to convert client config", "error", err)
			return nil
		}

		// Finalize the config to get the agent objects injected in
		if err := c.agent.finalizeClientConfig(clientConfig); err != nil {
			c.agent.logger.Error("failed to finalize client config", "error", err)
			return nil
		}

		if err := client.Reload(clientConfig); err != nil {
			c.agent.logger.Error("reloading client config failed", "error", err)
			return fmt.Errorf("reloading client config failed: %w", err)
		}
	}

	// reload HTTP server after we have reloaded both client and server, in case
	// we error in either of the above cases. For example, reloading the http
	// server to a TLS connection could succeed, while reloading the server's rpc
	// connections could fail.
	if shouldReloadHTTP {
		err := c.reloadHTTPServer()
		if err != nil {
			c.agent.httpLogger.Error("reloading config failed", "error", err)
			return nil
		}
	}
	return nil
}


Review comment (suggestion):
This and below should be called out as breaking changes in the changelog. Something like:

```
core: Errors encountered when reloading agent configuration will now cause agents to exit. Before configuration errors during reloads were only logged. This could lead to agents running but unable to communicate.
```

...or something. I _think_ this is always preferable. It's pretty clear glancing at https://github.com/hashicorp/nomad/blob/v1.10.0/nomad/server.go#L684-L697 that encountering an error in either of those 2 places during a reload could leave you with a zombie server! Not great!

However maybe some operators really loved banging away at their server configs and watching logs for feedback? Seems like a bad way to live, so I think it's ok to make this breaking change, alert users, and wait for someone to file an issue if there's a valid reason to _sometimes_ keep running in this error-on-reload scenario.

Code after:

	shouldReloadAgent, shouldReloadHTTP := c.agent.ShouldReload(newConf)
	if shouldReloadAgent {
		c.agent.logger.Debug("starting reload of agent config")
		err := c.agent.Reload(newConf)
		if err != nil {
			c.agent.logger.Error("failed to reload the config", "error", err)
			return nil
		}
	}

	if s := c.agent.Server(); s != nil {
		c.agent.logger.Debug("starting reload of server config")
		sconf, err := convertServerConfig(newConf)
		if err != nil {
			c.agent.logger.Error("failed to convert server config", "error", err)
			return nil
		}

		// Finalize the config to get the agent objects injected in
		c.agent.finalizeServerConfig(sconf)

		// Reload the config
		if err := s.Reload(sconf); err != nil {
			c.agent.logger.Error("reloading server config failed", "error", err)
			return fmt.Errorf("reloading server config failed: %w", err)
		}
	}

	if client := c.agent.Client(); client != nil {
		c.agent.logger.Debug("starting reload of client config")
		clientConfig, err := convertClientConfig(newConf)
		if err != nil {
			c.agent.logger.Error("failed to convert client config", "error", err)
			return nil
		}

		// Finalize the config to get the agent objects injected in
		if err := c.agent.finalizeClientConfig(clientConfig); err != nil {
			c.agent.logger.Error("failed to finalize client config", "error", err)
			return nil
		}

		if err := client.Reload(clientConfig); err != nil {
			c.agent.logger.Error("reloading client config failed", "error", err)
			return fmt.Errorf("reloading client config failed: %w", err)
		}
	}

	// reload HTTP server after we have reloaded both client and server, in case
	// we error in either of the above cases. For example, reloading the http