diff --git a/api/v1beta1/azuremanagedmachinepool_types.go b/api/v1beta1/azuremanagedmachinepool_types.go index 48e9499ebc7..0af7c61c304 100644 --- a/api/v1beta1/azuremanagedmachinepool_types.go +++ b/api/v1beta1/azuremanagedmachinepool_types.go @@ -520,6 +520,17 @@ type AzureManagedMachinePoolSpec struct { // +optional ScaleSetPriority *string `json:"scaleSetPriority,omitempty"` + // ScaleDownMode affects the cluster autoscaler behavior. Default to Delete. Possible values include: 'Deallocate', 'Delete' + // +kubebuilder:validation:Enum=Deallocate;Delete + // +kubebuilder:default=Delete + // +optional + ScaleDownMode *string `json:"scaleDownMode,omitempty"` + + // SpotMaxPrice defines max price to pay for spot instance. + // Possible values are any decimal value greater than zero or -1 which indicates the willingness to pay any on-demand price. + // +optional + SpotMaxPrice *float64 `json:"spotMaxPrice,omitempty"` + // KubeletConfig specifies the kubelet configurations for nodes. // Immutable. // +optional diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index b7437e6aefb..a0c972fdfc8 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -1402,6 +1402,16 @@ func (in *AzureManagedMachinePoolSpec) DeepCopyInto(out *AzureManagedMachinePool *out = new(string) **out = **in } + if in.ScaleDownMode != nil { + in, out := &in.ScaleDownMode, &out.ScaleDownMode + *out = new(string) + **out = **in + } + if in.SpotMaxPrice != nil { + in, out := &in.SpotMaxPrice, &out.SpotMaxPrice + *out = new(float64) + **out = **in + } if in.KubeletConfig != nil { in, out := &in.KubeletConfig, &out.KubeletConfig *out = new(KubeletConfig) diff --git a/azure/converters/managedagentpool.go b/azure/converters/managedagentpool.go index 300f66ab131..b9513c82484 100644 --- a/azure/converters/managedagentpool.go +++ b/azure/converters/managedagentpool.go @@ -45,6 +45,8 @@ func AgentPoolToManagedClusterAgentPoolProfile(pool containerservice.AgentPool) EnableNodePublicIP: properties.EnableNodePublicIP, NodePublicIPPrefixID: properties.NodePublicIPPrefixID, ScaleSetPriority: properties.ScaleSetPriority, + ScaleDownMode: properties.ScaleDownMode, + SpotMaxPrice: properties.SpotMaxPrice, Tags: properties.Tags, KubeletDiskType: properties.KubeletDiskType, LinuxOSConfig: properties.LinuxOSConfig, diff --git a/azure/scope/managedmachinepool.go b/azure/scope/managedmachinepool.go index 9e4b6cc5cb5..a09cba4a8a7 100644 --- a/azure/scope/managedmachinepool.go +++ b/azure/scope/managedmachinepool.go @@ -189,6 +189,8 @@ func buildAgentPoolSpec(managedControlPlane *infrav1.AzureManagedControlPlane, EnableNodePublicIP: managedMachinePool.Spec.EnableNodePublicIP, NodePublicIPPrefixID: managedMachinePool.Spec.NodePublicIPPrefixID, ScaleSetPriority: managedMachinePool.Spec.ScaleSetPriority, + ScaleDownMode: managedMachinePool.Spec.ScaleDownMode, + SpotMaxPrice: managedMachinePool.Spec.SpotMaxPrice, AdditionalTags: managedMachinePool.Spec.AdditionalTags, KubeletDiskType: managedMachinePool.Spec.KubeletDiskType, LinuxOSConfig: managedMachinePool.Spec.LinuxOSConfig, diff --git a/azure/services/agentpools/spec.go b/azure/services/agentpools/spec.go index 8dc27b05e0e..88903d3b7d7 100644 --- a/azure/services/agentpools/spec.go +++ b/azure/services/agentpools/spec.go @@ -129,6 +129,12 @@ type AgentPoolSpec struct { // ScaleSetPriority specifies the ScaleSetPriority for the node pool. Allowed values are 'Spot' and 'Regular' ScaleSetPriority *string `json:"scaleSetPriority,omitempty"` + // ScaleDownMode affects the cluster autoscaler behavior. Allowed values are 'Deallocate' and 'Delete' + ScaleDownMode *string `json:"scaleDownMode,omitempty"` + + // SpotMaxPrice defines max price to pay for spot instance. Allowed values are any decimal value greater than zero or -1 which indicates the willingness to pay any on-demand price. + SpotMaxPrice *float64 `json:"spotMaxPrice,omitempty"` + // KubeletConfig specifies the kubelet configurations for nodes. KubeletConfig *KubeletConfig `json:"kubeletConfig,omitempty"` @@ -193,6 +199,8 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p NodeLabels: existingPool.NodeLabels, NodeTaints: existingPool.NodeTaints, Tags: existingPool.Tags, + ScaleDownMode: existingPool.ScaleDownMode, + SpotMaxPrice: existingPool.SpotMaxPrice, KubeletConfig: existingPool.KubeletConfig, }, } @@ -207,6 +215,8 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p MaxCount: s.MaxCount, NodeLabels: s.NodeLabels, NodeTaints: &s.NodeTaints, + ScaleDownMode: containerservice.ScaleDownMode(pointer.StringDeref(s.ScaleDownMode, "")), + SpotMaxPrice: s.SpotMaxPrice, Tags: converters.TagsToMap(s.AdditionalTags), }, } @@ -354,6 +364,8 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p OsDiskType: containerservice.OSDiskType(pointer.StringDeref(s.OsDiskType, "")), OsType: containerservice.OSType(pointer.StringDeref(s.OSType, "")), ScaleSetPriority: containerservice.ScaleSetPriority(pointer.StringDeref(s.ScaleSetPriority, "")), + ScaleDownMode: containerservice.ScaleDownMode(pointer.StringDeref(s.ScaleDownMode, "")), + SpotMaxPrice: s.SpotMaxPrice, Type: containerservice.AgentPoolTypeVirtualMachineScaleSets, VMSize: sku, VnetSubnetID: vnetSubnetID, diff --git a/azure/services/agentpools/spec_test.go b/azure/services/agentpools/spec_test.go index 32501efdd60..9eb26700e24 100644 --- a/azure/services/agentpools/spec_test.go +++ b/azure/services/agentpools/spec_test.go @@ -114,6 +114,18 @@ func sdkWithAutoscaling(enableAutoscaling bool) func(*containerservice.AgentPool } } +func sdkWithScaleDownMode(scaleDownMode containerservice.ScaleDownMode) func(*containerservice.AgentPool) { + return func(pool *containerservice.AgentPool) { + pool.ManagedClusterAgentPoolProfileProperties.ScaleDownMode = scaleDownMode + } +} + +func sdkWithSpotMaxPrice(spotMaxPrice float64) func(*containerservice.AgentPool) { + return func(pool *containerservice.AgentPool) { + pool.ManagedClusterAgentPoolProfileProperties.SpotMaxPrice = &spotMaxPrice + } +} + func sdkWithCount(count int32) func(*containerservice.AgentPool) { return func(pool *containerservice.AgentPool) { pool.ManagedClusterAgentPoolProfileProperties.Count = pointer.Int32(count) @@ -215,6 +227,26 @@ func TestParameters(t *testing.T) { expected: sdkFakeAgentPool(), expectedError: nil, }, + { + name: "parameters with an existing agent pool and update needed on scale down mode", + spec: fakeAgentPool(), + existing: sdkFakeAgentPool( + sdkWithScaleDownMode(containerservice.ScaleDownModeDeallocate), + sdkWithProvisioningState("Succeeded"), + ), + expected: sdkFakeAgentPool(), + expectedError: nil, + }, + { + name: "parameters with an existing agent pool and update needed on spot max price", + spec: fakeAgentPool(), + existing: sdkFakeAgentPool( + sdkWithSpotMaxPrice(120), + sdkWithProvisioningState("Succeeded"), + ), + expected: sdkFakeAgentPool(), + expectedError: nil, + }, { name: "parameters with an existing agent pool and update needed on max count", spec: fakeAgentPool(), diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedmachinepools.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedmachinepools.yaml index cac7edf571c..88fd25a11ce 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedmachinepools.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azuremanagedmachinepools.yaml @@ -495,6 +495,14 @@ spec: items: type: string type: array + scaleDownMode: + default: Delete + description: 'ScaleDownMode affects the cluster autoscaler behavior. + Default to Delete. Possible values include: ''Deallocate'', ''Delete''' + enum: + - Deallocate + - Delete + type: string scaleSetPriority: description: 'ScaleSetPriority specifies the ScaleSetPriority value. Default to Regular. Possible values include: ''Regular'', ''Spot'' @@ -519,6 +527,10 @@ spec: sku: description: SKU is the size of the VMs in the node pool. Immutable. type: string + spotMaxPrice: + description: SpotMaxPrice defines max price to pay for spot instance. + Possible values are any decimal value greater than zero or -1 which + indicates the willingness to pay any on-demand price. subnetName: description: SubnetName specifies the Subnet where the MachinePool will be placed Immutable.