66package backend
77
88import (
9- "github.com/foundation-model-stack/multi-nic-cni/daemon/iface"
109 "k8s.io/client-go/discovery"
1110 "k8s.io/client-go/dynamic"
1211
@@ -17,11 +16,24 @@ import (
1716 "k8s.io/client-go/rest"
1817)
1918
19+ type InterfaceInfoType struct {
20+ InterfaceName string `json:"interfaceName"`
21+ NetAddress string `json:"netAddress"`
22+ HostIP string `json:"hostIP"`
23+ Vendor string `json:"vendor"`
24+ Product string `json:"product"`
25+ PciAddress string `json:"pciAddress"`
26+ }
27+
2028const (
2129 HOSTINTERFACE_RESOURCE = "hostinterfaces.v1.multinic.fms.io"
2230 HOSTINTERFACE_KIND = "hostinterfaces"
2331)
2432
33+ var (
34+ unmanagedLabelName = "multi-nic-unmanaged"
35+ )
36+
2537type HostInterfaceHandler struct {
2638 * DynamicHandler
2739 hostName string
@@ -43,14 +55,14 @@ func NewHostInterfaceHandler(config *rest.Config, hostName string) *HostInterfac
4355 return handler
4456}
4557
46- func (h * HostInterfaceHandler ) parse (uobj * unstructured.Unstructured ) ([]iface. InterfaceInfoType , error ) {
47- var infos []iface. InterfaceInfoType
58+ func (h * HostInterfaceHandler ) parse (uobj * unstructured.Unstructured ) ([]InterfaceInfoType , error ) {
59+ var infos []InterfaceInfoType
4860 var err error
4961 spec := uobj .Object ["spec" ].(map [string ]interface {})
5062 if v , found := spec ["interfaces" ]; found {
5163 if vals , ok := v .([]interface {}); ok {
5264 for _ , v := range vals {
53- var info iface. InterfaceInfoType
65+ var info InterfaceInfoType
5466 h .DynamicHandler .Parse (v .(map [string ]interface {}), & info )
5567 infos = append (infos , info )
5668 }
@@ -63,11 +75,24 @@ func (h *HostInterfaceHandler) parse(uobj *unstructured.Unstructured) ([]iface.I
6375 return infos , err
6476}
6577
66- func (h * HostInterfaceHandler ) GetHostInterfaces () ([]iface. InterfaceInfoType , error ) {
78+ func (h * HostInterfaceHandler ) GetHostInterfaces () ([]InterfaceInfoType , error ) {
6779 hifobj , err := h .DynamicHandler .Get (h .hostName , metav1 .NamespaceAll , metav1.GetOptions {})
6880 if err == nil {
6981 infos , err := h .parse (hifobj )
7082 return infos , err
7183 }
72- return []iface.InterfaceInfoType {}, err
84+ return []InterfaceInfoType {}, err
85+ }
86+
87+ func (h * HostInterfaceHandler ) GetUnmanagedHostInterfaces () ([]InterfaceInfoType , error ) {
88+ hifobj , err := h .DynamicHandler .Get (h .hostName , metav1 .NamespaceAll , metav1.GetOptions {})
89+ if err == nil {
90+ if labels := hifobj .GetLabels (); labels != nil {
91+ if labels [unmanagedLabelName ] == "true" {
92+ infos , err := h .parse (hifobj )
93+ return infos , err
94+ }
95+ }
96+ }
97+ return []InterfaceInfoType {}, err
7398}
0 commit comments