From 946438a4eebacd1cad79fdb6538ff4c2c28b12dd Mon Sep 17 00:00:00 2001 From: zealic Date: Fri, 20 Nov 2015 16:23:06 +0800 Subject: [PATCH] add -sync-only flag --- docs/command-line-flags.md | 1 + docs/configuration-guide.md | 1 + src/github.com/kelseyhightower/confd/config.go | 6 ++++++ .../kelseyhightower/confd/resource/template/resource.go | 7 +++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/command-line-flags.md b/docs/command-line-flags.md index c570413e5..0555aff83 100644 --- a/docs/command-line-flags.md +++ b/docs/command-line-flags.md @@ -23,6 +23,7 @@ Usage of confd: -prefix="/": key path prefix -scheme="http": the backend URI scheme (http or https) -srv-domain="": the name of the resource record + -syc-only=false: sync without check_cmd and reload_cmd -version=false: print version and exit -watch=false: enable watch support ``` diff --git a/docs/configuration-guide.md b/docs/configuration-guide.md index 86714e87f..784ec35d8 100644 --- a/docs/configuration-guide.md +++ b/docs/configuration-guide.md @@ -19,6 +19,7 @@ Optional: * `prefix` (string) - The string to prefix to keys. ("/") * `scheme` (string) - The backend URI scheme. ("http" or "https") * `srv_domain` (string) - The name of the resource record. +* `sync-only` (bool) - sync without check_cmd and reload_cmd. * `watch` (bool) - Enable watch support. Example: diff --git a/src/github.com/kelseyhightower/confd/config.go b/src/github.com/kelseyhightower/confd/config.go index 58462eede..af6d65571 100644 --- a/src/github.com/kelseyhightower/confd/config.go +++ b/src/github.com/kelseyhightower/confd/config.go @@ -37,6 +37,7 @@ var ( printVersion bool scheme string srvDomain string + syncOnly bool table string templateConfig template.Config backendsConfig backends.Config @@ -57,6 +58,7 @@ type Config struct { Prefix string `toml:"prefix"` SRVDomain string `toml:"srv_domain"` Scheme string `toml:"scheme"` + SyncOnly bool `toml:"sync-only"` Table string `toml:"table"` LogLevel string `toml:"log-level"` Watch bool `toml:"watch"` @@ -80,6 +82,7 @@ func init() { flag.BoolVar(&printVersion, "version", false, "print version and exit") flag.StringVar(&scheme, "scheme", "http", "the backend URI scheme (http or https)") flag.StringVar(&srvDomain, "srv-domain", "", "the name of the resource record") + flag.BoolVar(&syncOnly, "sync-only", false, "sync without check_cmd and reload_cmd") flag.StringVar(&table, "table", "", "the name of the DynamoDB table (only used with -backend=dynamodb)") flag.BoolVar(&watch, "watch", false, "enable watch support") } @@ -192,6 +195,7 @@ func initConfig() error { KeepStageFile: keepStageFile, Noop: config.Noop, Prefix: config.Prefix, + SyncOnly: config.SyncOnly, TemplateDir: filepath.Join(config.ConfDir, "templates"), } return nil @@ -261,6 +265,8 @@ func setConfigFromFlag(f *flag.Flag) { config.Scheme = scheme case "srv-domain": config.SRVDomain = srvDomain + case "sync-only": + config.SyncOnly = syncOnly case "table": config.Table = table case "log-level": diff --git a/src/github.com/kelseyhightower/confd/resource/template/resource.go b/src/github.com/kelseyhightower/confd/resource/template/resource.go index cbd0480f5..a233b88e9 100644 --- a/src/github.com/kelseyhightower/confd/resource/template/resource.go +++ b/src/github.com/kelseyhightower/confd/resource/template/resource.go @@ -26,6 +26,7 @@ type Config struct { Noop bool Prefix string StoreClient backends.StoreClient + SyncOnly bool TemplateDir string } @@ -54,6 +55,7 @@ type TemplateResource struct { prefix string store memkv.Store storeClient backends.StoreClient + syncOnly bool } var ErrEmptySrc = errors.New("empty src template") @@ -75,6 +77,7 @@ func NewTemplateResource(path string, config Config) (*TemplateResource, error) tr.storeClient = config.StoreClient tr.funcMap = newFuncMap() tr.store = memkv.New() + tr.syncOnly = config.SyncOnly addFuncs(tr.funcMap, tr.store.FuncMap) tr.prefix = filepath.Join("/", config.Prefix, tr.Prefix) if tr.Src == "" { @@ -162,7 +165,7 @@ func (t *TemplateResource) sync() error { } if !ok { log.Info("Target config " + t.Dest + " out of sync") - if t.CheckCmd != "" { + if !t.syncOnly && t.CheckCmd != "" { if err := t.check(); err != nil { return errors.New("Config check failed: " + err.Error()) } @@ -189,7 +192,7 @@ func (t *TemplateResource) sync() error { return err } } - if t.ReloadCmd != "" { + if !t.syncOnly && t.ReloadCmd != "" { if err := t.reload(); err != nil { return err }