Skip to content

Commit

Permalink
Fixes #366 (#367)
Browse files Browse the repository at this point in the history
- Add `--inmemory-zone flag`
- Implement `InMemoryZoneInit` function to setup initial zones for
  inmemory provider
- Make "" the default zone for the inmemory provider instead of
  nil/none when no initial zones are specified
- Update config/flag parsing tests to accept new flag
  • Loading branch information
ffledgling authored and Yerken committed Oct 25, 2017
1 parent 723b829 commit 6134fe9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func main() {
},
)
case "inmemory":
p, err = provider.NewInMemoryProvider(provider.InMemoryWithDomain(domainFilter), provider.InMemoryWithLogging()), nil
p, err = provider.NewInMemoryProvider(provider.InMemoryInitZones(cfg.InMemoryZones), provider.InMemoryWithDomain(domainFilter), provider.InMemoryWithLogging()), nil
default:
log.Fatalf("unknown dns provider: %s", cfg.Provider)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/externaldns/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Config struct {
InfobloxWapiPassword string
InfobloxWapiVersion string
InfobloxSSLVerify bool
InMemoryZones []string
Policy string
Registry string
TXTOwnerID string
Expand Down Expand Up @@ -83,6 +84,7 @@ var defaultConfig = &Config{
InfobloxWapiPassword: "",
InfobloxWapiVersion: "2.3.1",
InfobloxSSLVerify: true,
InMemoryZones: []string{},
Policy: "sync",
Registry: "txt",
TXTOwnerID: "default",
Expand Down Expand Up @@ -140,6 +142,7 @@ func (cfg *Config) ParseFlags(args []string) error {
app.Flag("infoblox-wapi-password", "When using the Infoblox provider, specify the WAPI password (required when --provider=infoblox)").Default(defaultConfig.InfobloxWapiPassword).StringVar(&cfg.InfobloxWapiPassword)
app.Flag("infoblox-wapi-version", "When using the Infoblox provider, specify the WAPI version (default: 2.3.1)").Default(defaultConfig.InfobloxWapiVersion).StringVar(&cfg.InfobloxWapiVersion)
app.Flag("infoblox-ssl-verify", "When using the Infoblox provider, specify whether to verify the SSL certificate (default: true)").Default(strconv.FormatBool(defaultConfig.InfobloxSSLVerify)).BoolVar(&cfg.InfobloxSSLVerify)
app.Flag("inmemory-zone", "Provide a list of pre-configured zones for the inmemory provider; specify multiple times for multiple zones (optional)").Default("").StringsVar(&cfg.InMemoryZones)

// Flags related to policies
app.Flag("policy", "Modify how DNS records are sychronized between sources and providers (default: sync, options: sync, upsert-only)").Default(defaultConfig.Policy).EnumVar(&cfg.Policy, "sync", "upsert-only")
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/externaldns/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
InfobloxWapiPassword: "",
InfobloxWapiVersion: "2.3.1",
InfobloxSSLVerify: true,
InMemoryZones: []string{""},
Policy: "sync",
Registry: "txt",
TXTOwnerID: "default",
Expand Down Expand Up @@ -79,6 +80,7 @@ var (
InfobloxWapiPassword: "infoblox",
InfobloxWapiVersion: "2.6.1",
InfobloxSSLVerify: false,
InMemoryZones: []string{"example.org", "company.com"},
Policy: "upsert-only",
Registry: "noop",
TXTOwnerID: "owner-1",
Expand Down Expand Up @@ -128,6 +130,8 @@ func TestParseFlags(t *testing.T) {
"--infoblox-wapi-username=infoblox",
"--infoblox-wapi-password=infoblox",
"--infoblox-wapi-version=2.6.1",
"--inmemory-zone=example.org",
"--inmemory-zone=company.com",
"--no-infoblox-ssl-verify",
"--domain-filter=example.org",
"--domain-filter=company.com",
Expand Down Expand Up @@ -167,6 +171,7 @@ func TestParseFlags(t *testing.T) {
"EXTERNAL_DNS_INFOBLOX_WAPI_PASSWORD": "infoblox",
"EXTERNAL_DNS_INFOBLOX_WAPI_VERSION": "2.6.1",
"EXTERNAL_DNS_INFOBLOX_SSL_VERIFY": "0",
"EXTERNAL_DNS_INMEMORY_ZONE": "example.org\ncompany.com",
"EXTERNAL_DNS_DOMAIN_FILTER": "example.org\ncompany.com",
"EXTERNAL_DNS_AWS_ZONE_TYPE": "private",
"EXTERNAL_DNS_POLICY": "upsert-only",
Expand Down
11 changes: 11 additions & 0 deletions provider/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ func InMemoryWithDomain(domainFilter DomainFilter) InMemoryOption {
}
}

// InMemoryInitZones pre-seeds the InMemoryProvider with given zones
func InMemoryInitZones(zones []string) InMemoryOption {
return func(p *InMemoryProvider) {
for _, z := range zones {
if err := p.CreateZone(z); err != nil {
log.Warnf("Unable to initialize zones for inmemory provider")
}
}
}
}

// NewInMemoryProvider returns InMemoryProvider DNS provider interface implementation
func NewInMemoryProvider(opts ...InMemoryOption) *InMemoryProvider {
im := &InMemoryProvider{
Expand Down

0 comments on commit 6134fe9

Please sign in to comment.