Skip to content

Commit

Permalink
Fix NetworkInterface status propagation for IPs
Browse files Browse the repository at this point in the history
  • Loading branch information
afritzler committed Feb 7, 2024
1 parent c000818 commit bee2f08
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 35 deletions.
3 changes: 1 addition & 2 deletions pkg/api/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package api

import (
"net"
"time"
)

Expand Down Expand Up @@ -97,7 +96,7 @@ type NetworkInterfaceStatus struct {
Name string `json:"name"`
Handle string `json:"handle"`
State NetworkInterfaceState `json:"state"`
IPs []net.IP `json:"ips"`
IPs []string `json:"ips"`
}

type NetworkInterfaceState string
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/machine_controller_nics.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (r *MachineReconciler) attachDetachNetworkInterfaces(
Name: nicName,
Handle: mountedNic.networkInterface.Handle,
State: api.NetworkInterfaceStateAttached,
IPs: desiredNic.Ips,
})
}
}
Expand Down
30 changes: 4 additions & 26 deletions pkg/plugins/networkinterface/apinet/apinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -147,24 +146,8 @@ func (p *Plugin) Apply(ctx context.Context, spec *api.NetworkInterfaceSpec, mach
return nil, fmt.Errorf("error applying apinet network interface: %w", err)
}

hostDev, err := getHostDevice(apinetNic)
if err != nil {
return nil, fmt.Errorf("error getting host device: %w", err)
}
if hostDev != nil {
log.V(1).Info("Host device is ready", "HostDevice", hostDev)
return &providernetworkinterface.NetworkInterface{
Handle: provider.GetNetworkInterfaceID(
apinetNic.Namespace,
apinetNic.Name,
apinetNic.Spec.NodeRef.Name,
apinetNic.UID,
),
HostDevice: hostDev,
}, nil
}

log.V(1).Info("Waiting for apinet network interface to become ready")
var hostDev *providernetworkinterface.HostDevice
apinetNicKey := client.ObjectKeyFromObject(apinetNic)
if err := wait.PollUntilContextTimeout(ctx, 50*time.Millisecond, 5*time.Second, true, func(ctx context.Context) (done bool, err error) {
if err := p.host.APINetClient().Get(ctx, apinetNicKey, apinetNic); err != nil {
Expand All @@ -180,17 +163,12 @@ func (p *Plugin) Apply(ctx context.Context, spec *api.NetworkInterfaceSpec, mach
return nil, fmt.Errorf("error waiting for nic to become ready: %w", err)
}

// Fetch the updated object to get the ID or any other updated fields
if err := p.host.APINetClient().Get(ctx, apinetNicKey, apinetNic); err != nil {
return nil, fmt.Errorf("error fetching updated apinet network interface: %w", err)
}

log.V(1).Info("Host device is ready", "HostDevice", hostDev)
nicIPs := make([]net.IP, 0, len(apinetNic.Spec.IPs))
nicIPs := make([]string, 0, len(apinetNic.Spec.IPs))
for _, apinetNicIP := range apinetNic.Spec.IPs {
// TODO: do proper IP type conversion here
nicIPs = append(nicIPs, net.ParseIP(apinetNicIP.String()))
nicIPs = append(nicIPs, apinetNicIP.String())
}
log.V(1).Info("Host device is ready", "HostDevice", hostDev, "IPs", nicIPs)
return &providernetworkinterface.NetworkInterface{
Handle: provider.GetNetworkInterfaceID(
apinetNic.Namespace,
Expand Down
3 changes: 1 addition & 2 deletions pkg/plugins/networkinterface/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package networkinterface
import (
"context"
"fmt"
"net"

computev1alpha1 "github.com/ironcore-dev/ironcore/api/compute/v1alpha1"
networkingv1alpha1 "github.com/ironcore-dev/ironcore/api/networking/v1alpha1"
Expand Down Expand Up @@ -101,7 +100,7 @@ type NetworkInterface struct {
HostDevice *HostDevice
Isolated *Isolated
ProviderNetwork *ProviderNetwork
IPs []net.IP
IPs []string
}

type Isolated struct{}
Expand Down
6 changes: 1 addition & 5 deletions provider/server/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,11 @@ func (s *Server) getIRINICStatus(machine *api.Machine) ([]*iri.NetworkInterfaceS
return nil, fmt.Errorf("failed to get nic state: %w", err)
}

nicIPs := make([]string, 0, len(nic.IPs))
for _, ip := range nic.IPs {
nicIPs = append(nicIPs, ip.String())
}
nics = append(nics, &iri.NetworkInterfaceStatus{
Name: nic.Name,
Handle: nic.Handle,
State: state,
Ips: nicIPs,
Ips: nic.IPs,
})
}

Expand Down

0 comments on commit bee2f08

Please sign in to comment.