-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Add command storeconfig #551
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,28 @@ Complete documentation is available at https://traefik.io`, | |
}, | ||
} | ||
|
||
//storeconfig Command init | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note for later: we might want to split There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would like to add a file "commands.go" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure yet 👼 |
||
var kv *staert.KvSource | ||
var err error | ||
|
||
storeconfigCmd := &flaeg.Command{ | ||
Name: "storeconfig", | ||
Description: `Store the static traefik configuration into a Key-value stores. Traefik will not start.`, | ||
Config: traefikConfiguration, | ||
DefaultPointersConfig: traefikPointersConfiguration, | ||
Run: func() error { | ||
if kv == nil { | ||
return fmt.Errorf("Error using command storeconfig, no Key-value store defined") | ||
} | ||
jsonConf, _ := json.Marshal(traefikConfiguration.GlobalConfiguration) | ||
fmtlog.Printf("Storing configuration: %s\n", jsonConf) | ||
return kv.StoreConfig(traefikConfiguration.GlobalConfiguration) | ||
}, | ||
Metadata: map[string]string{ | ||
"parseAllSources": "true", | ||
}, | ||
} | ||
|
||
//init flaeg source | ||
f := flaeg.New(traefikCmd, os.Args[1:]) | ||
//add custom parsers | ||
|
@@ -93,8 +115,9 @@ Complete documentation is available at https://traefik.io`, | |
f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{}) | ||
f.AddParser(reflect.TypeOf([]acme.Domain{}), &acme.Domains{}) | ||
|
||
//add version command | ||
//add commands | ||
f.AddCommand(versionCmd) | ||
f.AddCommand(storeconfigCmd) | ||
if _, err := f.Parse(traefikCmd); err != nil { | ||
fmtlog.Println(err) | ||
os.Exit(-1) | ||
|
@@ -110,20 +133,28 @@ Complete documentation is available at https://traefik.io`, | |
s.AddSource(f) | ||
if _, err := s.LoadConfig(); err != nil { | ||
fmtlog.Println(fmt.Errorf("Error reading TOML config file %s : %s", toml.ConfigFileUsed(), err)) | ||
os.Exit(-1) | ||
} | ||
|
||
traefikConfiguration.ConfigFile = toml.ConfigFileUsed() | ||
|
||
kv, err := CreateKvSource(traefikConfiguration) | ||
kv, err = CreateKvSource(traefikConfiguration) | ||
if err != nil { | ||
fmtlog.Println(err) | ||
os.Exit(-1) | ||
} | ||
|
||
if kv != nil { | ||
usedCmd, err := f.GetCommand() | ||
if err != nil { | ||
fmtlog.Println(err) | ||
os.Exit(-1) | ||
} | ||
// IF a KV Store is enable and no sub-command called in args | ||
if kv != nil && usedCmd == traefikCmd { | ||
s.AddSource(kv) | ||
if _, err := s.LoadConfig(); err != nil { | ||
fmtlog.Println(err) | ||
os.Exit(-1) | ||
} | ||
} | ||
|
||
|
@@ -173,7 +204,7 @@ func run(traefikConfiguration *TraefikConfiguration) { | |
fi, err := os.OpenFile(globalConfiguration.TraefikLogsFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) | ||
defer func() { | ||
if err := fi.Close(); err != nil { | ||
log.Error("Error closinf file", err) | ||
log.Error("Error closing file", err) | ||
} | ||
}() | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
60 seconds might be a little too much to wait for 👼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied it like that form "TestNominalConfiguration" 😅
How long do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say 15 seconds should be enough 👼.