diff --git a/api/v1beta1/gcpmachine_types.go b/api/v1beta1/gcpmachine_types.go index 7e27e7845..c501d1faf 100644 --- a/api/v1beta1/gcpmachine_types.go +++ b/api/v1beta1/gcpmachine_types.go @@ -216,6 +216,12 @@ type CustomerEncryptionKey struct { // +optional SuppliedKey *SuppliedKey `json:"suppliedKey,omitempty"` } +type ProvisioningModel string + +const ( + ProvisioningModelStandard ProvisioningModel = "Standard" + ProvisioningModelSpot ProvisioningModel = "Spot" +) // GCPMachineSpec defines the desired state of GCPMachine. type GCPMachineSpec struct { @@ -302,6 +308,14 @@ type GCPMachineSpec struct { // +optional Preemptible bool `json:"preemptible,omitempty"` + // ProvisioningModel defines if instance is spot. + // If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible". + // If "Spot", VM type is "Spot". + // +kubebuilder:validation:Enum=Standard;Spot + // +kubebuilder:default=Standard + // +optional + ProvisioningModel *ProvisioningModel `json:"provisioningModel,omitempty"` + // IPForwarding Allows this instance to send and receive packets with non-matching destination or source IPs. // This is required if you plan to use this instance to forward routes. Defaults to enabled. // +kubebuilder:validation:Enum=Enabled;Disabled diff --git a/cloud/scope/machine.go b/cloud/scope/machine.go index 96f745822..51fad6eff 100644 --- a/cloud/scope/machine.go +++ b/cloud/scope/machine.go @@ -402,6 +402,9 @@ func (m *MachineScope) InstanceSpec(log logr.Logger) *compute.Instance { Preemptible: m.GCPMachine.Spec.Preemptible, }, } + if m.GCPMachine.Spec.ProvisioningModel != nil && *m.GCPMachine.Spec.ProvisioningModel == infrav1.ProvisioningModelSpot { + instance.Scheduling.ProvisioningModel = "SPOT" + } instance.CanIpForward = true if m.GCPMachine.Spec.IPForwarding != nil && *m.GCPMachine.Spec.IPForwarding == infrav1.IPForwardingDisabled { diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml index 24955802d..a070ad5ca 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachines.yaml @@ -231,6 +231,16 @@ spec: preemptible: description: Preemptible defines if instance is preemptible type: boolean + provisioningModel: + default: Standard + description: |- + ProvisioningModel defines if instance is spot. + If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible". + If "Spot", VM type is "Spot". + enum: + - Standard + - Spot + type: string providerID: description: ProviderID is the unique identifier as specified by the cloud provider. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml index 5cc470597..d78d196c1 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmachinetemplates.yaml @@ -246,6 +246,16 @@ spec: preemptible: description: Preemptible defines if instance is preemptible type: boolean + provisioningModel: + default: Standard + description: |- + ProvisioningModel defines if instance is spot. + If set to "Standard" while preemptible is true, then the VM will be of type "Preemptible". + If "Spot", VM type is "Spot". + enum: + - Standard + - Spot + type: string providerID: description: ProviderID is the unique identifier as specified by the cloud provider. diff --git a/docs/book/src/topics/preemptible-vms.md b/docs/book/src/topics/preemptible-vms.md index b0e9636d9..ade417896 100644 --- a/docs/book/src/topics/preemptible-vms.md +++ b/docs/book/src/topics/preemptible-vms.md @@ -28,3 +28,25 @@ spec: vmSize: E2 preemptible: true ``` + +## Spot VMs +[Spot VMs are the latest version of preemptible VMs.](https://cloud.google.com/compute/docs/instances/spot) + +To use a Spot VM instead of a Preemptible VM, add `provisioningModel` to `GCPMachineTemplate` and set it to `Spot`. + +```yaml +apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 +kind: GCPMachineTemplate +metadata: + name: capg-md-0 +spec: + region: us-west-1 + template: + osDisk: + diskSizeGB: 30 + managedDisk: + storageAccountType: STANDARD + osType: Linux + vmSize: E2 + provisioningModel: Spot +```