Skip to content

Commit

Permalink
Merge pull request #119 from loxilb-io/multus-default-route-fix
Browse files Browse the repository at this point in the history
PR: Fix for multus endpoint parsing
  • Loading branch information
TrekkieCoder committed Mar 20, 2024
2 parents 72cf6b4 + 1310a2e commit 1c40de7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/k8s/multus.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import (

type dnsIf interface{}

type networkList struct {
Name string `json:"name"`
}

type networkStatus struct {
Name string `json:"name"`
Iface string `json:"interface"`
Expand All @@ -44,6 +48,16 @@ func GetMultusNetworkName(ns, name string) string {
return strings.Join([]string{ns, name}, "/")
}

func UnmarshalNetworkList(ns string) ([]networkList, error) {
data := []networkList{}
err := json.Unmarshal([]byte(ns), &data)
if err != nil {
return data, err
}

return data, nil
}

func UnmarshalNetworkStatus(ns string) ([]networkStatus, error) {
data := []networkStatus{}
err := json.Unmarshal([]byte(ns), &data)
Expand Down Expand Up @@ -96,6 +110,11 @@ func GetMultusEndpoints(kubeClient clientset.Interface, svc *corev1.Service, net
continue
}

podNetList, err := UnmarshalNetworkList(multusNetworkListStr)
if err != nil {
podNetList = []networkList{{Name: multusNetworkListStr}}
}

networkStatusListStr, ok := pod.Annotations["k8s.v1.cni.cncf.io/network-status"]
if !ok {
return epList, errors.New("net found k8s.v1.cni.cncf.io/network-status annotation")
Expand All @@ -106,13 +125,12 @@ func GetMultusEndpoints(kubeClient clientset.Interface, svc *corev1.Service, net
return epList, err
}

multusNetworkList := strings.Split(multusNetworkListStr, ",")
for _, mNet := range multusNetworkList {
if !contain(netList, mNet) {
for _, mNet := range podNetList {
if !contain(netList, mNet.Name) {
continue
}

netName := GetMultusNetworkName(pod.Namespace, mNet)
netName := GetMultusNetworkName(pod.Namespace, mNet.Name)
for _, ns := range networkStatusList {
if ns.Name == netName {
if len(ns.Ips) > 0 {
Expand Down

0 comments on commit 1c40de7

Please sign in to comment.