Support hostnames in Ingress status
This commit is contained in:
parent
e1942885f2
commit
77967aa15f
1 changed files with 26 additions and 14 deletions
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package status
|
package status
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -92,19 +93,19 @@ func (s statusSync) Shutdown() {
|
||||||
|
|
||||||
glog.Infof("updating status of Ingress rules (remove)")
|
glog.Infof("updating status of Ingress rules (remove)")
|
||||||
|
|
||||||
ips, err := s.getRunningIPs()
|
addrs, err := s.runningAddresess()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("error obtaining running IPs: %v", ips)
|
glog.Errorf("error obtaining running IPs: %v", addrs)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ips) > 1 {
|
if len(addrs) > 1 {
|
||||||
// leave the job to the next leader
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Infof("removing my ip (%v)", ips)
|
glog.Infof("removing address from ingress status (%v)", addrs)
|
||||||
s.updateStatus([]api.LoadBalancerIngress{})
|
s.updateStatus([]api.LoadBalancerIngress{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,11 +132,11 @@ func (s *statusSync) sync(key interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ips, err := s.getRunningIPs()
|
addrs, err := s.runningAddresess()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.updateStatus(sliceToStatus(ips))
|
s.updateStatus(sliceToStatus(addrs))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -180,7 +181,9 @@ func NewStatusSyncer(config Config) Sync {
|
||||||
return st
|
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 != "" {
|
if s.PublishService != "" {
|
||||||
ns, name, _ := k8s.ParseNameNS(s.PublishService)
|
ns, name, _ := k8s.ParseNameNS(s.PublishService)
|
||||||
svc, err := s.Client.Core().Services(ns).Get(name)
|
svc, err := s.Client.Core().Services(ns).Get(name)
|
||||||
|
@ -188,12 +191,16 @@ func (s *statusSync) getRunningIPs() ([]string, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ips := []string{}
|
addrs := []string{}
|
||||||
for _, ip := range svc.Status.LoadBalancer.Ingress {
|
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
|
// get information about all the pods running the ingress controller
|
||||||
|
@ -213,10 +220,15 @@ func (s *statusSync) getRunningIPs() ([]string, error) {
|
||||||
return ips, nil
|
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{}
|
lbi := []api.LoadBalancerIngress{}
|
||||||
for _, ip := range ips {
|
for _, ep := range endpoints {
|
||||||
lbi = append(lbi, api.LoadBalancerIngress{IP: ip})
|
if net.ParseIP(ep) == nil {
|
||||||
|
lbi = append(lbi, api.LoadBalancerIngress{Hostname: ep})
|
||||||
|
} else {
|
||||||
|
lbi = append(lbi, api.LoadBalancerIngress{IP: ep})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(loadBalancerIngressByIP(lbi))
|
sort.Sort(loadBalancerIngressByIP(lbi))
|
||||||
|
|
Loading…
Reference in a new issue