diff --git a/cmd/remco/main.go b/cmd/remco/main.go index 071a2734..1a291f2d 100644 --- a/cmd/remco/main.go +++ b/cmd/remco/main.go @@ -13,6 +13,7 @@ import ( "fmt" "os" "os/signal" + "reflect" "sync" "syscall" @@ -25,12 +26,14 @@ import ( var ( configPath string printVersionAndExit bool + onetime bool ) func init() { const defaultConfig = "/etc/remco/config" flag.StringVar(&configPath, "config", defaultConfig, "path to the configuration file") flag.BoolVar(&printVersionAndExit, "version", false, "print version and exit") + flag.BoolVar(&onetime, "onetime", false, "run templating process once and exit") } func run() { @@ -46,6 +49,17 @@ func run() { log.Fatal(err) } + if onetime { + for _, res := range cfg.Resource { + for _, b := range res.Backends.GetBackends() { + if !reflect.ValueOf(b).IsZero() { + backend := b.GetBackend() + backend.Onetime = true + } + } + } + } + run := NewSupervisor(cfg, reapLock, done) defer run.Stop() diff --git a/pkg/backends/consul.go b/pkg/backends/consul.go index d378c74c..c2830b46 100644 --- a/pkg/backends/consul.go +++ b/pkg/backends/consul.go @@ -75,3 +75,8 @@ func (c *ConsulConfig) Connect() (template.Backend, error) { return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *ConsulConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/env.go b/pkg/backends/env.go index 919b2669..bb3dc5f4 100644 --- a/pkg/backends/env.go +++ b/pkg/backends/env.go @@ -34,3 +34,8 @@ func (c *EnvConfig) Connect() (template.Backend, error) { c.Backend.ReadWatcher = client return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *EnvConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/etcd.go b/pkg/backends/etcd.go index 84761387..9edbfeb9 100644 --- a/pkg/backends/etcd.go +++ b/pkg/backends/etcd.go @@ -111,3 +111,8 @@ func (c *EtcdConfig) Connect() (template.Backend, error) { c.Backend.ReadWatcher = client return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *EtcdConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/file.go b/pkg/backends/file.go index 664f7f4e..11915904 100644 --- a/pkg/backends/file.go +++ b/pkg/backends/file.go @@ -46,3 +46,8 @@ func (c *FileConfig) Connect() (template.Backend, error) { c.Backend.ReadWatcher = client return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *FileConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/mock.go b/pkg/backends/mock.go index 3f0b8aca..1c88c63d 100644 --- a/pkg/backends/mock.go +++ b/pkg/backends/mock.go @@ -35,3 +35,8 @@ func (c *MockConfig) Connect() (template.Backend, error) { return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *MockConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/plugin/plugin.go b/pkg/backends/plugin/plugin.go index 1b26b8ab..0c4d9d1b 100644 --- a/pkg/backends/plugin/plugin.go +++ b/pkg/backends/plugin/plugin.go @@ -55,6 +55,11 @@ func (p *Plugin) Connect() (template.Backend, error) { return p.Backend, nil } +// return Backend config to allow modification before connect() for onetime param or similar +func (p *Plugin) GetBackend() *template.Backend { + return &p.Backend +} + // initPlugin sends the config map to the plugin // the plugin can then run some initialization tasks func (p *plug) initPlugin(config map[string]interface{}) error { diff --git a/pkg/backends/redis.go b/pkg/backends/redis.go index 40576cf6..179f4447 100644 --- a/pkg/backends/redis.go +++ b/pkg/backends/redis.go @@ -71,3 +71,8 @@ func (c *RedisConfig) Connect() (template.Backend, error) { return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *RedisConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/vault.go b/pkg/backends/vault.go index e9ada21a..e80d4378 100644 --- a/pkg/backends/vault.go +++ b/pkg/backends/vault.go @@ -100,3 +100,8 @@ func (c *VaultConfig) Connect() (template.Backend, error) { return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *VaultConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/backends/zookeeper.go b/pkg/backends/zookeeper.go index 25726da7..7fb464c4 100644 --- a/pkg/backends/zookeeper.go +++ b/pkg/backends/zookeeper.go @@ -56,3 +56,8 @@ func (c *ZookeeperConfig) Connect() (template.Backend, error) { c.Backend.ReadWatcher = client return c.Backend, nil } + +// return Backend config to allow modification before connect() for onetime param or similar +func (c *ZookeeperConfig) GetBackend() *template.Backend { + return &c.Backend +} diff --git a/pkg/template/backend.go b/pkg/template/backend.go index 6530cef9..7286afda 100644 --- a/pkg/template/backend.go +++ b/pkg/template/backend.go @@ -27,6 +27,7 @@ import ( // Connect should also set the name and the StoreClient of the Backend. The other values of Backend will be loaded from the configuration file. type BackendConnector interface { Connect() (Backend, error) + GetBackend() *Backend } // Backend is the representation of a template backend like etcd or consul