Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Jul 6, 2023
1 parent d9ea584 commit e7cc501
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion api/v1beta1/azuremanagedmachinepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
capierrors "sigs.k8s.io/cluster-api/errors"
Expand Down Expand Up @@ -529,7 +530,7 @@ type AzureManagedMachinePoolSpec struct {
// 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"`
SpotMaxPrice *resource.Quantity `json:"spotMaxPrice,omitempty"`

// KubeletConfig specifies the kubelet configurations for nodes.
// Immutable.
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

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

13 changes: 10 additions & 3 deletions azure/services/agentpools/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package agentpools
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/resource"
"time"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2022-03-01/containerservice"
Expand Down Expand Up @@ -133,7 +134,7 @@ type AgentPoolSpec struct {
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"`
SpotMaxPrice *resource.Quantity `json:"spotMaxPrice,omitempty"`

// KubeletConfig specifies the kubelet configurations for nodes.
KubeletConfig *KubeletConfig `json:"kubeletConfig,omitempty"`
Expand Down Expand Up @@ -216,14 +217,17 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p
NodeLabels: s.NodeLabels,
NodeTaints: &s.NodeTaints,
ScaleDownMode: containerservice.ScaleDownMode(pointer.StringDeref(s.ScaleDownMode, "")),
SpotMaxPrice: s.SpotMaxPrice,
Tags: converters.TagsToMap(s.AdditionalTags),
},
}
if len(*normalizedProfile.NodeTaints) == 0 {
normalizedProfile.NodeTaints = nil
}

if s.SpotMaxPrice != nil {
normalizedProfile.SpotMaxPrice = pointer.Float64(s.SpotMaxPrice.AsApproximateFloat64())
}

if s.KubeletConfig != nil {
normalizedProfile.KubeletConfig = &containerservice.KubeletConfig{
CPUManagerPolicy: s.KubeletConfig.CPUManagerPolicy,
Expand Down Expand Up @@ -365,7 +369,6 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p
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 All @@ -376,6 +379,10 @@ func (s *AgentPoolSpec) Parameters(ctx context.Context, existing interface{}) (p
},
}

if s.SpotMaxPrice != nil {
agentPool.SpotMaxPrice = pointer.Float64(s.SpotMaxPrice.AsApproximateFloat64())
}

return agentPool, nil
}

Expand Down
23 changes: 22 additions & 1 deletion azure/services/agentpools/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package agentpools

import (
"context"
"k8s.io/apimachinery/pkg/api/resource"
"reflect"
"testing"
"time"
Expand Down Expand Up @@ -76,6 +77,13 @@ func withAutoscaling(enabled bool) func(*AgentPoolSpec) {
}
}

func withSpotMaxPrice(spotMaxPrice string) func(*AgentPoolSpec) {
quantity := resource.MustParse(spotMaxPrice)
return func(pool *AgentPoolSpec) {
pool.SpotMaxPrice = &quantity
}
}

func sdkFakeAgentPool(changes ...func(*containerservice.AgentPool)) containerservice.AgentPool {
pool := containerservice.AgentPool{
ManagedClusterAgentPoolProfileProperties: &containerservice.ManagedClusterAgentPoolProfileProperties{
Expand Down Expand Up @@ -241,12 +249,25 @@ func TestParameters(t *testing.T) {
name: "parameters with an existing agent pool and update needed on spot max price",
spec: fakeAgentPool(),
existing: sdkFakeAgentPool(
sdkWithSpotMaxPrice(120),
sdkWithSpotMaxPrice(123.456),
sdkWithProvisioningState("Succeeded"),
),
expected: sdkFakeAgentPool(),
expectedError: nil,
},
{
name: "parameters with an existing agent pool and update needed on spot max price",
spec: fakeAgentPool(
withSpotMaxPrice("789.123"),
),
existing: sdkFakeAgentPool(
sdkWithProvisioningState("Succeeded"),
),
expected: sdkFakeAgentPool(
sdkWithSpotMaxPrice(789.123),
),
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 @@ -528,9 +528,14 @@ spec:
description: SKU is the size of the VMs in the node pool. Immutable.
type: string
spotMaxPrice:
anyOf:
- type: integer
- type: string
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.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
subnetName:
description: SubnetName specifies the Subnet where the MachinePool
will be placed Immutable.
Expand Down

0 comments on commit e7cc501

Please sign in to comment.