Skip to content

Commit 2969bf2

Browse files
committed
Create VPC if it doesn't exit
1 parent 91f8ffe commit 2969bf2

13 files changed

+190
-104
lines changed

api/v1beta1/zz_generated.conversion.go

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/zz_generated.conversion.go

+29-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta3/cloudstackfailuredomain_types.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@ type Network struct {
5454
// Cloudstack Network Name the cluster is built in.
5555
Name string `json:"name"`
5656

57+
// Cloudstack Network Gateway the cluster is built in.
58+
// +optional
59+
Gateway string `json:"gateway,omitempty"`
60+
61+
// Cloudstack Network Netmask the cluster is built in.
62+
// +optional
63+
Netmask string `json:"netmask,omitempty"`
64+
5765
// Cloudstack VPC the network belongs to.
5866
// +optional
59-
VPC VPC `json:"vpc,omitempty"`
67+
VPC *VPC `json:"vpc,omitempty"`
6068
}
6169

6270
type VPC struct {
@@ -67,6 +75,10 @@ type VPC struct {
6775
// Cloudstack VPC Name of the network.
6876
// +optional
6977
Name string `json:"name"`
78+
79+
// CIDR for the VPC.
80+
// +optional
81+
CIDR string `json:"cidr,omitempty"`
7082
}
7183

7284
// CloudStackZoneSpec specifies a Zone's details.

api/v1beta3/cloudstackisolatednetwork_types.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@ type CloudStackIsolatedNetworkSpec struct {
4040
// FailureDomainName -- the FailureDomain the network is placed in.
4141
FailureDomainName string `json:"failureDomainName"`
4242

43+
// Gateway for the network.
44+
// +optional
45+
Gateway string `json:"gateway,omitempty"`
46+
47+
// Netmask for the network.
48+
// +optional
49+
Netmask string `json:"netmask,omitempty"`
50+
4351
// VPC the network belongs to.
4452
// +optional
45-
VPC VPC `json:"vpc,omitempty"`
53+
VPC *VPC `json:"vpc,omitempty"`
4654
}
4755

4856
// CloudStackIsolatedNetworkStatus defines the observed state of CloudStackIsolatedNetwork
@@ -59,10 +67,13 @@ type CloudStackIsolatedNetworkStatus struct {
5967

6068
func (n *CloudStackIsolatedNetwork) Network() *Network {
6169
return &Network{
62-
Name: n.Spec.Name,
63-
Type: "IsolatedNetwork",
64-
ID: n.Spec.ID,
65-
VPC: n.Spec.VPC}
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,
76+
}
6677
}
6778

6879
//+kubebuilder:object:root=true

api/v1beta3/zz_generated.deepcopy.go

+17-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+11
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ spec:
391391
network:
392392
description: The network within the Zone to use.
393393
properties:
394+
gateway:
395+
description: Cloudstack Network Gateway the cluster
396+
is built in.
397+
type: string
394398
id:
395399
description: Cloudstack Network ID the cluster is built
396400
in.
@@ -399,13 +403,20 @@ spec:
399403
description: Cloudstack Network Name the cluster is
400404
built in.
401405
type: string
406+
netmask:
407+
description: Cloudstack Network Netmask the cluster
408+
is built in.
409+
type: string
402410
type:
403411
description: Cloudstack Network Type the cluster is
404412
built in.
405413
type: string
406414
vpc:
407415
description: Cloudstack VPC the network belongs to.
408416
properties:
417+
cidr:
418+
description: CIDR for the VPC.
419+
type: string
409420
id:
410421
description: Cloudstack VPC ID of the network.
411422
type: string

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

+11
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,31 @@ spec:
169169
network:
170170
description: The network within the Zone to use.
171171
properties:
172+
gateway:
173+
description: Cloudstack Network Gateway the cluster is built
174+
in.
175+
type: string
172176
id:
173177
description: Cloudstack Network ID the cluster is built in.
174178
type: string
175179
name:
176180
description: Cloudstack Network Name the cluster is built
177181
in.
178182
type: string
183+
netmask:
184+
description: Cloudstack Network Netmask the cluster is built
185+
in.
186+
type: string
179187
type:
180188
description: Cloudstack Network Type the cluster is built
181189
in.
182190
type: string
183191
vpc:
184192
description: Cloudstack VPC the network belongs to.
185193
properties:
194+
cidr:
195+
description: CIDR for the VPC.
196+
type: string
186197
id:
187198
description: Cloudstack VPC ID of the network.
188199
type: string

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

+9
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,24 @@ spec:
192192
description: FailureDomainName -- the FailureDomain the network is
193193
placed in.
194194
type: string
195+
gateway:
196+
description: Gateway for the network.
197+
type: string
195198
id:
196199
description: ID.
197200
type: string
198201
name:
199202
description: Name.
200203
type: string
204+
netmask:
205+
description: Netmask for the network.
206+
type: string
201207
vpc:
202208
description: VPC the network belongs to.
203209
properties:
210+
cidr:
211+
description: CIDR for the VPC.
212+
type: string
204213
id:
205214
description: Cloudstack VPC ID of the network.
206215
type: string

controllers/cloudstackfailuredomain_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *CloudStackFailureDomainReconciliationRunner) Reconcile() (retRes ctrl.R
107107
r.ReconciliationSubject.Spec.Zone.Network.Type == infrav1.NetworkTypeIsolated {
108108
netName := r.ReconciliationSubject.Spec.Zone.Network.Name
109109
if res, err := r.GenerateIsolatedNetwork(
110-
netName, func() string { return r.ReconciliationSubject.Spec.Name })(); r.ShouldReturn(res, err) {
110+
netName, func() string { return r.ReconciliationSubject.Spec.Name }, r.ReconciliationSubject.Spec.Zone.Network)(); r.ShouldReturn(res, err) {
111111
return res, err
112112
} else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
113113
return res, err

controllers/utils/isolated_network.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (r *ReconciliationRunner) IsoNetMetaName(name string) string {
3333
}
3434

3535
// GenerateIsolatedNetwork of the passed name that's owned by the ReconciliationSubject.
36-
func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc func() string) CloudStackReconcilerMethod {
36+
func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc func() string, network infrav1.Network) CloudStackReconcilerMethod {
3737
return func() (ctrl.Result, error) {
3838
lowerName := strings.ToLower(name)
3939
metaName := r.IsoNetMetaName(lowerName)
@@ -43,6 +43,12 @@ func (r *ReconciliationRunner) GenerateIsolatedNetwork(name string, fdNameFunc f
4343
csIsoNet.Spec.FailureDomainName = fdNameFunc()
4444
csIsoNet.Spec.ControlPlaneEndpoint.Host = r.CSCluster.Spec.ControlPlaneEndpoint.Host
4545
csIsoNet.Spec.ControlPlaneEndpoint.Port = r.CSCluster.Spec.ControlPlaneEndpoint.Port
46+
csIsoNet.Spec.Gateway = network.Gateway
47+
csIsoNet.Spec.Netmask = network.Netmask
48+
49+
if network.VPC != nil {
50+
csIsoNet.Spec.VPC = network.VPC
51+
}
4652

4753
if err := r.K8sClient.Create(r.RequestCtx, csIsoNet); err != nil && !ContainsAlreadyExistsSubstring(err) {
4854
return r.ReturnWrappedError(err, "creating isolated network CRD")

0 commit comments

Comments
 (0)