in pkg/dns/dns.go [369:430]
func (kd *KubeDNS) handleEndpointUpdate(oldObj, newObj interface{}) {
oldEndpoints, ok := oldObj.(*v1.Endpoints)
if !ok {
klog.Errorf("oldObj type assertion failed! Expected 'v1.Endpoints', got %T", oldObj)
return
}
newEndpoints, ok := newObj.(*v1.Endpoints)
if !ok {
klog.Errorf("newObj type assertion failed! Expected 'v1.Endpoints', got %T", newObj)
return
}
// oldAddressMap is use to hold oldEndpoints addresses that are not
// in newEndpoints
oldAddressMap := make(map[string]bool)
// svc is same for both old and new endpoints
svc, err := kd.getServiceFromEndpoints(oldEndpoints)
if svc != nil && err == nil {
if !util.IsServiceIPSet(svc) {
for idx := range oldEndpoints.Subsets {
for subIdx := range oldEndpoints.Subsets[idx].Addresses {
address := &oldEndpoints.Subsets[idx].Addresses[subIdx]
endpointIP := address.IP
if _, has := getHostname(address); has {
oldAddressMap[endpointIP] = true
}
}
}
for idx := range newEndpoints.Subsets {
for subIdx := range newEndpoints.Subsets[idx].Addresses {
address := newEndpoints.Subsets[idx].Addresses[subIdx]
endpointIP := address.IP
if _, ok := oldAddressMap[endpointIP]; ok {
address := &newEndpoints.Subsets[idx].Addresses[subIdx]
// Entries are both in old and new endpoint. Remove from the `oldAddressMap`
// if the address is still named to the service.
if _, has := getHostname(address); has {
// The service is still named in the Pod
delete(oldAddressMap, endpointIP)
}
}
}
}
// Remove all old PTR records for the endpoints that are not
// in new endpoints, or
// the addresses that are no longer named.
kd.cacheLock.Lock()
for k := range oldAddressMap {
klog.V(4).Infof("Removing old endpoint IP %q", k)
delete(kd.reverseRecordMap, k)
}
kd.cacheLock.Unlock()
}
}
// TODO: Avoid unwanted updates.
kd.handleEndpointAdd(newObj)
}