Skip to content

Commit

Permalink
Support hostnames in Ingress status
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Dec 16, 2016
1 parent e194288 commit 77967aa
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions core/pkg/ingress/status/status.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package status

import (
"net"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -92,19 +93,19 @@ func (s statusSync) Shutdown() {

glog.Infof("updating status of Ingress rules (remove)")

ips, err := s.getRunningIPs()
addrs, err := s.runningAddresess()
if err != nil {
glog.Errorf("error obtaining running IPs: %v", ips)
glog.Errorf("error obtaining running IPs: %v", addrs)
return
}

if len(ips) > 1 {
if len(addrs) > 1 {
// leave the job to the next leader
glog.Infof("leaving status update for next leader (%v)", len(ips))
glog.Infof("leaving status update for next leader (%v)", len(addrs))
return
}

glog.Infof("removing my ip (%v)", ips)
glog.Infof("removing address from ingress status (%v)", addrs)
s.updateStatus([]api.LoadBalancerIngress{})
}

Expand All @@ -131,11 +132,11 @@ func (s *statusSync) sync(key interface{}) error {
return nil
}

ips, err := s.getRunningIPs()
addrs, err := s.runningAddresess()
if err != nil {
return err
}
s.updateStatus(sliceToStatus(ips))
s.updateStatus(sliceToStatus(addrs))

return nil
}
Expand Down Expand Up @@ -180,20 +181,26 @@ func NewStatusSyncer(config Config) Sync {
return st
}

func (s *statusSync) getRunningIPs() ([]string, error) {
// runningAddresess returns a list of IP addresses and/or FQDN where the
// ingress controller is currently running
func (s *statusSync) runningAddresess() ([]string, error) {
if s.PublishService != "" {
ns, name, _ := k8s.ParseNameNS(s.PublishService)
svc, err := s.Client.Core().Services(ns).Get(name)
if err != nil {
return nil, err
}

ips := []string{}
addrs := []string{}
for _, ip := range svc.Status.LoadBalancer.Ingress {
ips = append(ips, ip.IP)
if ip.IP == "" {
addrs = append(addrs, ip.Hostname)
} else {
addrs = append(addrs, ip.IP)
}
}

return ips, nil
return addrs, nil
}

// get information about all the pods running the ingress controller
Expand All @@ -213,10 +220,15 @@ func (s *statusSync) getRunningIPs() ([]string, error) {
return ips, nil
}

func sliceToStatus(ips []string) []api.LoadBalancerIngress {
// sliceToStatus converts a slice of IP and/or hostnames to LoadBalancerIngress
func sliceToStatus(endpoints []string) []api.LoadBalancerIngress {
lbi := []api.LoadBalancerIngress{}
for _, ip := range ips {
lbi = append(lbi, api.LoadBalancerIngress{IP: ip})
for _, ep := range endpoints {
if net.ParseIP(ep) == nil {
lbi = append(lbi, api.LoadBalancerIngress{Hostname: ep})
} else {
lbi = append(lbi, api.LoadBalancerIngress{IP: ep})
}
}

sort.Sort(loadBalancerIngressByIP(lbi))
Expand Down

0 comments on commit 77967aa

Please sign in to comment.