Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit d88615c

Browse files
authored
Merge pull request #29 from GDATASoftwareAG/define-lans-in-spec
define lans in spec
2 parents 74b496d + 76d664b commit d88615c

9 files changed

+278
-4
lines changed

api/v1alpha1/ionoscloudcluster_types.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ type IONOSCloudClusterSpec struct {
9999
Location Location `json:"location"`
100100

101101
// +kubebuilder:validation:MinLength=1
102-
IdentityName string `json:"identityName"`
103-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
102+
IdentityName string `json:"identityName"`
103+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
104+
Lans []IONOSLanSpec `json:"lans,omitempty"`
105+
LoadBalancer *IONOSLoadBalancerSpec `json:"loadBalancer,omitempty"`
104106

105107
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="DataCenterID is immutable"
106108
DataCenterID string `json:"dataCenterID,omitempty"`
@@ -156,3 +158,51 @@ func (c *IONOSCloudCluster) SetConditions(conditions clusterv1.Conditions) {
156158
func init() {
157159
SchemeBuilder.Register(&IONOSCloudCluster{}, &IONOSCloudClusterList{})
158160
}
161+
162+
type IONOSLanSpec struct {
163+
LanID *int32 `json:"lanID,omitempty"` //validate?
164+
Name string `json:"name"` //validate?
165+
Public bool `json:"public"`
166+
//NameTemplate string `json:"nameTemplate"`
167+
//FailoverIPs []string `json:"failoverIPs,omitempty"`
168+
}
169+
170+
type IONOSLoadBalancerSpec struct {
171+
ID string `json:"id,omitempty"`
172+
ListenerLanRef IONOSLanRefSpec `json:"listenerLanRef"`
173+
TargetLanRef IONOSLanRefSpec `json:"targetLanRef"`
174+
}
175+
176+
func (c *IONOSCloudCluster) Lan(name string) *IONOSLanSpec {
177+
for i := range c.Spec.Lans {
178+
if c.Spec.Lans[i].Name == name {
179+
return &c.Spec.Lans[i]
180+
}
181+
}
182+
return nil
183+
}
184+
185+
func (c *IONOSCloudCluster) LanBy(id *int32) *IONOSLanSpec {
186+
if id == nil || *id == 0 {
187+
return nil
188+
}
189+
for i := range c.Spec.Lans {
190+
if c.Spec.Lans[i].LanID == id {
191+
return &c.Spec.Lans[i]
192+
}
193+
}
194+
return nil
195+
}
196+
197+
func (c *IONOSCloudCluster) EnsureLan(spec IONOSLanSpec) {
198+
if spec.Name == "" {
199+
return
200+
}
201+
for i := range c.Spec.Lans {
202+
if c.Spec.Lans[i].Name == spec.Name {
203+
c.Spec.Lans[i] = spec
204+
return
205+
}
206+
}
207+
c.Spec.Lans = append(c.Spec.Lans, spec)
208+
}

api/v1alpha1/ionoscloudmachine_types.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type IONOSCloudMachineSpec struct {
5959
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="IP is immutable"
6060
IP *string `json:"ip,omitempty"`
6161
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="ProviderID is immutable"
62-
ProviderID string `json:"providerID,omitempty"`
62+
ProviderID string `json:"providerID,omitempty"`
63+
Nics []IONOSNicSpec `json:"nics,omitempty"`
6364
}
6465

6566
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.sshKeys) || has(self.sshKeys)", message="SSHKeys is required once set"
@@ -75,6 +76,12 @@ type IONOSVolumeSpec struct {
7576
SSHKeys *[]string `json:"sshKeys,omitempty"`
7677
}
7778

79+
type IONOSNicSpec struct {
80+
LanRef IONOSLanRefSpec `json:"lanRef"`
81+
PrimaryIP *string `json:"primaryIP,omitempty"`
82+
//NameTemplate string `json:"nameTemplate"`
83+
}
84+
7885
// IONOSCloudMachineStatus defines the observed state of IONOSCloudMachine
7986
type IONOSCloudMachineStatus struct {
8087
// Ready is true when the provider resource is ready.
@@ -117,3 +124,16 @@ func (c *IONOSCloudMachine) SetConditions(conditions clusterv1.Conditions) {
117124
func init() {
118125
SchemeBuilder.Register(&IONOSCloudMachine{}, &IONOSCloudMachineList{})
119126
}
127+
128+
func (c *IONOSCloudMachine) EnsureNic(spec IONOSNicSpec) {
129+
if spec.LanRef.Name == "" {
130+
return
131+
}
132+
for i := range c.Spec.Nics {
133+
if c.Spec.Nics[i].LanRef.Name == spec.LanRef.Name {
134+
c.Spec.Nics[i] = spec
135+
return
136+
}
137+
}
138+
c.Spec.Nics = append(c.Spec.Nics, spec)
139+
}

api/v1alpha1/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package v1alpha1
2+
3+
type IONOSLanRefSpec struct {
4+
Name string `json:"name"`
5+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 92 additions & 0 deletions
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_ionoscloudclusters.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,43 @@ spec:
6262
x-kubernetes-validations:
6363
- message: InternetLanID is immutable
6464
rule: self == oldSelf
65+
lans:
66+
items:
67+
properties:
68+
lanID:
69+
format: int32
70+
type: integer
71+
name:
72+
type: string
73+
public:
74+
type: boolean
75+
required:
76+
- name
77+
- public
78+
type: object
79+
type: array
80+
loadBalancer:
81+
properties:
82+
id:
83+
type: string
84+
listenerLanRef:
85+
properties:
86+
name:
87+
type: string
88+
required:
89+
- name
90+
type: object
91+
targetLanRef:
92+
properties:
93+
name:
94+
type: string
95+
required:
96+
- name
97+
type: object
98+
required:
99+
- listenerLanRef
100+
- targetLanRef
101+
type: object
65102
loadBalancerID:
66103
type: string
67104
x-kubernetes-validations:

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ spec:
104104
name:
105105
description: The name of the resource.
106106
type: string
107+
nics:
108+
items:
109+
properties:
110+
lanRef:
111+
properties:
112+
name:
113+
type: string
114+
required:
115+
- name
116+
type: object
117+
primaryIP:
118+
type: string
119+
required:
120+
- lanRef
121+
type: object
122+
type: array
107123
providerID:
108124
type: string
109125
x-kubernetes-validations:

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ spec:
115115
name:
116116
description: The name of the resource.
117117
type: string
118+
nics:
119+
items:
120+
properties:
121+
lanRef:
122+
properties:
123+
name:
124+
type: string
125+
required:
126+
- name
127+
type: object
128+
primaryIP:
129+
type: string
130+
required:
131+
- lanRef
132+
type: object
133+
type: array
118134
providerID:
119135
type: string
120136
x-kubernetes-validations:

internal/controller/ionoscloudcluster_controller.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ func (r *IONOSCloudClusterReconciler) reconcilePrivateLan(ctx *context.ClusterCo
221221
ctx.IONOSCloudCluster.Spec.PrivateLanID = lanID
222222
}
223223

224+
ctx.IONOSCloudCluster.EnsureLan(v1alpha1.IONOSLanSpec{
225+
Name: "private",
226+
LanID: ctx.IONOSCloudCluster.Spec.PrivateLanID,
227+
Public: false,
228+
})
229+
224230
// check status
225231
lanId := fmt.Sprint(*ctx.IONOSCloudCluster.Spec.PrivateLanID)
226232
lan, resp, err := ctx.IONOSClient.GetLan(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, lanId)
@@ -248,6 +254,12 @@ func (r *IONOSCloudClusterReconciler) reconcilePublicLan(ctx *context.ClusterCon
248254
ctx.IONOSCloudCluster.Spec.PublicLanID = lanID
249255
}
250256

257+
ctx.IONOSCloudCluster.EnsureLan(v1alpha1.IONOSLanSpec{
258+
Name: "public",
259+
LanID: ctx.IONOSCloudCluster.Spec.PublicLanID,
260+
Public: true,
261+
})
262+
251263
// check status
252264
lanId := fmt.Sprint(*ctx.IONOSCloudCluster.Spec.PublicLanID)
253265
lan, resp, err := ctx.IONOSClient.GetLan(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, lanId)
@@ -274,6 +286,12 @@ func (r *IONOSCloudClusterReconciler) reconcileInternet(ctx *context.ClusterCont
274286
ctx.IONOSCloudCluster.Spec.InternetLanID = lanID
275287
}
276288

289+
ctx.IONOSCloudCluster.EnsureLan(v1alpha1.IONOSLanSpec{
290+
Name: "internet",
291+
LanID: ctx.IONOSCloudCluster.Spec.InternetLanID,
292+
Public: true,
293+
})
294+
277295
// check status
278296
lanId := fmt.Sprint(*ctx.IONOSCloudCluster.Spec.InternetLanID)
279297
lan, resp, err := ctx.IONOSClient.GetLan(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, lanId)
@@ -325,6 +343,16 @@ func (r *IONOSCloudClusterReconciler) reconcileLoadBalancer(ctx *context.Cluster
325343
ctx.IONOSCloudCluster.Spec.LoadBalancerID = *loadBalancer.Id
326344
}
327345

346+
ctx.IONOSCloudCluster.Spec.LoadBalancer = &v1alpha1.IONOSLoadBalancerSpec{
347+
ID: ctx.IONOSCloudCluster.Spec.LoadBalancerID,
348+
ListenerLanRef: v1alpha1.IONOSLanRefSpec{
349+
Name: "public",
350+
},
351+
TargetLanRef: v1alpha1.IONOSLanRefSpec{
352+
Name: "private",
353+
},
354+
}
355+
328356
// check status
329357
loadBalancer, resp, err := ctx.IONOSClient.GetLoadBalancer(ctx, ctx.IONOSCloudCluster.Spec.DataCenterID, ctx.IONOSCloudCluster.Spec.LoadBalancerID)
330358
if err != nil && resp.StatusCode != http.StatusNotFound {

internal/controller/ionoscloudmachine_controller.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,20 @@ func (r *IONOSCloudMachineReconciler) reconcileServer(ctx *context.MachineContex
384384

385385
nics := *server.Entities.Nics.Items
386386
for _, nic := range nics {
387+
ips := *nic.Properties.Ips
387388
if strings.HasSuffix(*nic.Properties.Name, "-nic-lb") {
388-
ips := *nic.Properties.Ips
389389
ctx.IONOSCloudMachine.Spec.IP = &ips[0]
390390
}
391+
lan := ctx.IONOSCloudCluster.LanBy(nic.Properties.Lan)
392+
if lan == nil {
393+
continue
394+
}
395+
ctx.IONOSCloudMachine.EnsureNic(v1alpha1.IONOSNicSpec{
396+
LanRef: v1alpha1.IONOSLanRefSpec{
397+
Name: lan.Name,
398+
},
399+
PrimaryIP: &ips[0],
400+
})
391401
}
392402

393403
if ctx.IONOSCloudMachine.Spec.IP == nil {

0 commit comments

Comments
 (0)