Merge pull request #39956 from justinsb/dnsprovider_isempty

Automatic merge from submit-queue

dnsprovider: Add IsEmpty method

When batching changes, it is often handy to know whether a changeset
IsEmpty, and thus does not need to be Apply-ed.

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-01-25 15:07:32 -08:00 committed by GitHub
commit dd4de1e7d4
4 changed files with 15 additions and 1 deletions

View File

@ -45,7 +45,7 @@ type Zone interface {
Name() string Name() string
// ID returns the unique provider identifier for the zone // ID returns the unique provider identifier for the zone
ID() string ID() string
// ResourceRecordsets returns the provider's ResourceRecordSets interface, or false if not supported. // ResourceRecordSets returns the provider's ResourceRecordSets interface, or false if not supported.
ResourceRecordSets() (ResourceRecordSets, bool) ResourceRecordSets() (ResourceRecordSets, bool)
} }
@ -70,6 +70,8 @@ type ResourceRecordChangeset interface {
Remove(ResourceRecordSet) ResourceRecordChangeset Remove(ResourceRecordSet) ResourceRecordChangeset
// Apply applies the accumulated operations to the Zone. // Apply applies the accumulated operations to the Zone.
Apply() error Apply() error
// IsEmpty returns true if there are no accumulated operations.
IsEmpty() bool
} }
type ResourceRecordSet interface { type ResourceRecordSet interface {

View File

@ -99,3 +99,7 @@ func (c *ResourceRecordChangeset) Apply() error {
} }
return nil return nil
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.removals) == 0 && len(c.additions) == 0
}

View File

@ -59,6 +59,10 @@ func (c *ResourceRecordChangeset) Remove(rrset dnsprovider.ResourceRecordSet) dn
return c return c
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.changeset) == 0
}
func (c *ResourceRecordChangeset) Apply() error { func (c *ResourceRecordChangeset) Apply() error {
ctx := context.Background() ctx := context.Background()
etcdPathPrefix := c.zone.zones.intf.etcdPathPrefix etcdPathPrefix := c.zone.zones.intf.etcdPathPrefix

View File

@ -72,3 +72,7 @@ func (c *ResourceRecordChangeset) Apply() error {
return nil return nil
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.additions) == 0 && len(c.removals) == 0
}