From 1599fa20e003da1aa6ddf4f60a8fb299fc32817b Mon Sep 17 00:00:00 2001 From: Starnop Date: Thu, 1 Aug 2019 19:33:17 +0800 Subject: [PATCH] feature: add golbal dfget params in the dfdaemon config Signed-off-by: Starnop --- cmd/dfdaemon/app/root.go | 3 --- dfdaemon/config/config.go | 40 ++++++++++++++++-------------- dfdaemon/config/config_test.go | 13 ---------- dfdaemon/downloader/dfget/dfget.go | 13 +--------- 4 files changed, 23 insertions(+), 46 deletions(-) diff --git a/cmd/dfdaemon/app/root.go b/cmd/dfdaemon/app/root.go index efb35f487..2effb4f95 100644 --- a/cmd/dfdaemon/app/root.go +++ b/cmd/dfdaemon/app/root.go @@ -91,11 +91,8 @@ func init() { // dfget download config rf.String("localrepo", filepath.Join(os.Getenv("HOME"), ".small-dragonfly/dfdaemon/data/"), "temp output dir of dfdaemon") - rf.String("callsystem", "com_ops_dragonfly", "caller name") rf.String("dfpath", defaultDfgetPath, "dfget path") rf.String("ratelimit", netutils.NetLimit(), "net speed limit,format:xxxM/K") - rf.String("urlfilter", "Signature&Expires&OSSAccessKeyId", "filter specified url fields") - rf.Bool("notbs", true, "not try back source to download if throw exception") rf.StringSlice("node", nil, "specify the addresses(host:port) of supernodes that will be passed to dfget.") exitOnError(bindRootFlags(viper.GetViper()), "bind root command flags") diff --git a/dfdaemon/config/config.go b/dfdaemon/config/config.go index 5684f767b..4e4b68448 100644 --- a/dfdaemon/config/config.go +++ b/dfdaemon/config/config.go @@ -40,6 +40,10 @@ var fs = afero.NewOsFs() // Properties holds all configurable properties of dfdaemon. // The default path is '/etc/dragonfly/dfdaemon.yml' // For examples: +// dfget_flags: ["--node","192.168.33.21","--verbose","--ip","192.168.33.23", +// "--port","15001","--expiretime","3m0s","--alivetime","5m0s", +// "-f","filterParam1&filterParam2"] +// // registry_mirror: // # url for the registry mirror // remote: https://index.docker.io @@ -88,18 +92,16 @@ type Properties struct { CertPem string `yaml:"certpem" json:"certpem"` KeyPem string `yaml:"keypem" json:"keypem"` + Verbose bool `yaml:"verbose" json:"verbose"` + + MaxProcs int `yaml:"maxprocs" json:"maxprocs"` + // dfget config + DfgetFlags []string `yaml:"dfget_flags" json:"dfget_flags"` SuperNodes []string `yaml:"supernodes" json:"supernodes"` + RateLimit string `yaml:"ratelimit" json:"ratelimit"` DFRepo string `yaml:"localrepo" json:"localrepo"` DFPath string `yaml:"dfpath" json:"dfpath"` - RateLimit string `yaml:"ratelimit" json:"ratelimit"` - URLFilter string `yaml:"urlfilter" json:"urlfilter"` - CallSystem string `yaml:"callsystem" json:"callsystem"` - Notbs bool `yaml:"notbs" json:"notbs"` - - Verbose bool `yaml:"verbose" json:"verbose"` - - MaxProcs int `yaml:"maxprocs" json:"maxprocs"` } // Validate validates the config @@ -137,28 +139,30 @@ func (p *Properties) Validate() error { // DFGetConfig returns config for dfget downloader func (p *Properties) DFGetConfig() DFGetConfig { + // init DfgetFlags + var dfgetFlags []string + dfgetFlags = append(dfgetFlags, p.DfgetFlags...) + dfgetFlags = append(dfgetFlags, "--dfdaemon") + if p.Verbose { + dfgetFlags = append(dfgetFlags, "--verbose") + } + return DFGetConfig{ + DfgetFlags: dfgetFlags, SuperNodes: p.SuperNodes, + RateLimit: p.RateLimit, DFRepo: p.DFRepo, DFPath: p.DFPath, - RateLimit: p.RateLimit, - URLFilter: p.URLFilter, - CallSystem: p.CallSystem, - Notbs: p.Notbs, - Verbose: p.Verbose, } } // DFGetConfig configures how dfdaemon calls dfget type DFGetConfig struct { + DfgetFlags []string `yaml:"dfget_flags"` SuperNodes []string `yaml:"supernodes"` + RateLimit string `yaml:"ratelimit"` DFRepo string `yaml:"localrepo"` DFPath string `yaml:"dfpath"` - RateLimit string `yaml:"ratelimit"` - URLFilter string `yaml:"urlfilter"` - CallSystem string `yaml:"callsystem"` - Notbs bool `yaml:"notbs"` - Verbose bool `yaml:"verbose"` } // RegistryMirror configures the mirror of the official docker registry diff --git a/dfdaemon/config/config_test.go b/dfdaemon/config/config_test.go index 3ea08d1a2..622bc8d9f 100644 --- a/dfdaemon/config/config_test.go +++ b/dfdaemon/config/config_test.go @@ -266,19 +266,6 @@ func (ts *configTestSuite) TestProxyMatch() { } -func (ts *configTestSuite) TestDFGetConfig() { - r := ts.Require() - cfg := defaultConfig() - dfgetCfg := cfg.DFGetConfig() - r.Equal(cfg.SuperNodes, dfgetCfg.SuperNodes) - r.Equal(cfg.DFRepo, dfgetCfg.DFRepo) - r.Equal(cfg.DFPath, dfgetCfg.DFPath) - r.Equal(cfg.RateLimit, dfgetCfg.RateLimit) - r.Equal(cfg.URLFilter, dfgetCfg.URLFilter) - r.Equal(cfg.CallSystem, dfgetCfg.CallSystem) - r.Equal(cfg.Notbs, dfgetCfg.Notbs) -} - func (ts *configTestSuite) TestMirrorTLSConfig() { r := ts.Require() diff --git a/dfdaemon/downloader/dfget/dfget.go b/dfdaemon/downloader/dfget/dfget.go index 3ed3d515f..a36a087e2 100644 --- a/dfdaemon/downloader/dfget/dfget.go +++ b/dfdaemon/downloader/dfget/dfget.go @@ -64,27 +64,16 @@ func (dfGetter *DFGetter) getCommand( url string, header map[string][]string, output string, ) (cmd *exec.Cmd) { args := []string{ - "--dfdaemon", "-u", url, "-o", output, } - - if dfGetter.config.Notbs { - args = append(args, "--notbs") - } - - if dfGetter.config.Verbose { - args = append(args, "--verbose") - } + args = append(args, dfGetter.config.DfgetFlags...) add := func(key, value string) { if v := strings.TrimSpace(value); v != "" { args = append(args, key, v) } } - - add("--callsystem", dfGetter.config.CallSystem) - add("-f", dfGetter.config.URLFilter) add("-s", dfGetter.config.RateLimit) add("--totallimit", dfGetter.config.RateLimit) add("--node", strings.Join(dfGetter.config.SuperNodes, ","))