diff --git a/controller/controller.go b/controller/controller.go index 263f243c8..d153503a5 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -37,6 +37,8 @@ type Controller struct { Source source.Source Provider provider.Provider + // The interval between individual synchronizations + Interval time.Duration } // RunOnce runs a single iteration of a reconciliation loop. @@ -70,7 +72,7 @@ func (c *Controller) Run(stopChan <-chan struct{}) { } select { - case <-time.After(time.Minute): + case <-time.After(c.Interval): case <-stopChan: log.Infoln("terminating main controller loop") return diff --git a/main.go b/main.go index 09ed109b7..46b0bc65b 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,7 @@ func main() { Zone: cfg.Zone, Source: sources, Provider: p, + Interval: cfg.Interval, } if cfg.Once { diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index 6f0020d24..dc2e9fb0c 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -17,6 +17,8 @@ limitations under the License. package externaldns import ( + "time" + "github.com/spf13/pflag" "k8s.io/client-go/pkg/api/v1" @@ -37,6 +39,7 @@ type Config struct { Provider string GoogleProject string HealthPort string + Interval time.Duration Once bool DryRun bool Debug bool @@ -61,6 +64,7 @@ func (cfg *Config) ParseFlags(args []string) error { flags.StringVar(&cfg.GoogleProject, "google-project", "", "gcloud project to target") flags.StringVar(&cfg.HealthPort, "health-port", defaultHealthPort, "health port to listen on") flags.StringVar(&cfg.LogFormat, "log-format", defaultLogFormat, "log format output. options: [\"text\", \"json\"]") + flags.DurationVar(&cfg.Interval, "interval", time.Minute, "interval between synchronizations") flags.BoolVar(&cfg.Once, "once", false, "run once and exit") flags.BoolVar(&cfg.DryRun, "dry-run", true, "dry-run mode") flags.BoolVar(&cfg.Debug, "debug", false, "debug mode") diff --git a/pkg/apis/externaldns/types_test.go b/pkg/apis/externaldns/types_test.go index f8188d24c..28e420768 100644 --- a/pkg/apis/externaldns/types_test.go +++ b/pkg/apis/externaldns/types_test.go @@ -19,6 +19,7 @@ package externaldns import ( "reflect" "testing" + "time" ) func TestParseFlags(t *testing.T) { @@ -40,6 +41,8 @@ func TestParseFlags(t *testing.T) { Provider: "", GoogleProject: "", HealthPort: defaultHealthPort, + Interval: time.Minute, + Once: false, DryRun: true, Debug: false, LogFormat: defaultLogFormat, @@ -58,6 +61,8 @@ func TestParseFlags(t *testing.T) { Provider: "", GoogleProject: "", HealthPort: defaultHealthPort, + Interval: time.Minute, + Once: false, DryRun: true, Debug: false, LogFormat: defaultLogFormat, @@ -76,6 +81,8 @@ func TestParseFlags(t *testing.T) { Provider: "", GoogleProject: "", HealthPort: defaultHealthPort, + Interval: time.Minute, + Once: false, DryRun: true, Debug: false, LogFormat: defaultLogFormat, @@ -99,6 +106,8 @@ func TestParseFlags(t *testing.T) { Provider: "", GoogleProject: "", HealthPort: defaultHealthPort, + Interval: time.Minute, + Once: false, DryRun: true, Debug: false, LogFormat: "json", @@ -116,7 +125,9 @@ func TestParseFlags(t *testing.T) { "--provider", "provider", "--google-project", "project", "--health-port", "1234", - "--dry-run", "true", + "--interval", "10m", + "--once", + "--dry-run=false", "--debug", "--version"}}, expected: &Config{ @@ -128,7 +139,9 @@ func TestParseFlags(t *testing.T) { Provider: "provider", GoogleProject: "project", HealthPort: "1234", - DryRun: true, + Interval: 10 * time.Minute, + Once: true, + DryRun: false, Debug: true, LogFormat: "yaml", Version: true,