Skip to content

Commit d2c47d0

Browse files
Add ID in the network spec
1 parent cec9455 commit d2c47d0

File tree

4 files changed

+61
-88
lines changed

4 files changed

+61
-88
lines changed

api/v1beta3/cloudstackmachine_types.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ const (
3333
)
3434

3535
type NetworkSpec struct {
36-
// The name of the network
36+
// CloudStack Network Name (required to resolve ID)
3737
Name string `json:"name"`
38-
// Optional static IP in that network
38+
39+
// Optional IP in the network
3940
IP string `json:"ip,omitempty"`
41+
42+
// Optional Network ID (overrides Name if set)
43+
ID string `json:"id,omitempty"`
4044
}
4145

4246
// CloudStackMachineSpec defines the desired state of CloudStackMachine
@@ -62,13 +66,10 @@ type CloudStackMachineSpec struct {
6266
// +optional
6367
DiskOffering CloudStackResourceDiskOffering `json:"diskOffering,omitempty"`
6468

65-
// The primary network interface (overrides zone.network)
66-
// +optional
67-
Network *NetworkSpec `json:"network,omitempty"`
68-
69-
// Additional networks (attached as secondary NICs)
69+
// The list of networks (overrides zone.network)
7070
// +optional
71-
ExtraNetworks []NetworkSpec `json:"extraNetworks,omitempty"`
71+
// In CloudStackMachineSpec
72+
Networks []NetworkSpec `json:"networks,omitempty"`
7273

7374
// CloudStack ssh key to use.
7475
// +optional

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackmachines.yaml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -645,20 +645,6 @@ spec:
645645
- label
646646
- mountPath
647647
type: object
648-
extraNetworks:
649-
description: Additional networks (attached as secondary NICs)
650-
items:
651-
properties:
652-
ip:
653-
description: Optional static IP in that network
654-
type: string
655-
name:
656-
description: The name of the network
657-
type: string
658-
required:
659-
- name
660-
type: object
661-
type: array
662648
failureDomainName:
663649
description: FailureDomainName -- the name of the FailureDomain the
664650
machine is placed in.
@@ -673,18 +659,25 @@ spec:
673659
name:
674660
description: Name.
675661
type: string
676-
network:
677-
description: The primary network interface (overrides zone.network)
678-
properties:
679-
ip:
680-
description: Optional static IP in that network
681-
type: string
682-
name:
683-
description: The name of the network
684-
type: string
685-
required:
686-
- name
687-
type: object
662+
networks:
663+
description: |-
664+
The list of networks (overrides zone.network)
665+
In CloudStackMachineSpec
666+
items:
667+
properties:
668+
id:
669+
description: Optional Network ID (overrides Name if set)
670+
type: string
671+
ip:
672+
description: Optional IP in the network
673+
type: string
674+
name:
675+
description: CloudStack Network Name (required to resolve ID)
676+
type: string
677+
required:
678+
- name
679+
type: object
680+
type: array
688681
offering:
689682
description: CloudStack compute offering.
690683
properties:

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackmachinetemplates.yaml

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,6 @@ spec:
580580
- label
581581
- mountPath
582582
type: object
583-
extraNetworks:
584-
description: Additional networks (attached as secondary NICs)
585-
items:
586-
properties:
587-
ip:
588-
description: Optional static IP in that network
589-
type: string
590-
name:
591-
description: The name of the network
592-
type: string
593-
required:
594-
- name
595-
type: object
596-
type: array
597583
failureDomainName:
598584
description: FailureDomainName -- the name of the FailureDomain
599585
the machine is placed in.
@@ -608,18 +594,27 @@ spec:
608594
name:
609595
description: Name.
610596
type: string
611-
network:
612-
description: The primary network interface (overrides zone.network)
613-
properties:
614-
ip:
615-
description: Optional static IP in that network
616-
type: string
617-
name:
618-
description: The name of the network
619-
type: string
620-
required:
621-
- name
622-
type: object
597+
networks:
598+
description: |-
599+
The list of networks (overrides zone.network)
600+
In CloudStackMachineSpec
601+
items:
602+
properties:
603+
id:
604+
description: Optional Network ID (overrides Name if
605+
set)
606+
type: string
607+
ip:
608+
description: Optional IP in the network
609+
type: string
610+
name:
611+
description: CloudStack Network Name (required to resolve
612+
ID)
613+
type: string
614+
required:
615+
- name
616+
type: object
617+
type: array
623618
offering:
624619
description: CloudStack compute offering.
625620
properties:

pkg/cloud/instance.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -334,39 +334,23 @@ func (c *client) DeployVM(
334334

335335
p := c.cs.VirtualMachine.NewDeployVirtualMachineParams(offering.Id, templateID, fd.Spec.Zone.ID)
336336

337-
if csMachine.Spec.Network == nil && len(csMachine.Spec.ExtraNetworks) == 0 && fd.Spec.Zone.Network.ID != "" {
338-
// No explicit NICs; fallback to single default network ID
337+
if len(csMachine.Spec.Networks) == 0 && fd.Spec.Zone.Network.ID != "" {
339338
p.SetNetworkids([]string{fd.Spec.Zone.Network.ID})
340339
} else {
341-
// Build ipToNetworkList for multiple NICs
342340
ipToNetworkList := []map[string]string{}
343341

344-
// Primary NIC
345-
if csMachine.Spec.Network != nil {
346-
id, err := c.resolveNetworkIDByName(csMachine.Spec.Network.Name)
347-
if err != nil {
348-
return err
342+
for _, net := range csMachine.Spec.Networks {
343+
networkID := net.ID
344+
if networkID == "" {
345+
var err error
346+
networkID, err = c.resolveNetworkIDByName(net.Name)
347+
if err != nil {
348+
return err
349+
}
349350
}
350-
entry := map[string]string{"networkid": id}
351-
if csMachine.Spec.Network.IP != "" {
352-
entry["ip"] = csMachine.Spec.Network.IP
353-
}
354-
ipToNetworkList = append(ipToNetworkList, entry)
355-
} else if fd.Spec.Zone.Network.ID != "" {
356-
ipToNetworkList = append(ipToNetworkList, map[string]string{
357-
"networkid": fd.Spec.Zone.Network.ID,
358-
})
359-
}
360-
361-
// Extra NICs
362-
for _, extra := range csMachine.Spec.ExtraNetworks {
363-
id, err := c.resolveNetworkIDByName(extra.Name)
364-
if err != nil {
365-
return err
366-
}
367-
entry := map[string]string{"networkid": id}
368-
if extra.IP != "" {
369-
entry["ip"] = extra.IP
351+
entry := map[string]string{"networkid": networkID}
352+
if net.IP != "" {
353+
entry["ip"] = net.IP
370354
}
371355
ipToNetworkList = append(ipToNetworkList, entry)
372356
}

0 commit comments

Comments
 (0)