Skip to content

Commit 4ad2d72

Browse files
authored
Merge pull request #3201 from helio/fix-nil-pointer
fix nil pointer for VMSS boot diagnostics
2 parents 78acabc + 9303173 commit 4ad2d72

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

azure/services/scalesets/scalesets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func (s *Service) validateSpec(ctx context.Context) error {
401401
}
402402

403403
// Validate DiagnosticProfile spec
404-
if spec.DiagnosticsProfile.Boot != nil {
404+
if spec.DiagnosticsProfile != nil && spec.DiagnosticsProfile.Boot != nil {
405405
if spec.DiagnosticsProfile.Boot.StorageAccountType == infrav1.UserManagedDiagnosticsStorage {
406406
if spec.DiagnosticsProfile.Boot.UserManaged == nil {
407407
return azure.WithTerminalError(fmt.Errorf("userManaged must be specified when storageAccountType is '%s'", infrav1.UserManagedDiagnosticsStorage))

azure/services/scalesets/scalesets_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,27 @@ func TestReconcileVMSS(t *testing.T) {
792792
}}
793793
instances := newDefaultInstances()
794794

795+
setupDefaultVMSSInProgressOperationDoneExpectations(s, m, vmss, instances)
796+
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PutFuture)
797+
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PatchFuture)
798+
s.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, nil)
799+
s.Location().AnyTimes().Return("test-location")
800+
s.HasReplicasExternallyManaged(gomockinternal.AContext()).Return(false)
801+
},
802+
},
803+
{
804+
name: "should not panic when DiagnosticsProfile is nil",
805+
expectedError: "",
806+
expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder) {
807+
spec := newDefaultVMSSSpec()
808+
spec.DiagnosticsProfile = nil
809+
s.ScaleSetSpec().Return(spec).AnyTimes()
810+
811+
vmss := newDefaultVMSS("VM_SIZE")
812+
vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.DiagnosticsProfile = nil
813+
814+
instances := newDefaultInstances()
815+
795816
setupDefaultVMSSInProgressOperationDoneExpectations(s, m, vmss, instances)
796817
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PutFuture)
797818
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PatchFuture)

0 commit comments

Comments
 (0)