From bd156dc9d19867f98bfac0d8fe9945f923724a7c Mon Sep 17 00:00:00 2001 From: John Belamaric Date: Fri, 9 Feb 2018 17:32:52 -0500 Subject: Stop noisy modifications (#1517) * Stop noisy modifications * Review comments, tests * More coverage * vet * Make it obvious new port name is not a typo --- plugin/kubernetes/controller.go | 64 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'plugin/kubernetes/controller.go') diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go index 3262f299e..39d4ead64 100644 --- a/plugin/kubernetes/controller.go +++ b/plugin/kubernetes/controller.go @@ -431,6 +431,64 @@ func (dns *dnsControl) updateModifed() { atomic.StoreInt64(&dns.modified, unix) } -func (dns *dnsControl) Add(obj interface{}) { dns.updateModifed() } -func (dns *dnsControl) Delete(obj interface{}) { dns.updateModifed() } -func (dns *dnsControl) Update(objOld, newObj interface{}) { dns.updateModifed() } +func (dns *dnsControl) Add(obj interface{}) { dns.updateModifed() } +func (dns *dnsControl) Delete(obj interface{}) { dns.updateModifed() } + +func (dns *dnsControl) Update(objOld, newObj interface{}) { + // endpoint updates can come frequently, make sure + // it's a change we care about + if o, ok := objOld.(*api.Endpoints); ok { + n := newObj.(*api.Endpoints) + if endpointsEquivalent(o, n) { + return + } + } + dns.updateModifed() +} + +// endpointsEquivalent checks if the update to an endpoint is something +// that matters to us: ready addresses, host names, ports (including names for SRV) +func endpointsEquivalent(a, b *api.Endpoints) bool { + // supposedly we should be able to rely on + // these being sorted and able to be compared + // they are supposed to be in a canonical format + + if len(a.Subsets) != len(b.Subsets) { + return false + } + + for i, sa := range a.Subsets { + // check the Addresses and Ports. Ignore unready addresses. + sb := b.Subsets[i] + if len(sa.Addresses) != len(sb.Addresses) { + return false + } + if len(sa.Ports) != len(sb.Ports) { + return false + } + + for addr, aaddr := range sa.Addresses { + baddr := sb.Addresses[addr] + if aaddr.IP != baddr.IP { + return false + } + if aaddr.Hostname != baddr.Hostname { + return false + } + } + + for port, aport := range sa.Ports { + bport := sb.Ports[port] + if aport.Name != bport.Name { + return false + } + if aport.Port != bport.Port { + return false + } + if aport.Protocol != bport.Protocol { + return false + } + } + } + return true +} -- cgit v1.2.3