Skip to content
Merged
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
32 changes: 22 additions & 10 deletions api/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,37 @@ const (
)

type NetworkInterfaceSpec struct {
Name string `json:"name"`
NetworkId string `json:"networkId"`
Ips []string `json:"ips"`
Attributes map[string]string `json:"attributes"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
Metadata *NetworkInterfaceMetadata `json:"metadata,omitempty"`
Name string `json:"name"`
NetworkId string `json:"networkId"`
Ips []string `json:"ips"`
Attributes map[string]string `json:"attributes"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}

type NetworkInterfaceMetadata struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

type NetworkInterfaceStatus struct {
Name string `json:"name"`
Handle string `json:"handle"`
State NetworkInterfaceState `json:"state"`
Type NetworkInterfaceType `json:"type,omitempty"`
Path string `json:"path,omitempty"`
Name string `json:"name"`
Handle string `json:"handle"`
State NetworkInterfaceState `json:"state"`
Type NetworkInterfaceType `json:"type,omitempty"`
Path string `json:"path,omitempty"`
Ips []string `json:"ips,omitempty"`
Prefixes []string `json:"prefixes,omitempty"`
VirtualIP string `json:"virtualIP,omitempty"`
}

type NetworkInterfaceState string

const (
NetworkInterfaceStatePending NetworkInterfaceState = "Pending"
NetworkInterfaceStateReady NetworkInterfaceState = "Ready"
NetworkInterfaceStateError NetworkInterfaceState = "Error"
NetworkInterfaceStatePrepared NetworkInterfaceState = "Prepared"
NetworkInterfaceStateAttached NetworkInterfaceState = "Attached"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-logr/logr v1.4.4
github.com/google/uuid v1.6.0
github.com/ironcore-dev/controller-utils v0.15.0
github.com/ironcore-dev/ironcore v0.8.1-0.20260924093634-7346f4f9b904
github.com/ironcore-dev/ironcore v0.8.1-0.20261005140517-6ec7ff227ec3
github.com/ironcore-dev/ironcore-image v0.5.0
github.com/ironcore-dev/ironcore-net v0.6.0
github.com/ironcore-dev/provider-utils v0.0.0-20261023075413-1d4246454a50
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ github.com/ironcore-dev/brokers v0.0.0-20260928082849-628cc25fd8ca h1:fLdDpNuymi
github.com/ironcore-dev/brokers v0.0.0-20260928082849-628cc25fd8ca/go.mod h1:2RWGtX3C0UaYqah5SgglJH2fM9oUu1njzY5oXneVWoI=
github.com/ironcore-dev/controller-utils v0.15.0 h1:K8vMOeY8rMyZcoL67hGvOZxxPb7rlrR6yS5VvcP6Xig=
github.com/ironcore-dev/controller-utils v0.15.0/go.mod h1:E/3nSv9TxRtSGpejWMwLTxbb9fknTcPhcA8moHXa0sY=
github.com/ironcore-dev/ironcore v0.8.1-0.20260924093634-7346f4f9b904 h1:/EDdIi+hDurZy1zJCNprTWaqZQDAg4mo5wW7s78PXUk=
github.com/ironcore-dev/ironcore v0.8.1-0.20260924093634-7346f4f9b904/go.mod h1:LkAjBGMMwMgomdJK1MqwRyK1IWjMraIZ4NmUxWL24F4=
github.com/ironcore-dev/ironcore v0.8.1-0.20261005140517-6ec7ff227ec3 h1:yNMKZ/ZSS9q7FV2KD0ZATIygUMbYTXypGb6t5Fq6juY=
github.com/ironcore-dev/ironcore v0.8.1-0.20261005140517-6ec7ff227ec3/go.mod h1:X0QNN3CcgLwB+nL7w+C+zaCI/l09BKIQELjbZdEa8/s=
github.com/ironcore-dev/ironcore-image v0.5.0 h1:L4ZLIV5WhOFk4Bp+PtBXut6nYXsCRAoyEiZe+CknPOg=
github.com/ironcore-dev/ironcore-image v0.5.0/go.mod h1:seDdoS2K31VpL4LlKC9apbLs2fbGrHZEsPBR3dBYMs0=
github.com/ironcore-dev/ironcore-net v0.6.0 h1:0O81zKDqxUrXkJX2o2ne49bE2PwRRe4C+isShk7ZKuM=
Expand Down
33 changes: 27 additions & 6 deletions internal/plugins/networkinterface/apinet/apinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ func (p *Plugin) Apply(
apinetNic.Spec.NodeRef.Name,
apinetNic.UID,
),
State: api.NetworkInterfaceStatePrepared,
Type: deviceType,
Path: path,
State: api.NetworkInterfaceStatePrepared,
Type: deviceType,
Path: path,
Ips: toString(apinetNic.Spec.IPs),
Prefixes: toString(apinetNic.Status.Prefixes),
VirtualIP: virtualIP(apinetNic),
}, nil
}

Expand Down Expand Up @@ -211,9 +214,12 @@ func (p *Plugin) Apply(
apinetNic.Spec.NodeRef.Name,
apinetNic.UID,
),
State: api.NetworkInterfaceStatePrepared,
Type: deviceType,
Path: path,
State: api.NetworkInterfaceStatePrepared,
Type: deviceType,
Path: path,
Ips: toString(apinetNic.Spec.IPs),
Prefixes: toString(apinetNic.Status.Prefixes),
VirtualIP: virtualIP(apinetNic),
}, nil
}

Expand All @@ -223,6 +229,21 @@ func (p *Plugin) Apply(
}, nil
}

