From 1506cce65bccc646a6781afbf3d7f8f8119e405b Mon Sep 17 00:00:00 2001 From: Francesco Ciocchetti Date: Mon, 2 Jan 2023 12:51:56 +0100 Subject: [PATCH] better detect when machines in MachinePool VMSS are not running the latest model --- azure/converters/vmss.go | 2 ++ azure/converters/vmss_test.go | 17 ++++++++++------- azure/scope/machinepoolmachine.go | 9 +++++++-- azure/services/scalesets/scalesets_test.go | 18 +++++++++++------- azure/types.go | 13 +++++++------ 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/azure/converters/vmss.go b/azure/converters/vmss.go index 9863e637fca..26d141c458b 100644 --- a/azure/converters/vmss.go +++ b/azure/converters/vmss.go @@ -99,6 +99,8 @@ func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM { instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0] } + instance.LatestModelApplied = *sdkInstance.LatestModelApplied + return &instance } diff --git a/azure/converters/vmss_test.go b/azure/converters/vmss_test.go index b6b52271b70..cfb3f03baf0 100644 --- a/azure/converters/vmss_test.go +++ b/azure/converters/vmss_test.go @@ -63,7 +63,8 @@ func Test_SDKToVMSS(t *testing.T) { Name: to.StringPtr("vm0"), Zones: to.StringSlicePtr([]string{"zone0"}), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + LatestModelApplied: to.BoolPtr(true), OsProfile: &compute.OSProfile{ ComputerName: to.StringPtr("instance-000000"), }, @@ -75,7 +76,8 @@ func Test_SDKToVMSS(t *testing.T) { Name: to.StringPtr("vm1"), Zones: to.StringSlicePtr([]string{"zone1"}), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + ProvisioningState: to.StringPtr(string(compute.ProvisioningState1Succeeded)), + LatestModelApplied: to.BoolPtr(true), OsProfile: &compute.OSProfile{ ComputerName: to.StringPtr("instance-000001"), }, @@ -99,11 +101,12 @@ func Test_SDKToVMSS(t *testing.T) { for i := 0; i < 2; i++ { expected.Instances[i] = azure.VMSSVM{ - ID: fmt.Sprintf("vm/%d", i), - InstanceID: fmt.Sprintf("%d", i), - Name: fmt.Sprintf("instance-00000%d", i), - AvailabilityZone: fmt.Sprintf("zone%d", i), - State: "Succeeded", + ID: fmt.Sprintf("vm/%d", i), + InstanceID: fmt.Sprintf("%d", i), + Name: fmt.Sprintf("instance-00000%d", i), + AvailabilityZone: fmt.Sprintf("zone%d", i), + State: "Succeeded", + LatestModelApplied: true, } } g.Expect(actual).To(gomega.Equal(&expected)) diff --git a/azure/scope/machinepoolmachine.go b/azure/scope/machinepoolmachine.go index 1ffea6c8955..67751c970bd 100644 --- a/azure/scope/machinepoolmachine.go +++ b/azure/scope/machinepoolmachine.go @@ -523,8 +523,13 @@ func (s *MachinePoolMachineScope) hasLatestModelApplied(ctx context.Context) (bo return false, errors.New("machinepoolscope image must not be nil") } - // if the images match, then the VM is of the same model - return reflect.DeepEqual(s.instance.Image, *image), nil + // if the images match, then the VM is of the same model , AND with the value returned by Azure + + var latestModelApplied bool + + latestModelApplied = reflect.DeepEqual(s.instance.Image, *image) && s.instance.LatestModelApplied + + return latestModelApplied, nil } func newWorkloadClusterProxy(c client.Client, cluster client.ObjectKey) *workloadClusterProxy { diff --git a/azure/services/scalesets/scalesets_test.go b/azure/services/scalesets/scalesets_test.go index 6598f3314dc..696b8b754c2 100644 --- a/azure/services/scalesets/scalesets_test.go +++ b/azure/services/scalesets/scalesets_test.go @@ -80,10 +80,11 @@ func TestGetExistingVMSS(t *testing.T) { Zones: []string{"1", "3"}, Instances: []azure.VMSSVM{ { - ID: "my-vm-id", - InstanceID: "my-vm-1", - Name: "instance-000001", - State: "Succeeded", + ID: "my-vm-id", + InstanceID: "my-vm-1", + Name: "instance-000001", + State: "Succeeded", + LatestModelApplied: true, }, }, }, @@ -109,7 +110,8 @@ func TestGetExistingVMSS(t *testing.T) { InstanceID: to.StringPtr("my-vm-1"), Name: to.StringPtr("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: to.StringPtr("Succeeded"), + LatestModelApplied: to.BoolPtr(true), OsProfile: &compute.OSProfile{ ComputerName: to.StringPtr("instance-000001"), }, @@ -1373,7 +1375,8 @@ func newDefaultInstances() []compute.VirtualMachineScaleSetVM { InstanceID: to.StringPtr("my-vm-1"), Name: to.StringPtr("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: to.StringPtr("Succeeded"), + LatestModelApplied: to.BoolPtr(true), OsProfile: &compute.OSProfile{ ComputerName: to.StringPtr("instance-000001"), }, @@ -1392,7 +1395,8 @@ func newDefaultInstances() []compute.VirtualMachineScaleSetVM { InstanceID: to.StringPtr("my-vm-2"), Name: to.StringPtr("my-vm"), VirtualMachineScaleSetVMProperties: &compute.VirtualMachineScaleSetVMProperties{ - ProvisioningState: to.StringPtr("Succeeded"), + ProvisioningState: to.StringPtr("Succeeded"), + LatestModelApplied: to.BoolPtr(true), OsProfile: &compute.OSProfile{ ComputerName: to.StringPtr("instance-000002"), }, diff --git a/azure/types.go b/azure/types.go index 8b6598e73a3..1c1df2a3fd2 100644 --- a/azure/types.go +++ b/azure/types.go @@ -91,12 +91,13 @@ type ExtensionSpec struct { type ( // VMSSVM defines a VM in a virtual machine scale set. VMSSVM struct { - ID string `json:"id,omitempty"` - InstanceID string `json:"instanceID,omitempty"` - Image infrav1.Image `json:"image,omitempty"` - Name string `json:"name,omitempty"` - AvailabilityZone string `json:"availabilityZone,omitempty"` - State infrav1.ProvisioningState `json:"vmState,omitempty"` + ID string `json:"id,omitempty"` + InstanceID string `json:"instanceID,omitempty"` + Image infrav1.Image `json:"image,omitempty"` + Name string `json:"name,omitempty"` + AvailabilityZone string `json:"availabilityZone,omitempty"` + State infrav1.ProvisioningState `json:"vmState,omitempty"` + LatestModelApplied bool `json:"latestModelApplied,omitempty"` } // VMSS defines a virtual machine scale set.