Skip to content

Commit 53b6a4b

Browse files
committed
feat: add cube and gpu support via templates
1 parent fa77f69 commit 53b6a4b

4 files changed

Lines changed: 75 additions & 14 deletions

File tree

api/v1alpha1/ionoscloudmachine_types.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,17 @@ type IonosCloudMachineSpec struct {
118118
//+kubebuilder:validation:Format=uuid
119119
DatacenterID string `json:"datacenterID"`
120120

121+
// TemplateID is The ID of the template for creating CUBE or GPU servers.
122+
// If a template has GPU cards assigned, then it can only be used to create GPU servers,
123+
// otherwise it can only be used for CUBE servers.
124+
// NumCores, MemoryMB, CPUFamily and the size parameter of the first volume (boot Disk) are ignored when this is set.
125+
// Available TemplateIDs can be listed using the cloud api.
126+
//+kubebuilder:validation:Format=uuid
127+
//+optional
128+
TemplateID string `json:"templateID,omitempty"`
129+
121130
// NumCores defines the number of cores for the VM.
131+
// Ignored when TemplateID is specified.
122132
//+kubebuilder:validation:Minimum=1
123133
//+kubebuilder:default=1
124134
//+optional
@@ -133,6 +143,7 @@ type IonosCloudMachineSpec struct {
133143
// MemoryMB is the memory size for the VM in MB.
134144
// Size must be specified in multiples of 256 MB with a minimum of 1024 MB
135145
// which is required as we are using hot-pluggable RAM by default.
146+
// Ignored when TemplateID is specified.
136147
//+kubebuilder:validation:MultipleOf=1024
137148
//+kubebuilder:validation:Minimum=2048
138149
//+kubebuilder:default=3072
@@ -144,6 +155,7 @@ type IonosCloudMachineSpec struct {
144155
//
145156
// If not specified, the cloud will select a suitable CPU family
146157
// based on the availability in the data center.
158+
// Ignored when TemplateID is specified.
147159
//+kubebuilder:example=AMD_OPTERON
148160
//+optional
149161
CPUFamily *string `json:"cpuFamily,omitempty"`
@@ -180,9 +192,10 @@ type IonosCloudMachineSpec struct {
180192
// +kubebuilder:validation:MinLength=1
181193
NetworkID *string `json:"networkID,omitempty"`
182194

183-
// Type is the server type of the VM. Can be either ENTERPRISE or VCPU.
195+
// Type is the server type of the VM. Can be either ENTERPRISE, VCPU, CUBE or GPU.
196+
// Use the types CUBE or GPU together with TemplateID.
184197
//+kubebuilder:validation:XValidation:rule="self == oldSelf",message="type is immutable"
185-
//+kubebuilder:validation:Enum=ENTERPRISE;VCPU
198+
//+kubebuilder:validation:Enum=ENTERPRISE;VCPU;CUBE;GPU
186199
//+kubebuilder:default=ENTERPRISE
187200
//+optional
188201
Type ServerType `json:"type,omitempty"`
@@ -221,7 +234,8 @@ type Volume struct {
221234
//+optional
222235
DiskType VolumeDiskType `json:"diskType,omitempty"`
223236

224-
// SizeGB defines the size of the volume in GB
237+
// SizeGB defines the size of the volume in GB.
238+
// Ignored when TemplateID of IonosCloudMachineSpec is specified (for the boot volume).
225239
//+kubebuilder:validation:Minimum=10
226240
//+kubebuilder:default=20
227241
//+optional

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ spec:
164164
165165
If not specified, the cloud will select a suitable CPU family
166166
based on the availability in the data center.
167+
Ignored when TemplateID is specified.
167168
example: AMD_OPTERON
168169
type: string
169170
datacenterID:
@@ -242,7 +243,9 @@ spec:
242243
type: string
243244
sizeGB:
244245
default: 20
245-
description: SizeGB defines the size of the volume in GB
246+
description: |-
247+
SizeGB defines the size of the volume in GB.
248+
Ignored when TemplateID of IonosCloudMachineSpec is specified (for the boot volume).
246249
minimum: 10
247250
type: integer
248251
required:
@@ -325,6 +328,7 @@ spec:
325328
MemoryMB is the memory size for the VM in MB.
326329
Size must be specified in multiples of 256 MB with a minimum of 1024 MB
327330
which is required as we are using hot-pluggable RAM by default.
331+
Ignored when TemplateID is specified.
328332
format: int32
329333
minimum: 2048
330334
multipleOf: 1024
@@ -343,7 +347,9 @@ spec:
343347
rule: self == oldSelf
344348
numCores:
345349
default: 1
346-
description: NumCores defines the number of cores for the VM.
350+
description: |-
351+
NumCores defines the number of cores for the VM.
352+
Ignored when TemplateID is specified.
347353
format: int32
348354
minimum: 1
349355
type: integer
@@ -352,13 +358,25 @@ spec:
352358
ProviderID is the IONOS Cloud provider ID
353359
will be in the format ionos://ee090ff2-1eef-48ec-a246-a51a33aa4f3a
354360
type: string
361+
templateID:
362+
description: |-
363+
TemplateID is The ID of the template for creating CUBE or GPU servers.
364+
If a template has GPU cards assigned, then it can only be used to create GPU servers,
365+
otherwise it can only be used for CUBE servers.
366+
NumCores, MemoryMB, CPUFamily and the size parameter of the first volume (boot Disk) are ignored when this is set.
367+
Available TemplateIDs can be listed using the cloud api.
368+
format: uuid
369+
type: string
355370
type:
356371
default: ENTERPRISE
357-
description: Type is the server type of the VM. Can be either ENTERPRISE
358-
or VCPU.
372+
description: |-
373+
Type is the server type of the VM. Can be either ENTERPRISE, VCPU, CUBE or GPU.
374+
Use the types CUBE or GPU together with TemplateID.
359375
enum:
360376
- ENTERPRISE
361377
- VCPU
378+
- CUBE
379+
- GPU
362380
type: string
363381
x-kubernetes-validations:
364382
- message: type is immutable

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ spec:
184184
185185
If not specified, the cloud will select a suitable CPU family
186186
based on the availability in the data center.
187+
Ignored when TemplateID is specified.
187188
example: AMD_OPTERON
188189
type: string
189190
datacenterID:
@@ -264,8 +265,9 @@ spec:
264265
type: string
265266
sizeGB:
266267
default: 20
267-
description: SizeGB defines the size of the volume in
268-
GB
268+
description: |-
269+
SizeGB defines the size of the volume in GB.
270+
Ignored when TemplateID of IonosCloudMachineSpec is specified (for the boot volume).
269271
minimum: 10
270272
type: integer
271273
required:
@@ -349,6 +351,7 @@ spec:
349351
MemoryMB is the memory size for the VM in MB.
350352
Size must be specified in multiples of 256 MB with a minimum of 1024 MB
351353
which is required as we are using hot-pluggable RAM by default.
354+
Ignored when TemplateID is specified.
352355
format: int32
353356
minimum: 2048
354357
multipleOf: 1024
@@ -367,8 +370,9 @@ spec:
367370
rule: self == oldSelf
368371
numCores:
369372
default: 1
370-
description: NumCores defines the number of cores for the
371-
VM.
373+
description: |-
374+
NumCores defines the number of cores for the VM.
375+
Ignored when TemplateID is specified.
372376
format: int32
373377
minimum: 1
374378
type: integer
@@ -377,13 +381,25 @@ spec:
377381
ProviderID is the IONOS Cloud provider ID
378382
will be in the format ionos://ee090ff2-1eef-48ec-a246-a51a33aa4f3a
379383
type: string
384+
templateID:
385+
description: |-
386+
TemplateID is The ID of the template for creating CUBE or GPU servers.
387+
If a template has GPU cards assigned, then it can only be used to create GPU servers,
388+
otherwise it can only be used for CUBE servers.
389+
NumCores, MemoryMB, CPUFamily and the size parameter of the first volume (boot Disk) are ignored when this is set.
390+
Available TemplateIDs can be listed using the cloud api.
391+
format: uuid
392+
type: string
380393
type:
381394
default: ENTERPRISE
382-
description: Type is the server type of the VM. Can be either
383-
ENTERPRISE or VCPU.
395+
description: |-
396+
Type is the server type of the VM. Can be either ENTERPRISE, VCPU, CUBE or GPU.
397+
Use the types CUBE or GPU together with TemplateID.
384398
enum:
385399
- ENTERPRISE
386400
- VCPU
401+
- CUBE
402+
- GPU
387403
type: string
388404
x-kubernetes-validations:
389405
- message: type is immutable

internal/service/cloud/server.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (s *Service) deleteServer(ctx context.Context, ms *scope.Machine, server *s
246246

247247
deleteVolumes := ms.ClusterScope.IsDeleted()
248248
bootVolumeID := server.GetProperties().GetBootVolume().GetId()
249-
if !deleteVolumes && bootVolumeID != nil {
249+
if !deleteVolumes && bootVolumeID != nil && server.Properties.TemplateUuid == nil {
250250
// We need to make sure to only delete volumes if the cluster is being deleted.
251251
// If a node is being replaced, we only delete the boot volume and keep all other volumes.
252252
// The CSI will take care of re-attaching the existing volumes to the new node.
@@ -381,6 +381,14 @@ func (*Service) buildServerProperties(
381381
Type: ptr.To(machineSpec.Type.String()),
382382
}
383383

384+
if machineSpec.TemplateID != "" {
385+
props.TemplateUuid = &machineSpec.TemplateID
386+
387+
props.Cores = nil
388+
props.Ram = nil
389+
props.CpuFamily = nil
390+
}
391+
384392
return props
385393
}
386394

@@ -404,6 +412,11 @@ func (s *Service) buildServerEntities(ms *scope.Machine, params serverEntityPara
404412
},
405413
}
406414

415+
if machineSpec.TemplateID != "" {
416+
bootVolume.Properties.Size = nil
417+
bootVolume.Properties.Type = nil
418+
}
419+
407420
if params.imageID != "" {
408421
bootVolume.Properties.Image = &params.imageID
409422
}

0 commit comments

Comments
 (0)