mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-05-04 22:26:11 +02:00
feat: make interval between synchronizations configurable (#123)
This commit is contained in:
parent
d507345a63
commit
facdea51dd
@ -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
|
||||
|
||||
1
main.go
1
main.go
@ -96,6 +96,7 @@ func main() {
|
||||
Zone: cfg.Zone,
|
||||
Source: sources,
|
||||
Provider: p,
|
||||
Interval: cfg.Interval,
|
||||
}
|
||||
|
||||
if cfg.Once {
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user