netstat: Extract the collection of iface status from the pod to a method
@@ -66,20 +66,11 @@ func (c *NetStat) UpdateStatus(vmi *v1.VirtualMachineInstance, domain *api.Domai
return nil
}
- vmi.Status.Interfaces = []v1.VirtualMachineInstanceNetworkInterface{}
- for _, network := range vmi.Spec.Networks {
- podIface, err := c.getPodInterfacefromFileCache(vmi, network.Name)
+ interfacesStatus, err := c.ifacesStatusFromPod(vmi)
if err != nil {
return err
}
-
- ifc := v1.VirtualMachineInstanceNetworkInterface{
- Name: network.Name,
- IP: podIface.PodIP,
- IPs: podIface.PodIPs,
- }
- vmi.Status.Interfaces = append(vmi.Status.Interfaces, ifc)
- }
+ vmi.Status.Interfaces = interfacesStatus
if len(domain.Spec.Devices.Interfaces) > 0 || len(domain.Status.Interfaces) > 0 {
// This calculates the vmi.Status.Interfaces based on the following data sets:
@@ -180,6 +171,23 @@ func (c *NetStat) UpdateStatus(vmi *v1.VirtualMachineInstance, domain *api.Domai
return nil
}
+func (c *NetStat) ifacesStatusFromPod(vmi *v1.VirtualMachineInstance) ([]v1.VirtualMachineInstanceNetworkInterface, error) {
+ ifacesStatus := []v1.VirtualMachineInstanceNetworkInterface{}
+ for _, network := range vmi.Spec.Networks {
+ podIface, err := c.getPodInterfacefromFileCache(vmi, network.Name)
+ if err != nil {
+ return nil, err
+ }
+
+ ifacesStatus = append(ifacesStatus, v1.VirtualMachineInstanceNetworkInterface{
+ Name: network.Name,
+ IP: podIface.PodIP,
+ IPs: podIface.PodIPs,
+ })
+ }
+ return ifacesStatus, nil
+}
+
func (c *NetStat) getPodInterfacefromFileCache(vmi *v1.VirtualMachineInstance, ifaceName string) (*cache.PodCacheInterface, error) {
// Once the Interface files are set on the handler, they don't change
// If already present in the map, don't read again