func toString[S fmt.Stringer](ss []S) []string {
ret := make([]string, len(ss))
for i, s := range ss {
ret[i] = s.String()
}
return ret
}

func virtualIP(nic *apinetv1alpha1.NetworkInterface) string {
if len(nic.Status.PublicIPs) == 0 {
return ""
}
return nic.Status.PublicIPs[0].String()
}

func getDeviceInfo(status *apinetv1alpha1.NetworkInterfaceStatus) (string, api.NetworkInterfaceType, error) {
if status.PCIAddress != nil {
pciDevice := status.PCIAddress
Expand Down
42 changes: 38 additions & 4 deletions internal/server/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ironcore-dev/cloud-hypervisor-provider/api"
iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1"
irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
"k8s.io/utils/ptr"
)

Expand Down Expand Up @@ -104,6 +105,7 @@ func (s *Server) getIRINICSpec(machine *api.Machine) []*iri.NetworkInterface {
NetworkId: nic.NetworkId,
Ips: nic.Ips,
Attributes: nic.Attributes,
Metadata: getIRINetworkInterfaceMetadata(nic.Metadata),
})
}

Expand Down Expand Up @@ -137,9 +139,12 @@ func (s *Server) getIRINICStatus(machine *api.Machine) ([]*iri.NetworkInterfaceS
}

nics = append(nics, &iri.NetworkInterfaceStatus{
Name: nic.Name,
Handle: nic.Handle,
State: state,
Name: nic.Name,
Handle: nic.Handle,
State: state,
Ips: nic.Ips,
Prefixes: nic.Prefixes,
VirtualIp: nic.VirtualIP,
})
}

Expand Down Expand Up @@ -176,9 +181,13 @@ func (s *Server) getIRINICState(state api.NetworkInterfaceState) (iri.NetworkInt
case api.NetworkInterfaceStateAttached:
return iri.NetworkInterfaceState_NETWORK_INTERFACE_ATTACHED, nil
case api.NetworkInterfaceStatePrepared:
fallthrough
return iri.NetworkInterfaceState_NETWORK_INTERFACE_READY, nil
case api.NetworkInterfaceStateReady:
return iri.NetworkInterfaceState_NETWORK_INTERFACE_READY, nil
case api.NetworkInterfaceStatePending:
return iri.NetworkInterfaceState_NETWORK_INTERFACE_PENDING, nil
case api.NetworkInterfaceStateError:
return iri.NetworkInterfaceState_NETWORK_INTERFACE_ERROR, nil
default:
return 0, fmt.Errorf("unknown network interface state '%q'", state)
}
Expand Down Expand Up @@ -278,9 +287,34 @@ func (s *Server) getNICFromIRINIC(iriNIC *iri.NetworkInterface) (*api.NetworkInt
}

return &api.NetworkInterfaceSpec{
Metadata: getNetworkInterfaceMetadata(iriNIC.Metadata),
Name: iriNIC.Name,
NetworkId: iriNIC.NetworkId,
Ips: iriNIC.Ips,
Attributes: iriNIC.Attributes,
}, nil
}

func getIRINetworkInterfaceMetadata(metadata *api.NetworkInterfaceMetadata) *irimeta.ObjectMetadata {
if metadata == nil {
return nil
}

return &irimeta.ObjectMetadata{
Id: metadata.ID,
Name: metadata.Name,
Namespace: metadata.Namespace,
}
}

func getNetworkInterfaceMetadata(metadata *irimeta.ObjectMetadata) *api.NetworkInterfaceMetadata {
if metadata == nil {
return nil
}

return &api.NetworkInterfaceMetadata{
ID: metadata.Id,
Name: metadata.Name,
Namespace: metadata.Namespace,
}
}
9 changes: 4 additions & 5 deletions internal/server/machine_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ func (s *Server) createMachineFromIRIMachine(

var networkInterfaces []*api.NetworkInterfaceSpec
for _, iriNetworkInterface := range iriMachine.Spec.NetworkInterfaces {
networkInterfaceSpec := &api.NetworkInterfaceSpec{
Name: iriNetworkInterface.Name,
NetworkId: iriNetworkInterface.NetworkId,
Ips: iriNetworkInterface.Ips,
Attributes: iriNetworkInterface.Attributes,
networkInterfaceSpec, err := s.getNICFromIRINIC(iriNetworkInterface)
if err != nil {
return nil, fmt.Errorf("error converting network interface: %w", err)
}

networkInterfaces = append(networkInterfaces, networkInterfaceSpec)
}

Expand Down
10 changes: 10 additions & 0 deletions internal/server/machine_networkinterface_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var _ = Describe("AttachNetworkInterface", func() {
Name: "my-nic",
NetworkId: "network-id",
Ips: []string{"10.0.0.1"},
Metadata: &irimeta.ObjectMetadata{
Id: "nic-uid-1",
Name: "nic-name-1",
Namespace: "nic-namespace-1",
},
},
})).Error().NotTo(HaveOccurred())

Expand All @@ -49,5 +54,10 @@ var _ = Describe("AttachNetworkInterface", func() {
Expect(err).NotTo(HaveOccurred())
Expect(updatedMachine.Machines).To(HaveLen(1))
Expect(updatedMachine.Machines[0].Spec.NetworkInterfaces).To(HaveLen(1))
Expect(updatedMachine.Machines[0].Spec.NetworkInterfaces[0].Metadata).To(Equal(&irimeta.ObjectMetadata{
Id: "nic-uid-1",
Name: "nic-name-1",
Namespace: "nic-namespace-1",
}))
})
})
Loading