From 2ddfa8fa5943f902e00472aae0f742cb973ee56a Mon Sep 17 00:00:00 2001 From: bonnyr Date: Sun, 16 Jan 2022 21:24:44 -0800 Subject: [PATCH] initial workaound for IPv6 workload support --- internal/configs/ingress.go | 6 +++--- internal/k8s/controller.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/configs/ingress.go b/internal/configs/ingress.go index 1865b84ccb..3addcbbd50 100644 --- a/internal/configs/ingress.go +++ b/internal/configs/ingress.go @@ -456,10 +456,10 @@ func createUpstream(ingEx *IngressEx, name string, backend *networking.IngressBa } for _, endp := range endps { - addressport := strings.Split(endp, ":") + pos := strings.LastIndex(endp, ":") upsServers = append(upsServers, version1.UpstreamServer{ - Address: addressport[0], - Port: addressport[1], + Address: endp[:pos], + Port: endp[pos+1:], MaxFails: cfg.MaxFails, MaxConns: cfg.MaxConns, FailTimeout: cfg.FailTimeout, diff --git a/internal/k8s/controller.go b/internal/k8s/controller.go index 0eb0170bf0..85e2802590 100644 --- a/internal/k8s/controller.go +++ b/internal/k8s/controller.go @@ -2972,7 +2972,7 @@ func getEndpointsBySubselectedPods(targetPort int32, pods []*api_v1.Pod, svcEps } for _, address := range subset.Addresses { if address.IP == pod.Status.PodIP { - addr := fmt.Sprintf("%v:%v", pod.Status.PodIP, targetPort) + addr := ipv6SafeAddrPort(pod.Status.PodIP, targetPort) ownerType, ownerName := getPodOwnerTypeAndName(pod) podEnd := podEndpoint{ Address: addr, @@ -2991,6 +2991,13 @@ func getEndpointsBySubselectedPods(targetPort int32, pods []*api_v1.Pod, svcEps return endps } +func ipv6SafeAddrPort(addr string, port int32) string { + if strings.Count(addr, ":") > 1 && !strings.Contains(addr, "[") { + addr = "[" + addr + "]" + } + return fmt.Sprintf("%v:%v", addr, port) // why %v? +} + func getPodName(pod *api_v1.ObjectReference) string { if pod != nil { return pod.Name @@ -3103,7 +3110,7 @@ func (lbc *LoadBalancerController) getEndpointsForPort(endps api_v1.Endpoints, b if port.Port == targetPort { var endpoints []podEndpoint for _, address := range subset.Addresses { - addr := fmt.Sprintf("%v:%v", address.IP, port.Port) + addr := ipv6SafeAddrPort(address.IP, port.Port) podEnd := podEndpoint{ Address: addr, }