Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #771 from Starnop/bug-ip
Browse files Browse the repository at this point in the history
feature: add golbal dfget params to the dfdaemon config
  • Loading branch information
lowzj authored Aug 5, 2019
2 parents 68ba7b4 + 1599fa2 commit 24aa469
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
3 changes: 0 additions & 3 deletions cmd/dfdaemon/app/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
40 changes: 22 additions & 18 deletions dfdaemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions dfdaemon/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
13 changes: 1 addition & 12 deletions dfdaemon/downloader/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ","))
Expand Down

0 comments on commit 24aa469

Please sign in to comment.