Skip to content

Commit

Permalink
gh-212 Minor fixes for dual-stack support
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Dec 7, 2024
1 parent 0a5f34b commit 4af695d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
18 changes: 16 additions & 2 deletions pkg/agent/manager/loadbalancer/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ func (m *Manager) genExtIPName(ipStr string) []string {
return hosts
}
}
if tk.IsNetIPv6(ipStr) {
ipStrSlice := strings.Split(ipStr, ":")
ipStr = strings.Join(ipStrSlice, "-")
}
return []string{prefix + ipStr}
}

Expand Down Expand Up @@ -432,6 +436,9 @@ func (m *Manager) addLoadBalancer(svc *corev1.Service) error {

var sipPools []*ippool.IPPool
ipPool := m.ipPoolTbl[defaultPoolName]
if addrType == "ipv6" || addrType == "ipv6to4" {
ipPool = m.ip6PoolTbl[defaultPoolName]
}

// Check for loxilb specific annotations - poolName
if pn := svc.Annotations[PoolNameAnnotation]; pn != "" {
Expand Down Expand Up @@ -1561,15 +1568,22 @@ func (m *Manager) getServiceIngressIPs(service *corev1.Service) []string {
} else {
llbHost := strings.Split(ingress.Hostname, "-")

if len(llbHost) != 2 {
if len(llbHost) < 2 {
if net.ParseIP(llbHost[0]) != nil {
ingressIP = llbHost[0]

}
} else {
if llbHost[0] == m.networkConfig.Zone {
if net.ParseIP(llbHost[1]) != nil {
ingressIP = llbHost[1]
} else if len(llbHost) > 2 {
ipStrSlice := llbHost[1:]
if len(ipStrSlice) > 0 {
ipStr := strings.Join(ipStrSlice, ":")
if net.ParseIP(ipStr) != nil {
ingressIP = ipStr
}
}
}
} else {
continue
Expand Down
17 changes: 14 additions & 3 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"crypto/tls"
"crypto/x509"
"fmt"
tk "github.com/loxilb-io/loxilib"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"net"
"net/http"
"net/url"
"strings"
"time"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
)

type LoxiZoneInst struct {
Expand Down Expand Up @@ -64,6 +65,16 @@ func NewLoxiClient(apiServer string, aliveCh chan *LoxiClient, deadCh chan struc
return nil, err
}

hostPort := strings.Split(base.Host, ":")
if len(hostPort) > 1 {
shostPort := hostPort[:len(hostPort)-1]
host := strings.Join(shostPort[:], ":")
if tk.IsNetIPv6(host) {
host = fmt.Sprintf("[%s]", host)
}
base.Host = fmt.Sprintf("%s:%s", host, hostPort[len(hostPort)-1])
}

host, port, err := net.SplitHostPort(base.Host)
if err != nil {
klog.Errorf("failed to parse host,port %s. err: %s", base.Host, err.Error())
Expand Down
22 changes: 17 additions & 5 deletions pkg/k8s/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,28 @@ func GetServiceLocalEndpoints(kubeClient clientset.Interface, svc *corev1.Servic

epMap := make(map[string]struct{})
for _, pod := range podList.Items {

if pod.Status.HostIP != "" {
hostIP := pod.Status.HostIP
if addrType == "ipv6" && !tk.IsNetIPv6(pod.Status.HostIP) {
continue
v6found := false
for _, ip := range pod.Status.HostIPs {
if tk.IsNetIPv6(ip.String()) {
hostIP = ip.String()
v6found = true
break
}
}
if !v6found {
continue
}
}
if len(nodeMatchList) > 0 && !MatchNodeinNodeList(pod.Status.HostIP, nodeMatchList) {
if len(nodeMatchList) > 0 && !MatchNodeinNodeList(hostIP, nodeMatchList) {
continue
}
if _, found := epMap[pod.Status.HostIP]; !found {
epMap[pod.Status.HostIP] = struct{}{}
epList = append(epList, pod.Status.HostIP)
if _, found := epMap[hostIP]; !found {
epMap[hostIP] = struct{}{}
epList = append(epList, hostIP)
}
}
}
Expand Down

0 comments on commit 4af695d

Please sign in to comment.