Skip to content

Commit

Permalink
Watch config using viper
Browse files Browse the repository at this point in the history
Conflicts:
	Gomfile
	aws/manage_route_spec.go
	config/config.go
	config/config_test.go
	daemon/daemon.go
  • Loading branch information
tsheasha authored and bobtfish committed Mar 9, 2016
1 parent fdb343a commit b6107c4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions aws/manage_route_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package aws
import (
"errors"
"fmt"
"net"
"strings"

log "github.com/Sirupsen/logrus"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/bobtfish/AWSnycast/healthcheck"
"github.com/bobtfish/AWSnycast/instancemetadata"
"github.com/hashicorp/go-multierror"
"net"
"strings"
)

type ManageRoutesSpec struct {
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Config) Validate(im instancemetadata.InstanceMetadata, manager aws.Rout
result = multierror.Append(result, errors.New("No route_tables key in config"))
} else {
if len(c.RouteTables) == 0 {
result = multierror.Append(result, errors.New("No route_tables defined in config"))
result = multierror.Append(result, errors.New("No routetables defined in config"))
} else {
for k, v := range c.RouteTables {
if err := v.Validate(im, manager, k, c.Healthchecks, c.RemoteHealthcheckTemplates); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
"errors"
"fmt"
"testing"

a "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/bobtfish/AWSnycast/aws"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/bobtfish/AWSnycast/testhelpers"
"github.com/hashicorp/go-multierror"
"github.com/stretchr/testify/assert"
"testing"
)

var tim instancemetadata.InstanceMetadata
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestConfigValidateEmptyRouteTables(t *testing.T) {
RouteTables: r,
}
err := c.Validate(tim, rtm)
testhelpers.CheckOneMultiError(t, err, "No route_tables defined in config")
testhelpers.CheckOneMultiError(t, err, "No routetables defined in config")
}

func TestConfigValidateBadRouteTables(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/bobtfish/AWSnycast/aws"
"github.com/bobtfish/AWSnycast/config"
"github.com/bobtfish/AWSnycast/instancemetadata"
"github.com/spf13/viper"
"gopkg.in/fsnotify.v1"
"time"
)

Expand Down Expand Up @@ -126,6 +128,15 @@ func (d *Daemon) Run(oneShot bool, noop bool) int {
if oneShot {
d.quitChan <- true
} else {
// Reload the daemon on config change
viper.SetConfigFile(d.ConfigFile)
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) {
log.WithFields(log.Fields{"file": d.ConfigFile}).Info("Config file changed, reloading daemon")
d.quitChan <- true
d.Run(oneShot, noop)
})

d.runHealthChecks()
defer d.stopHealthChecks()
d.RunSleepLoop()
Expand Down

0 comments on commit b6107c4

Please sign in to comment.