Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
feature: add golbal dfget params in the dfdaemon config
Browse files Browse the repository at this point in the history
Signed-off-by: Starnop <[email protected]>
  • Loading branch information
starnop committed Aug 2, 2019
1 parent 4b2a3fc commit 7f14569
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 50 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
44 changes: 19 additions & 25 deletions dfdaemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var fs = afero.NewOsFs()
// Properties holds all configurable properties of dfdaemon.
// The default path is '/etc/dragonfly/dfdaemon.yml'
// For examples:
// global_dfget_params: ["--node","192.168.33.21","--verbose","--ip","192.168.33.23","--port","15001"]
//
// registry_mirror:
// # url for the registry mirror
// remote: https://index.docker.io
Expand Down Expand Up @@ -88,18 +90,16 @@ type Properties struct {
CertPem string `yaml:"certpem" json:"certpem"`
KeyPem string `yaml:"keypem" json:"keypem"`

// dfget config
SuperNodes []string `yaml:"supernodes" json:"supernodes"`
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"`

// dfget config
GlobalDfgetParams []string `yaml:"global_dfget_params" json:"global_dfget_params"`
SuperNodes []string `yaml:"supernodes" json:"supernodes"`
RateLimit string `yaml:"ratelimit" json:"ratelimit"`
DFRepo string `yaml:"localrepo" json:"localrepo"`
DFPath string `yaml:"dfpath" json:"dfpath"`
}

// Validate validates the config
Expand Down Expand Up @@ -138,27 +138,21 @@ func (p *Properties) Validate() error {
// DFGetConfig returns config for dfget downloader
func (p *Properties) DFGetConfig() DFGetConfig {
return DFGetConfig{
SuperNodes: p.SuperNodes,
DFRepo: p.DFRepo,
DFPath: p.DFPath,
RateLimit: p.RateLimit,
URLFilter: p.URLFilter,
CallSystem: p.CallSystem,
Notbs: p.Notbs,
Verbose: p.Verbose,
GlobalDfgetParams: p.GlobalDfgetParams,
SuperNodes: p.SuperNodes,
RateLimit: p.RateLimit,
DFRepo: p.DFRepo,
DFPath: p.DFPath,
}
}

// DFGetConfig configures how dfdaemon calls dfget
type DFGetConfig struct {
SuperNodes []string `yaml:"supernodes"`
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"`
GlobalDfgetParams []string `yaml:"global_dfget_params"`
SuperNodes []string `yaml:"supernodes"`
RateLimit string `yaml:"ratelimit"`
DFRepo string `yaml:"localrepo"`
DFPath string `yaml:"dfpath"`
}

// 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
11 changes: 2 additions & 9 deletions dfdaemon/downloader/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,15 @@ func (dfGetter *DFGetter) getCommand(
"-o", output,
}

if dfGetter.config.Notbs {
args = append(args, "--notbs")
}

if dfGetter.config.Verbose {
args = append(args, "--verbose")
for _, param := range dfGetter.config.GlobalDfgetParams {
args = append(args, param)
}

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 7f14569

Please sign in to comment.