Skip to content

Commit f96fba5

Browse files
committed
add az machine pool rolling upgrades with maxsurge, maxunavailable, and deletepolicy
1 parent 7369ccc commit f96fba5

File tree

67 files changed

+6226
-1017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+6226
-1017
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,5 +587,5 @@ verify-modules: modules
587587
.PHONY: verify-gen
588588
verify-gen: generate
589589
@if !(git diff --quiet HEAD); then \
590-
echo "generated files are out of date, run make generate"; exit 1; \
590+
git diff; echo "generated files are out of date, run make generate"; exit 1; \
591591
fi

api/v1alpha4/conditions_consts.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,16 @@ const (
6262
ScaleSetDeletingReason = "ScaleSetDeleting"
6363
// ScaleSetProvisionFailedReason used for failures during scale set provisioning.
6464
ScaleSetProvisionFailedReason = "ScaleSetProvisionFailed"
65+
66+
// ScaleSetDesiredReplicasCondition reports on the scaling state of the machine pool
67+
ScaleSetDesiredReplicasCondition clusterv1.ConditionType = "ScaleSetDesiredReplicas"
68+
// ScaleSetScaleUpReason describes the machine pool scaling up
69+
ScaleSetScaleUpReason = "ScaleSetScalingUp"
70+
// ScaleSetScaleDownReason describes the machine pool scaling down
71+
ScaleSetScaleDownReason = "ScaleSetScalingDown"
72+
73+
// ScaleSetModelUpdatedCondition reports on the model state of the pool
74+
ScaleSetModelUpdatedCondition clusterv1.ConditionType = "ScaleSetModelUpdated"
75+
// ScaleSetModelOutOfDateReason describes the machine pool model being out of date
76+
ScaleSetModelOutOfDateReason = "ScaleSetModelOutOfDate"
6577
)

api/v1alpha4/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,8 @@ type AzureBastion struct {
600600
// +optional
601601
PublicIP PublicIPSpec `json:"publicIP,omitempty"`
602602
}
603+
604+
// IsTerminalProvisioningState returns true if the ProvisioningState is a terminal state for an Azure resource
605+
func IsTerminalProvisioningState(state ProvisioningState) bool {
606+
return state == Failed || state == Succeeded
607+
}

azure/converters/vmss.go

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ package converters
1919
import (
2020
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-30/compute"
2121
"github.com/Azure/go-autorest/autorest/to"
22-
2322
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4"
24-
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha4"
23+
"sigs.k8s.io/cluster-api-provider-azure/azure"
2524
)
2625

2726
// SDKToVMSS converts an Azure SDK VirtualMachineScaleSet to the AzureMachinePool type.
28-
func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.VirtualMachineScaleSetVM) *infrav1exp.VMSS {
29-
vmss := &infrav1exp.VMSS{
27+
func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.VirtualMachineScaleSetVM) *azure.VMSS {
28+
vmss := &azure.VMSS{
3029
ID: to.String(sdkvmss.ID),
3130
Name: to.String(sdkvmss.Name),
3231
State: infrav1.ProvisioningState(to.String(sdkvmss.ProvisioningState)),
@@ -46,25 +45,66 @@ func SDKToVMSS(sdkvmss compute.VirtualMachineScaleSet, sdkinstances []compute.Vi
4645
}
4746

4847
if len(sdkinstances) > 0 {
49-
vmss.Instances = make([]infrav1exp.VMSSVM, len(sdkinstances))
48+
vmss.Instances = make([]azure.VMSSVM, len(sdkinstances))
5049
for i, vm := range sdkinstances {
51-
instance := infrav1exp.VMSSVM{
52-
ID: to.String(vm.ID),
53-
InstanceID: to.String(vm.InstanceID),
54-
Name: to.String(vm.OsProfile.ComputerName),
55-
State: infrav1.ProvisioningState(to.String(vm.ProvisioningState)),
56-
}
57-
58-
if vm.LatestModelApplied != nil {
59-
instance.LatestModelApplied = *vm.LatestModelApplied
60-
}
61-
62-
if vm.Zones != nil && len(*vm.Zones) > 0 {
63-
instance.AvailabilityZone = to.StringSlice(vm.Zones)[0]
64-
}
65-
vmss.Instances[i] = instance
50+
vmss.Instances[i] = *SDKToVMSSVM(vm)
6651
}
6752
}
6853

54+
if sdkvmss.VirtualMachineProfile != nil &&
55+
sdkvmss.VirtualMachineProfile.StorageProfile != nil &&
56+
sdkvmss.VirtualMachineProfile.StorageProfile.ImageReference != nil {
57+
58+
imageRef := sdkvmss.VirtualMachineProfile.StorageProfile.ImageReference
59+
vmss.Image = SDKImageToImage(imageRef, sdkvmss.Plan != nil)
60+
}
61+
6962
return vmss
7063
}
64+
65+
// SDKToVMSSVM converts an Azure SDK VirtualMachineScaleSetVM into an infrav1exp.VMSSVM
66+
func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM {
67+
instance := azure.VMSSVM{
68+
ID: to.String(sdkInstance.ID),
69+
InstanceID: to.String(sdkInstance.InstanceID),
70+
}
71+
72+
if sdkInstance.VirtualMachineScaleSetVMProperties == nil {
73+
return &instance
74+
}
75+
76+
instance.State = infrav1.Creating
77+
if sdkInstance.ProvisioningState != nil {
78+
instance.State = infrav1.ProvisioningState(to.String(sdkInstance.ProvisioningState))
79+
}
80+
81+
if sdkInstance.OsProfile != nil && sdkInstance.OsProfile.ComputerName != nil {
82+
instance.Name = *sdkInstance.OsProfile.ComputerName
83+
}
84+
85+
if sdkInstance.StorageProfile != nil && sdkInstance.StorageProfile.ImageReference != nil {
86+
imageRef := sdkInstance.StorageProfile.ImageReference
87+
instance.Image = SDKImageToImage(imageRef, sdkInstance.Plan != nil)
88+
}
89+
90+
if sdkInstance.Zones != nil && len(*sdkInstance.Zones) > 0 {
91+
// an instance should only have 1 zone, so we select the first item of the slice
92+
instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0]
93+
}
94+
95+
return &instance
96+
}
97+
98+
// SDKImageToImage converts a SDK image reference to infrav1.Image
99+
func SDKImageToImage(sdkImageRef *compute.ImageReference, isThirdPartyImage bool) infrav1.Image {
100+
return infrav1.Image{
101+
ID: sdkImageRef.ID,
102+
Marketplace: &infrav1.AzureMarketplaceImage{
103+
Publisher: to.String(sdkImageRef.Publisher),
104+
Offer: to.String(sdkImageRef.Offer),
105+
SKU: to.String(sdkImageRef.Sku),
106+
Version: to.String(sdkImageRef.Version),
107+
ThirdPartyImage: isThirdPartyImage,
108+
},
109+
}
110+
}

azure/converters/vmss_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ import (
2323
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2020-06-30/compute"
2424
"github.com/Azure/go-autorest/autorest/to"
2525
"github.com/onsi/gomega"
26-
26+
"sigs.k8s.io/cluster-api-provider-azure/azure"
2727
"sigs.k8s.io/cluster-api-provider-azure/azure/converters"
28-
infrav1exp "sigs.k8s.io/cluster-api-provider-azure/exp/api/v1alpha4"
2928
)
3029

3130
func Test_SDKToVMSS(t *testing.T) {
3231
cases := []struct {
3332
Name string
3433
SubjectFactory func(*gomega.GomegaWithT) (compute.VirtualMachineScaleSet, []compute.VirtualMachineScaleSetVM)
35-
Expect func(*gomega.GomegaWithT, *infrav1exp.VMSS)
34+
Expect func(*gomega.GomegaWithT, *azure.VMSS)
3635
}{
3736
{
3837
Name: "ShouldPopulateWithData",
@@ -83,8 +82,8 @@ func Test_SDKToVMSS(t *testing.T) {
8382
},
8483
}
8584
},
86-
Expect: func(g *gomega.GomegaWithT, actual *infrav1exp.VMSS) {
87-
expected := infrav1exp.VMSS{
85+
Expect: func(g *gomega.GomegaWithT, actual *azure.VMSS) {
86+
expected := azure.VMSS{
8887
ID: "vmssID",
8988
Name: "vmssName",
9089
Sku: "skuName",
@@ -94,11 +93,11 @@ func Test_SDKToVMSS(t *testing.T) {
9493
Tags: map[string]string{
9594
"foo": "bazz",
9695
},
97-
Instances: make([]infrav1exp.VMSSVM, 2),
96+
Instances: make([]azure.VMSSVM, 2),
9897
}
9998

10099
for i := 0; i < 2; i++ {
101-
expected.Instances[i] = infrav1exp.VMSSVM{
100+
expected.Instances[i] = azure.VMSSVM{
102101
ID: fmt.Sprintf("vm/%d", i),
103102
InstanceID: fmt.Sprintf("%d", i),
104103
Name: fmt.Sprintf("instance-00000%d", i),

azure/errors.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ func (t ReconcileError) IsTerminal() bool {
109109
return t.errorType == TerminalErrorType
110110
}
111111

112+
// Is returns true if the target is a ReconcileError
113+
func (t ReconcileError) Is(target error) bool {
114+
return errors.As(target, &ReconcileError{})
115+
}
116+
112117
// RequeueAfter returns requestAfter value
113118
func (t ReconcileError) RequeueAfter() time.Duration {
114119
return t.requestAfter

azure/scope/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (m *MachineScope) Role() string {
295295
return infrav1.Node
296296
}
297297

298-
// GetVMID returns the AzureMachine instance id by parsing Spec.ProviderID.
298+
// GetVMID returns the AzureMachine instance id by parsing Spec.FakeProviderID.
299299
func (m *MachineScope) GetVMID() string {
300300
parsed, err := noderefutil.NewProviderID(m.ProviderID())
301301
if err != nil {

0 commit comments

Comments
 (0)