Skip to content

Commit

Permalink
udn, cni: Report UDN iface info on network-status
Browse files Browse the repository at this point in the history
Before this commit, this was the network status we reported for a UDN
pod:
```
kubectl get pods pod
-ojsonpath="{@.metadata.annotations.k8s\.v1\.cni\.cncf\.io\/network-status}"
| jq
[
  {
    "name": "ovn-kubernetes",
    "interface": "eth0",
    "ips": [
      "10.244.1.9",
      "fd00:10:244:2::9"
    ],
    "mac": "0a:58:0a:f4:01:09",
    "default": true,
    "dns": {}
  }
]
```

With it, we now report:
```
[
 {
    "name": "ovn-kubernetes",
    "interface": "ovn-udn1",
    "ips": [
      "10.128.0.3"
    ],
    "mac": "0a:58:0a:80:00:03",
    "default": true,
    "dns": {}
  },
  {
    "name": "ovn-kubernetes",
    "interface": "eth0",
    "ips": [
      "10.244.1.6",
      "fd00:10:244:2::6"
    ],
    "mac": "0a:58:0a:f4:01:06",
    "default": false,
    "dns": {}
  }
 ]
```

This way, applications complying to the k8snetworkplumbingwg de-facto
standard can be aware of the UDN interface information.

We report the primary UDN first so the
network-attachment-definition-client can identify which of the 2
interfaces to report as primary [0].

[0]
k8snetworkplumbingwg/network-attachment-definition-client#71

Signed-off-by: Miguel Duarte Barroso <[email protected]>
Co-authored-by: Ram Lavi <[email protected]>
  • Loading branch information
maiqueb and RamLavi committed Sep 17, 2024
1 parent 8974bd4 commit 9c75e9d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,31 @@ func (pr *PodRequest) cmdAddWithGetCNIResultFunc(kubeAuth *KubeAPIAuth, clientse
if err != nil {
return nil, err
}
if _, err := getCNIResultFn(primaryUDNPodRequest, clientset, primaryUDNPodInfo); err != nil {
primaryUDNResult, err := getCNIResultFn(primaryUDNPodRequest, clientset, primaryUDNPodInfo)
if err != nil {
return nil, err
}

defaultClusterNetworkResult := current.Result{
CNIVersion: response.Result.CNIVersion,
Interfaces: response.Result.Interfaces,
IPs: response.Result.IPs,
Routes: response.Result.Routes,
DNS: response.Result.DNS,
}
originalNumberOfIfaces := len(primaryUDNResult.Interfaces)
response.Result.Interfaces = append(primaryUDNResult.Interfaces, response.Result.Interfaces...)
response.Result.IPs = append([]*current.IPConfig{}, primaryUDNResult.IPs...)
for i := range defaultClusterNetworkResult.IPs {
ifaceIPConfig := defaultClusterNetworkResult.IPs[i].Copy()
if ifaceIPConfig.Interface != nil {
ifaceIPConfig.Interface = current.Int(*ifaceIPConfig.Interface + originalNumberOfIfaces)
}
response.Result.IPs = append(response.Result.IPs, ifaceIPConfig)

}

response.Result.Routes = append(primaryUDNResult.Routes, response.Result.Routes...)
}
} else {
response.PodIFInfo = podInterfaceInfo
Expand Down

0 comments on commit 9c75e9d

Please sign in to comment.