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

feature: add golbal dfget params to the dfdaemon config #771

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

@lowzj lowzj Aug 2, 2019

Choose a reason for hiding this comment

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

This should not be deleted if the --verbose flag of dfdaemon has been set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. PTAL again. THX

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