DaemonCli: Move check into startMetricsServer
Fix TODO: move into startMetricsServer() Fix errors.Wrap return nil when passed err is nil Co-Authored-By: Sebastiaan van Stijn <thaJeztah@users.noreply.github.com> Signed-off-by: HuanHuan Ye <logindaveye@gmail.com>
This commit is contained in:
parent
536e26c81a
commit
88c554f950
2 changed files with 14 additions and 11 deletions
|
@ -208,15 +208,11 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
return errors.Wrap(err, "failed to validate authorization plugin")
|
||||
}
|
||||
|
||||
// TODO: move into startMetricsServer()
|
||||
if cli.Config.MetricsAddress != "" {
|
||||
if !d.HasExperimental() {
|
||||
return errors.Wrap(err, "metrics-addr is only supported when experimental is enabled")
|
||||
}
|
||||
if err := startMetricsServer(cli.Config.MetricsAddress); err != nil {
|
||||
cli.d = d
|
||||
|
||||
if err := cli.startMetricsServer(cli.Config.MetricsAddress); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c, err := createAndStartCluster(cli, d)
|
||||
if err != nil {
|
||||
|
@ -230,8 +226,6 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
|||
|
||||
logrus.Info("Daemon has completed initialization")
|
||||
|
||||
cli.d = d
|
||||
|
||||
routerOptions, err := newRouterOptions(cli.Config, d)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -5,10 +5,19 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/docker/go-metrics"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func startMetricsServer(addr string) error {
|
||||
func (cli *DaemonCli) startMetricsServer(addr string) error {
|
||||
if addr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !cli.d.HasExperimental() {
|
||||
return errors.New("metrics-addr is only supported when experimental is enabled")
|
||||
}
|
||||
|
||||
if err := allocateDaemonPort(addr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue