Skip to content

Commit

Permalink
better detect when machines in MachinePool VMSS are not running the l…
Browse files Browse the repository at this point in the history
…atest model
  • Loading branch information
primeroz committed Jan 2, 2023
1 parent 460f141 commit 1506cce
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
2 changes: 2 additions & 0 deletions azure/converters/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func SDKToVMSSVM(sdkInstance compute.VirtualMachineScaleSetVM) *azure.VMSSVM {
instance.AvailabilityZone = to.StringSlice(sdkInstance.Zones)[0]
}

instance.LatestModelApplied = *sdkInstance.LatestModelApplied

return &instance
}

Expand Down
17 changes: 10 additions & 7 deletions azure/converters/vmss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand All @@ -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"),
},
Expand All @@ -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))
Expand Down
9 changes: 7 additions & 2 deletions azure/scope/machinepoolmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 11 additions & 7 deletions azure/services/scalesets/scalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand All @@ -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"),
},
Expand Down Expand Up @@ -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"),
},
Expand All @@ -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"),
},
Expand Down
13 changes: 7 additions & 6 deletions azure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1506cce

Please sign in to comment.