Skip to content

Commit 14e2818

Browse files
jwmay2012Jordan May
authored andcommitted
Add support for Spot VMs
1 parent 67ff6d8 commit 14e2818

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

api/v1beta1/gcpmachine_types.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ type CustomerEncryptionKey struct {
216216
// +optional
217217
SuppliedKey *SuppliedKey `json:"suppliedKey,omitempty"`
218218
}
219+
type ProvisioningModel string
220+
221+
const (
222+
ProvisioningModelStandard ProvisioningModel = "Standard"
223+
ProvisioningModelSpot ProvisioningModel = "Spot"
224+
)
219225

220226
// GCPMachineSpec defines the desired state of GCPMachine.
221227
type GCPMachineSpec struct {
@@ -302,6 +308,14 @@ type GCPMachineSpec struct {
302308
// +optional
303309
Preemptible bool `json:"preemptible,omitempty"`
304310

311+
// ProvisioningModel defines if instance is spot.
312+
// If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible".
313+
// If "Spot", VM type is "Spot".
314+
// +kubebuilder:validation:Enum=Standard;Spot
315+
// +kubebuilder:default=Standard
316+
// +optional
317+
ProvisioningModel *ProvisioningModel `json:"provisioningModel,omitempty"`
318+
305319
// IPForwarding Allows this instance to send and receive packets with non-matching destination or source IPs.
306320
// This is required if you plan to use this instance to forward routes. Defaults to enabled.
307321
// +kubebuilder:validation:Enum=Enabled;Disabled

cloud/scope/machine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance {
402402
Preemptible: m.GCPMachine.Spec.Preemptible,
403403
},
404404
}
405+
if m.GCPMachine.Spec.ProvisioningModel != nil && *m.GCPMachine.Spec.ProvisioningModel == infrav1.ProvisioningModelSpot {
406+
instance.Scheduling.ProvisioningModel = "SPOT"
407+
}
405408

406409
instance.CanIpForward = true
407410
if m.GCPMachine.Spec.IPForwarding != nil && *m.GCPMachine.Spec.IPForwarding == infrav1.IPForwardingDisabled {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ spec:
231231
preemptible:
232232
description: Preemptible defines if instance is preemptible
233233
type: boolean
234+
provisioningModel:
235+
default: Standard
236+
description: |-
237+
ProvisioningModel defines if instance is spot.
238+
If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible".
239+
If "Spot", VM type is "Spot".
240+
enum:
241+
- Standard
242+
- Spot
243+
type: string
234244
providerID:
235245
description: ProviderID is the unique identifier as specified by the
236246
cloud provider.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ spec:
246246
preemptible:
247247
description: Preemptible defines if instance is preemptible
248248
type: boolean
249+
provisioningModel:
250+
default: Standard
251+
description: |-
252+
ProvisioningModel defines if instance is spot.
253+
If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible".
254+
If "Spot", VM type is "Spot".
255+
enum:
256+
- Standard
257+
- Spot
258+
type: string
249259
providerID:
250260
description: ProviderID is the unique identifier as specified
251261
by the cloud provider.

docs/book/src/topics/preemptible-vms.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,25 @@ spec:
2828
vmSize: E2
2929
preemptible: true
3030
```
31+
32+
## Spot VMs
33+
[Spot VMs are the latest version of preemptible VMs.](https://cloud.google.com/compute/docs/instances/spot)
34+
35+
To use a Spot VM instead of a Preemptible VM, add `provisioningModel` to `GCPMachineTemplate` and set it to `Spot`.
36+
37+
```yaml
38+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
39+
kind: GCPMachineTemplate
40+
metadata:
41+
name: capg-md-0
42+
spec:
43+
region: us-west-1
44+
template:
45+
osDisk:
46+
diskSizeGB: 30
47+
managedDisk:
48+
storageAccountType: STANDARD
49+
osType: Linux
50+
vmSize: E2
51+
provisioningModel: Spot
52+
```

0 commit comments

Comments
 (0)