Skip to content

Commit

Permalink
Merge pull request #3201 from helio/fix-nil-pointer
Browse files Browse the repository at this point in the history
fix nil pointer for VMSS boot diagnostics
  • Loading branch information
k8s-ci-robot authored Mar 3, 2023
2 parents 78acabc + 9303173 commit 4ad2d72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion azure/services/scalesets/scalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (s *Service) validateSpec(ctx context.Context) error {
}

// Validate DiagnosticProfile spec
if spec.DiagnosticsProfile.Boot != nil {
if spec.DiagnosticsProfile != nil && spec.DiagnosticsProfile.Boot != nil {
if spec.DiagnosticsProfile.Boot.StorageAccountType == infrav1.UserManagedDiagnosticsStorage {
if spec.DiagnosticsProfile.Boot.UserManaged == nil {
return azure.WithTerminalError(fmt.Errorf("userManaged must be specified when storageAccountType is '%s'", infrav1.UserManagedDiagnosticsStorage))
Expand Down
21 changes: 21 additions & 0 deletions azure/services/scalesets/scalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,27 @@ func TestReconcileVMSS(t *testing.T) {
}}
instances := newDefaultInstances()

setupDefaultVMSSInProgressOperationDoneExpectations(s, m, vmss, instances)
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PutFuture)
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PatchFuture)
s.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, nil)
s.Location().AnyTimes().Return("test-location")
s.HasReplicasExternallyManaged(gomockinternal.AContext()).Return(false)
},
},
{
name: "should not panic when DiagnosticsProfile is nil",
expectedError: "",
expect: func(g *WithT, s *mock_scalesets.MockScaleSetScopeMockRecorder, m *mock_scalesets.MockClientMockRecorder) {
spec := newDefaultVMSSSpec()
spec.DiagnosticsProfile = nil
s.ScaleSetSpec().Return(spec).AnyTimes()

vmss := newDefaultVMSS("VM_SIZE")
vmss.VirtualMachineScaleSetProperties.VirtualMachineProfile.DiagnosticsProfile = nil

instances := newDefaultInstances()

setupDefaultVMSSInProgressOperationDoneExpectations(s, m, vmss, instances)
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PutFuture)
s.DeleteLongRunningOperationState(spec.Name, serviceName, infrav1.PatchFuture)
Expand Down

0 comments on commit 4ad2d72

Please sign in to comment.