Skip to content

Commit 53fea6e

Browse files
committed
Make network & VPC offering configurable
1 parent 505e11b commit 53fea6e

8 files changed

+71
-9
lines changed

api/v1beta3/cloudstackfailuredomain_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ type Network struct {
6262
// +optional
6363
Netmask string `json:"netmask,omitempty"`
6464

65+
// Cloudstack Network Offering the cluster is built in.
66+
// Default is "DefaultIsolatedNetworkOfferingWithSourceNatService" for
67+
// isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
68+
// for VPC networks.
69+
// +optional
70+
Offering string `json:"offering,omitempty"`
71+
6572
// Cloudstack VPC the network belongs to.
6673
// +optional
6774
VPC *VPC `json:"vpc,omitempty"`
@@ -79,6 +86,11 @@ type VPC struct {
7986
// CIDR for the VPC.
8087
// +optional
8188
CIDR string `json:"cidr,omitempty"`
89+
90+
// Cloudstack VPC Offering for the network.
91+
// Default is "Default VPC offering"
92+
// +optional
93+
Offering string `json:"offering,omitempty"`
8294
}
8395

8496
// CloudStackZoneSpec specifies a Zone's details.

api/v1beta3/cloudstackisolatednetwork_types.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ type CloudStackIsolatedNetworkSpec struct {
4848
// +optional
4949
Netmask string `json:"netmask,omitempty"`
5050

51+
// Offering for the network.
52+
// Default is "DefaultIsolatedNetworkOfferingWithSourceNatService" for
53+
// isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
54+
// for VPC networks.
55+
// +optional
56+
Offering string `json:"offering,omitempty"`
57+
5158
// VPC the network belongs to.
5259
// +optional
5360
VPC *VPC `json:"vpc,omitempty"`
@@ -67,12 +74,13 @@ type CloudStackIsolatedNetworkStatus struct {
6774

6875
func (n *CloudStackIsolatedNetwork) Network() *Network {
6976
return &Network{
70-
Name: n.Spec.Name,
71-
Type: "IsolatedNetwork",
72-
ID: n.Spec.ID,
73-
Gateway: n.Spec.Gateway,
74-
Netmask: n.Spec.Netmask,
75-
VPC: n.Spec.VPC,
77+
Name: n.Spec.Name,
78+
Type: "IsolatedNetwork",
79+
ID: n.Spec.ID,
80+
Gateway: n.Spec.Gateway,
81+
Netmask: n.Spec.Netmask,
82+
VPC: n.Spec.VPC,
83+
Offering: n.Spec.Offering,
7684
}
7785
}
7886

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ spec:
407407
description: Cloudstack Network Netmask the cluster
408408
is built in.
409409
type: string
410+
offering:
411+
description: Cloudstack Network Offering the cluster
412+
is built in. Default is "DefaultIsolatedNetworkOfferingWithSourceNatService"
413+
for isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
414+
for VPC networks.
415+
type: string
410416
type:
411417
description: Cloudstack Network Type the cluster is
412418
built in.
@@ -423,6 +429,10 @@ spec:
423429
name:
424430
description: Cloudstack VPC Name of the network.
425431
type: string
432+
offering:
433+
description: Cloudstack VPC Offering for the network.
434+
Default is "Default VPC offering"
435+
type: string
426436
type: object
427437
required:
428438
- name

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ spec:
184184
description: Cloudstack Network Netmask the cluster is built
185185
in.
186186
type: string
187+
offering:
188+
description: Cloudstack Network Offering the cluster is built
189+
in. Default is "DefaultIsolatedNetworkOfferingWithSourceNatService"
190+
for isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
191+
for VPC networks.
192+
type: string
187193
type:
188194
description: Cloudstack Network Type the cluster is built
189195
in.
@@ -200,6 +206,10 @@ spec:
200206
name:
201207
description: Cloudstack VPC Name of the network.
202208
type: string
209+
offering:
210+
description: Cloudstack VPC Offering for the network.
211+
Default is "Default VPC offering"
212+
type: string
203213
type: object
204214
required:
205215
- name

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ spec:
204204
netmask:
205205
description: Netmask for the network.
206206
type: string
207+
offering:
208+
description: Offering for the network. Default is "DefaultIsolatedNetworkOfferingWithSourceNatService"
209+
for isolated networks and "DefaultIsolatedNetworkOfferingForVpcNetworks"
210+
for VPC networks.
211+
type: string
207212
vpc:
208213
description: VPC the network belongs to.
209214
properties:
@@ -216,6 +221,10 @@ spec:
216221
name:
217222
description: Cloudstack VPC Name of the network.
218223
type: string
224+
offering:
225+
description: Cloudstack VPC Offering for the network. Default
226+
is "Default VPC offering"
227+
type: string
219228
type: object
220229
required:
221230
- controlPlaneEndpoint

pkg/cloud/isolated_network.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (c *client) CreateIsolatedNetwork(fd *infrav1.CloudStackFailureDomain, isoN
112112
offeringName = NetVPCOffering
113113
}
114114

115+
if isoNet.Spec.Offering != "" {
116+
offeringName = isoNet.Spec.Offering
117+
}
118+
115119
// Get network offering ID.
116120
offeringID, err := c.getOfferingID(offeringName)
117121
if err != nil {

pkg/cloud/network.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func (c *client) ResolveNetwork(net *infrav1.Network) (retErr error) {
6565
net.Type = netDetails.Type
6666
net.Gateway = netDetails.Gateway
6767
net.Netmask = netDetails.Netmask
68+
net.Offering = netDetails.Networkofferingname
6869
if netDetails.Vpcid != "" {
6970
if net.VPC == nil {
7071
net.VPC = &infrav1.VPC{}
@@ -88,6 +89,7 @@ func (c *client) ResolveNetwork(net *infrav1.Network) (retErr error) {
8889
net.Type = netDetails.Type
8990
net.Gateway = netDetails.Gateway
9091
net.Netmask = netDetails.Netmask
92+
net.Offering = netDetails.Networkofferingname
9193
if netDetails.Vpcid != "" {
9294
if net.VPC == nil {
9395
net.VPC = &infrav1.VPC{}

pkg/cloud/vpc.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ type VPCIface interface {
4040
}
4141

4242
// getVPCOfferingID fetches a vpc offering id.
43-
func (c *client) getVPCOfferingID() (string, error) {
44-
offeringID, count, retErr := c.cs.VPC.GetVPCOfferingID(VPCOffering)
43+
func (c *client) getVPCOfferingID(offeringName string) (string, error) {
44+
offeringID, count, retErr := c.cs.VPC.GetVPCOfferingID(offeringName)
4545
if retErr != nil {
4646
c.customMetrics.EvaluateErrorAndIncrementAcsReconciliationErrorCounter(retErr)
4747
return "", retErr
@@ -70,6 +70,7 @@ func (c *client) ResolveVPC(vpc *infrav1.VPC) error {
7070
}
7171
vpc.Name = resp.Name
7272
vpc.CIDR = resp.Cidr
73+
vpc.Offering = resp.Vpcofferingname
7374
return nil
7475
}
7576

@@ -84,6 +85,7 @@ func (c *client) ResolveVPC(vpc *infrav1.VPC) error {
8485
}
8586
vpc.ID = resp.Id
8687
vpc.CIDR = resp.Cidr
88+
vpc.Offering = resp.Vpcofferingname
8789
return nil
8890
}
8991

@@ -93,7 +95,12 @@ func (c *client) CreateVPC(fd *infrav1.CloudStackFailureDomain, vpc *infrav1.VPC
9395
return errors.New("VPC name must be specified")
9496
}
9597

96-
offeringID, err := c.getVPCOfferingID()
98+
offeringName := VPCOffering
99+
if vpc.Offering != "" {
100+
offeringName = vpc.Offering
101+
}
102+
103+
offeringID, err := c.getVPCOfferingID(offeringName)
97104
if err != nil {
98105
return err
99106
}

0 commit comments

Comments
 (0)