Skip to content

Commit

Permalink
Merge pull request #187 from ori-edge/upgrade/api
Browse files Browse the repository at this point in the history
convert to k8s.io/api 0.26.1
  • Loading branch information
networkop authored Jan 25, 2023
2 parents d8c7864 + 93b99dd commit c1aacb7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/coredns/coredns v1.10.0
github.com/miekg/dns v1.1.50
github.com/nginxinc/kubernetes-ingress v1.12.5
k8s.io/api v0.25.4
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.25.4
sigs.k8s.io/gateway-api v0.4.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,8 @@ k8s.io/api v0.21.3/go.mod h1:hUgeYHUbBp23Ue4qdX9tR8/ANi/g3ehylAqDn9NWVOg=
k8s.io/api v0.22.1/go.mod h1:bh13rkTp3F1XEaLGykbyRD2QaTTzPm0e/BMd8ptFONY=
k8s.io/api v0.25.4 h1:3YO8J4RtmG7elEgaWMb4HgmpS2CfY1QlaOz9nwB+ZSs=
k8s.io/api v0.25.4/go.mod h1:IG2+RzyPQLllQxnhzD8KQNEu4c4YvyDTpSMztf4A0OQ=
k8s.io/api v0.26.1 h1:f+SWYiPd/GsiWwVRz+NbFyCgvv75Pk9NK6dlkZgpCRQ=
k8s.io/api v0.26.1/go.mod h1:xd/GBNgR0f707+ATNyPmQ1oyKSgndzXij81FzWGsejg=
k8s.io/apiextensions-apiserver v0.21.3/go.mod h1:kl6dap3Gd45+21Jnh6utCx8Z2xxLm8LGDkprcd+KbsE=
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
k8s.io/apimachinery v0.21.3/go.mod h1:H/IM+5vH9kZRNJ4l3x/fXP/5bOPJaVP/guptnZPeCFI=
Expand Down
36 changes: 32 additions & 4 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func lookupServiceIndex(ctrl cache.SharedIndexInformer) func([]string) []netip.A
for _, obj := range objs {
service, _ := obj.(*core.Service)

result = append(result, fetchLoadBalancerIPs(service.Status.LoadBalancer)...)
result = append(result, fetchServiceLoadBalancerIPs(service.Status.LoadBalancer.Ingress)...)
}
return
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func lookupIngressIndex(ctrl cache.SharedIndexInformer) func([]string) []netip.A
for _, obj := range objs {
ingress, _ := obj.(*networking.Ingress)

result = append(result, fetchLoadBalancerIPs(ingress.Status.LoadBalancer)...)
result = append(result, fetchIngressLoadBalancerIPs(ingress.Status.LoadBalancer.Ingress)...)
}

return
Expand Down Expand Up @@ -501,8 +501,36 @@ func fetchGatewayIPs(gw *gatewayapi_v1alpha2.Gateway) (results []netip.Addr) {
return
}

func fetchLoadBalancerIPs(lb core.LoadBalancerStatus) (results []netip.Addr) {
for _, address := range lb.Ingress {
func fetchServiceLoadBalancerIPs(ingresses []core.LoadBalancerIngress) (results []netip.Addr) {

for _, address := range ingresses {
if address.Hostname != "" {
log.Debugf("Looking up hostname %s", address.Hostname)
ips, err := net.LookupIP(address.Hostname)
if err != nil {
continue
}
for _, ip := range ips {
addr, err := netip.ParseAddr(ip.String())
if err != nil {
continue
}
results = append(results, addr)
}
} else if address.IP != "" {
addr, err := netip.ParseAddr(address.IP)
if err != nil {
continue
}
results = append(results, addr)
}
}
return
}

func fetchIngressLoadBalancerIPs(ingresses []networking.IngressLoadBalancerIngress) (results []netip.Addr) {

for _, address := range ingresses {
if address.Hostname != "" {
log.Debugf("Looking up hostname %s", address.Hostname)
ips, err := net.LookupIP(address.Hostname)
Expand Down
16 changes: 12 additions & 4 deletions kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ func TestController(t *testing.T) {
if !isFound(index, found) {
t.Errorf("Ingress key %s not found in index: %v", index, found)
}
ips := fetchIngressLoadBalancerIPs(testObj.Status.LoadBalancer.Ingress)
if len(ips) != 1 {
t.Errorf("Unexpected number of IPs found %d", len(ips))
}
}

for index, testObj := range testServices {
found, _ := serviceHostnameIndexFunc(testObj)
if !isFound(index, found) {
t.Errorf("Service key %s not found in index: %v", index, found)
}
ips := fetchServiceLoadBalancerIPs(testObj.Status.LoadBalancer.Ingress)
if len(ips) != 1 {
t.Errorf("Unexpected number of IPs found %d", len(ips))
}
}

for index, testObj := range testVirtualServers {
Expand Down Expand Up @@ -156,8 +164,8 @@ var testIngresses = map[string]*networking.Ingress{
},
},
Status: networking.IngressStatus{
LoadBalancer: core.LoadBalancerStatus{
Ingress: []core.LoadBalancerIngress{
LoadBalancer: networking.IngressLoadBalancerStatus{
Ingress: []networking.IngressLoadBalancerIngress{
{IP: "192.0.0.1"},
},
},
Expand All @@ -172,8 +180,8 @@ var testIngresses = map[string]*networking.Ingress{
},
},
Status: networking.IngressStatus{
LoadBalancer: core.LoadBalancerStatus{
Ingress: []core.LoadBalancerIngress{
LoadBalancer: networking.IngressLoadBalancerStatus{
Ingress: []networking.IngressLoadBalancerIngress{
{IP: "192.0.0.2"},
},
},
Expand Down

0 comments on commit c1aacb7

Please sign in to comment.