mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
Add create-only policy
This commit is contained in:
parent
06052acfc9
commit
2b13a7fa38
@ -350,7 +350,7 @@ func (cfg *Config) ParseFlags(args []string) error {
|
||||
app.Flag("transip-keyfile", "When using the TransIP provider, specify the path to the private key file (required when --provider=transip)").Default(defaultConfig.TransIPPrivateKeyFile).StringVar(&cfg.TransIPPrivateKeyFile)
|
||||
|
||||
// Flags related to policies
|
||||
app.Flag("policy", "Modify how DNS records are synchronized between sources and providers (default: sync, options: sync, upsert-only)").Default(defaultConfig.Policy).EnumVar(&cfg.Policy, "sync", "upsert-only")
|
||||
app.Flag("policy", "Modify how DNS records are synchronized between sources and providers (default: sync, options: sync, upsert-only, create-only)").Default(defaultConfig.Policy).EnumVar(&cfg.Policy, "sync", "upsert-only", "create-only")
|
||||
|
||||
// Flags related to the registry
|
||||
app.Flag("registry", "The registry implementation to use to keep track of DNS record ownership (default: txt, options: txt, noop, aws-sd)").Default(defaultConfig.Registry).EnumVar(&cfg.Registry, "txt", "noop", "aws-sd")
|
||||
|
@ -25,6 +25,7 @@ type Policy interface {
|
||||
var Policies = map[string]Policy{
|
||||
"sync": &SyncPolicy{},
|
||||
"upsert-only": &UpsertOnlyPolicy{},
|
||||
"create-only": &CreateOnlyPolicy{},
|
||||
}
|
||||
|
||||
// SyncPolicy allows for full synchronization of DNS records.
|
||||
@ -35,7 +36,7 @@ func (p *SyncPolicy) Apply(changes *Changes) *Changes {
|
||||
return changes
|
||||
}
|
||||
|
||||
// UpsertOnlyPolicy allows evrything but deleting DNS records.
|
||||
// UpsertOnlyPolicy allows everything but deleting DNS records.
|
||||
type UpsertOnlyPolicy struct{}
|
||||
|
||||
// Apply applies the upsert-only policy which strips out any deletions.
|
||||
@ -46,3 +47,13 @@ func (p *UpsertOnlyPolicy) Apply(changes *Changes) *Changes {
|
||||
UpdateNew: changes.UpdateNew,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateOnlyPolicy allows only creating DNS records.
|
||||
type CreateOnlyPolicy struct{}
|
||||
|
||||
// Apply applies the create-only policy which strips out updates and deletions.
|
||||
func (p *CreateOnlyPolicy) Apply(changes *Changes) *Changes {
|
||||
return &Changes{
|
||||
Create: changes.Create,
|
||||
}
|
||||
}
|
@ -52,6 +52,12 @@ func TestApply(t *testing.T) {
|
||||
&Changes{Create: baz, UpdateOld: fooV1, UpdateNew: fooV2, Delete: bar},
|
||||
&Changes{Create: baz, UpdateOld: fooV1, UpdateNew: fooV2, Delete: empty},
|
||||
},
|
||||
{
|
||||
// CreateOnlyPolicy clears the list of updates and deletions.
|
||||
&CreateOnlyPolicy{},
|
||||
&Changes{Create: baz, UpdateOld: fooV1, UpdateNew: fooV2, Delete: bar},
|
||||
&Changes{Create: baz, UpdateOld: empty, UpdateNew: empty, Delete: empty},
|
||||
},
|
||||
} {
|
||||
// apply policy
|
||||
changes := tc.policy.Apply(tc.changes)
|
||||
@ -68,6 +74,7 @@ func TestApply(t *testing.T) {
|
||||
func TestPolicies(t *testing.T) {
|
||||
validatePolicy(t, Policies["sync"], &SyncPolicy{})
|
||||
validatePolicy(t, Policies["upsert-only"], &UpsertOnlyPolicy{})
|
||||
validatePolicy(t, Policies["create-only"], &CreateOnlyPolicy{})
|
||||
}
|
||||
|
||||
// validatePolicy validates that a given policy is of the given type.
|
||||
|
Loading…
Reference in New Issue
Block a user