Skip to content

Commit

Permalink
add -sync-only flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zealic committed Nov 20, 2015
1 parent 46d3c69 commit 946438a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 1 addition & 0 deletions docs/configuration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/github.com/kelseyhightower/confd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
printVersion bool
scheme string
srvDomain string
syncOnly bool
table string
templateConfig template.Config
backendsConfig backends.Config
Expand All @@ -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"`
Expand All @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
Noop bool
Prefix string
StoreClient backends.StoreClient
SyncOnly bool
TemplateDir string
}

Expand Down Expand Up @@ -54,6 +55,7 @@ type TemplateResource struct {
prefix string
store memkv.Store
storeClient backends.StoreClient
syncOnly bool
}

var ErrEmptySrc = errors.New("empty src template")
Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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())
}
Expand All @@ -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
}
Expand Down

0 comments on commit 946438a

Please sign in to comment.