Skip to content

Commit

Permalink
add onetime command line param
Browse files Browse the repository at this point in the history
  • Loading branch information
sseide committed Feb 10, 2022
1 parent 89b372b commit d6366cb
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/remco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"os"
"os/signal"
"reflect"
"sync"
"syscall"

Expand All @@ -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() {
Expand All @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions pkg/backends/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions pkg/backends/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/backends/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions pkg/template/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d6366cb

Please sign in to comment.