Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Detect when Machines in MachinePool VMSS are not running on the latest model #2975

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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