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

feature: deamon support --log-driver and --log-opt options #1647

Merged

Conversation

zhuangqh
Copy link
Contributor

@zhuangqh zhuangqh commented Jul 6, 2018

Signed-off-by: zhuangqh zhuangqhc@gmail.com

Ⅰ. Describe what this PR did

pouchd could start with --log-driver and --log-opt as the default configuration of log driver.

Ⅱ. Does this pull request fix one issue?

fixes #1646

Ⅲ. Describe how you did it

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

Due to the defect of go-swagger v0.12, the validation of these options are temporarily noneffective.

@zhuangqh
Copy link
Contributor Author

zhuangqh commented Jul 6, 2018

PTAL @fuweid

main.go Outdated
@@ -105,6 +107,10 @@ func setupFlags(cmd *cobra.Command) {
flagSet.BoolVar(&cfg.NetworkConfig.BridgeConfig.IPForward, "ipforward", true, "Enable ipforward")
flagSet.BoolVar(&cfg.NetworkConfig.BridgeConfig.UserlandProxy, "userland-proxy", false, "Enable userland proxy")

// log config
flagSet.StringVar(&cfg.DefaultLogConfig.LogDriver, "log-driver", "", "Set default log driver")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can set the log-driver to jsonfile, like mody does. WDTY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. If log-driver is empty, CI will fail.

main.go Outdated
@@ -19,6 +19,7 @@ import (
"github.com/alibaba/pouch/storage/quota"
"github.com/alibaba/pouch/version"

"github.com/alibaba/pouch/apis/opts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put this line to previous group.

LogDriver: types.LogConfigLogDriverJSONFile,
}
defaultConfig := mgr.Config.DefaultLogConfig
config.HostConfig.LogConfig = &defaultConfig
Copy link
Contributor

@fuweid fuweid Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request maybe come from swarm. If it does, the config.HostConfig.LogConfig is not nil but the value is empty. For this case, the config.HostConfig.LogConfig.LogDriver is empty and config.HostConfig.LogConfig. LogOpts is nil.

It isn't good practice in API design. However, we need to compatible with legacy system. Add other check that config.HostConfig.LogConfig is empty or not. WDTY?

}
// note: request from swarm is not standard. config.HostConfig.LogConfig is not nil, but its value is empty.
// We need to be compatible with this legacy system.
if config.HostConfig.LogConfig == nil || config.HostConfig.LogConfig.LogDriver == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use helper function to check the config.HostConfig.LogConfig is empty or not?

Like,

func isEmptyLogConfig(xx *types.LogConfig) bool {
      if config.HostConfig.LogConfig == nil  {
           return true
      }
      return config.HostConfig.LogConfig.LogDriver == "" && len(config.HostConfig.LogConfig.LogOpts) == 0
}

WDTY?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Thanks

main.go Outdated
@@ -105,6 +107,10 @@ func setupFlags(cmd *cobra.Command) {
flagSet.BoolVar(&cfg.NetworkConfig.BridgeConfig.IPForward, "ipforward", true, "Enable ipforward")
flagSet.BoolVar(&cfg.NetworkConfig.BridgeConfig.UserlandProxy, "userland-proxy", false, "Enable userland proxy")

// log config
flagSet.StringVar(&cfg.DefaultLogConfig.LogDriver, "log-driver", "jsonfile", "Set default log driver")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/"jsonfile"/types.LogConfigLogDriverJSONFile 😄

@codecov-io
Copy link

codecov-io commented Jul 7, 2018

Codecov Report

Merging #1647 into master will decrease coverage by 23.33%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1647       +/-   ##
===========================================
- Coverage   41.45%   18.12%   -23.34%     
===========================================
  Files         273      226       -47     
  Lines       17714    15033     -2681     
===========================================
- Hits         7344     2725     -4619     
- Misses       9461    12127     +2666     
+ Partials      909      181      -728
Impacted Files Coverage Δ
daemon/mgr/container.go 0% <0%> (-50.4%) ⬇️
pkg/httputils/http_error.go 0% <0%> (-100%) ⬇️
pkg/httputils/http_utils.go 0% <0%> (-100%) ⬇️
apis/server/router.go 0% <0%> (-91.37%) ⬇️
daemon/mgr/container_state.go 0% <0%> (-87.24%) ⬇️
apis/server/volume_bridge.go 0% <0%> (-86.67%) ⬇️
daemon/mgr/container_monitor.go 0% <0%> (-85.19%) ⬇️
daemon/mgr/container_logger.go 0% <0%> (-84%) ⬇️
daemon/mgr/spec_annotations.go 0% <0%> (-82.36%) ⬇️
apis/server/container_bridge.go 0% <0%> (-82.02%) ⬇️
... and 125 more

@@ -414,6 +410,23 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty
}, nil
}

// set manager log config to the container's log config if the container's log config is not specified.
func (mgr *ContainerManager) setDefaultLogConfig(logConfig *types.LogConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/setDefaultLogConfig/setDefaultLogConfigIfMissing/g

@@ -414,6 +410,23 @@ func (mgr *ContainerManager) Create(ctx context.Context, name string, config *ty
}, nil
}

// set manager log config to the container's log config if the container's log config is not specified.
func (mgr *ContainerManager) setDefaultLogConfig(logConfig *types.LogConfig) {
if logConfig == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can set the value to the config, since it is not pointer to pointer

@zhuangqh zhuangqh force-pushed the feature_log_driver_option branch 3 times, most recently from ac009f4 to ed72940 Compare July 9, 2018 03:50
Signed-off-by: zhuangqh <zhuangqhc@gmail.com>
@fuweid
Copy link
Contributor

fuweid commented Jul 9, 2018

LGTM

@fuweid fuweid merged commit 7ec009e into AliyunContainerService:master Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] pouch daemon starts with default --log-driver and --log-opt options
4 participants