Skip to content

Commit

Permalink
default spec.spotMaxPrice in AzureManagedMachinePool
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Oct 13, 2023
1 parent 30d08b2 commit 389acba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/azuremanagedmachinepool_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -80,6 +81,10 @@ func (mw *azureManagedMachinePoolWebhook) Default(ctx context.Context, obj runti
m.Spec.OSType = ptr.To(DefaultOSType)
}

if ptr.Deref(m.Spec.ScaleSetPriority, "") == "Spot" && m.Spec.SpotMaxPrice == nil {
m.Spec.SpotMaxPrice = ptr.To(resource.MustParse("-1"))
}

return nil
}

Expand Down
14 changes: 14 additions & 0 deletions api/v1beta1/azuremanagedmachinepool_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v4"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/component-base/featuregate/testing"
Expand Down Expand Up @@ -59,6 +60,7 @@ func TestAzureManagedMachinePoolDefaultingWebhook(t *testing.T) {
g.Expect(val).To(Equal("System"))
g.Expect(*ammp.Spec.Name).To(Equal("fooname"))
g.Expect(*ammp.Spec.OSType).To(Equal(LinuxOS))
g.Expect(ammp.Spec.SpotMaxPrice).To(BeNil())

t.Logf("Testing ammp defaulting webhook with empty string name specified in Spec")
emptyName := ""
Expand All @@ -80,6 +82,18 @@ func TestAzureManagedMachinePoolDefaultingWebhook(t *testing.T) {
err = mw.Default(context.Background(), ammp)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(*ammp.Spec.OsDiskType).To(Equal("Ephemeral"))

t.Logf("Testing ammp defaulting webhook with scaleSetPriority Spot")
ammp.Spec.ScaleSetPriority = ptr.To("Spot")
err = mw.Default(context.Background(), ammp)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ammp.Spec.SpotMaxPrice.Equal(resource.MustParse("-1"))).To(BeTrue())

t.Logf("Testing ammp defaulting webhook with scaleSetPriority Spot with max price set")
ammp.Spec.SpotMaxPrice = ptr.To(resource.MustParse("100"))
err = mw.Default(context.Background(), ammp)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ammp.Spec.SpotMaxPrice.Equal(resource.MustParse("100"))).To(BeTrue())
}

func TestAzureManagedMachinePoolUpdatingWebhook(t *testing.T) {
Expand Down

0 comments on commit 389acba

Please sign in to comment.