Skip to content

Commit

Permalink
Allow setting ScaleDownMode and SpotMaxPrice for AzureManagedMachinePool
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Jun 27, 2023
1 parent 8e1c9ae commit d9ea584
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/v1beta1/azuremanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions azure/converters/managedagentpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions azure/scope/managedmachinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions azure/services/agentpools/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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,
},
}
Expand All @@ -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),
},
}
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions azure/services/agentpools/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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''
Expand All @@ -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.
Expand Down

0 comments on commit d9ea584

Please sign in to comment.