Skip to content
This repository has been archived by the owner on Sep 19, 2018. It is now read-only.

Commit

Permalink
ignore hostname deletes when used by other ingresses
Browse files Browse the repository at this point in the history
  • Loading branch information
alkar committed Nov 24, 2017
1 parent 65e34ad commit c88790d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ingressWatcher struct {
resyncPeriod time.Duration
labelSelector string
stopChannel chan struct{}
store cache.Store
}

func newIngressWatcher(client kubernetes.Interface, eventHandler eventHandlerFunc, labelSelector string, resyncPeriod time.Duration) *ingressWatcher {
Expand Down Expand Up @@ -54,7 +55,8 @@ func (iw *ingressWatcher) Start() {
iw.eventHandler(watch.Deleted, obj.(*v1beta1.Ingress), nil)
},
}
_, controller := cache.NewInformer(lw, &v1beta1.Ingress{}, iw.resyncPeriod, eh)
store, controller := cache.NewInformer(lw, &v1beta1.Ingress{}, iw.resyncPeriod, eh)
iw.store = store
log.Println("[INFO] starting ingress watcher")
controller.Run(iw.stopChannel)
log.Println("[INFO] ingress watcher stopped")
Expand All @@ -65,6 +67,18 @@ func (iw *ingressWatcher) Stop() {
close(iw.stopChannel)
}

func (iw *ingressWatcher) HostnameOwners(hostname string) []string {
owners := []string{}
for _, i := range iw.store.List() {
for _, h := range getHostnamesFromIngress(i.(*v1beta1.Ingress)) {
if hostname == h {
owners = append(owners, i.(*v1beta1.Ingress).Name)
}
}
}
return owners
}

func getHostnamesFromIngress(ingress *v1beta1.Ingress) []string {
hostnames := []string{}
for _, rule := range ingress.Spec.Rules {
Expand Down
5 changes: 5 additions & 0 deletions registrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func (r *registrator) pruneBatch(action string, records []cnameRecord) []cnameRe
t, err := resolveCname(fmt.Sprintf("%s.", strings.Trim(u.Hostname, ".")), r.ListNameservers())
switch action {
case route53.ChangeActionDelete:
o := r.ingressWatcher.HostnameOwners(u.Hostname)
if len(o) > 0 {
log.Printf("[DEBUG] will not delete record %s because it's still claimed by: %s", u.Hostname, strings.Join(o, ","))
break
}
if err == nil {
pruned = append(pruned, u)
} else if err != errDNSEmptyAnswer {
Expand Down

0 comments on commit c88790d

Please sign in to comment.