Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NetworkInterface status propagation for IPs #161

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need still this comment?

nicIPs = append(nicIPs, net.ParseIP(apinetNicIP.String()))
nicIPs = append(nicIPs, apinetNicIP.String())
}
log.V(1).Info("Host device is ready", "HostDevice", hostDev, "IPs", nicIPs)
Copy link
Contributor

@lukas016 lukas016 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it is good idea log whole structure hostDev and maybe IPs too, how it can help ops guys? Or maybe different level as info, if you need it.

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
Loading