Skip to content
Merged
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
12 changes: 7 additions & 5 deletions api/v1beta1/azuremachine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ func (m *AzureMachine) ValidateUpdate(oldRaw runtime.Object) error {
allErrs = append(allErrs, err)
}

if err := webhookutils.ValidateImmutable(
field.NewPath("Spec", "Diagnostics"),
old.Spec.Diagnostics,
m.Spec.Diagnostics); err != nil {
allErrs = append(allErrs, err)
if old.Spec.Diagnostics != nil {
if err := webhookutils.ValidateImmutable(
field.NewPath("Spec", "Diagnostics"),
old.Spec.Diagnostics,
m.Spec.Diagnostics); err != nil {
allErrs = append(allErrs, err)
}
}

if len(allErrs) == 0 {
Expand Down
42 changes: 42 additions & 0 deletions api/v1beta1/azuremachine_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,48 @@ func TestAzureMachine_ValidateUpdate(t *testing.T) {
},
wantErr: false,
},
{
name: "validTest: azuremachine.spec.Diagnostics should not error on updating nil diagnostics",
oldMachine: &AzureMachine{
Spec: AzureMachineSpec{},
},
newMachine: &AzureMachine{
Spec: AzureMachineSpec{
Diagnostics: &Diagnostics{Boot: &BootDiagnostics{StorageAccountType: ManagedDiagnosticsStorage}},
},
},
wantErr: false,
},
{
name: "invalidTest: azuremachine.spec.Diagnostics is immutable",
oldMachine: &AzureMachine{
Spec: AzureMachineSpec{
Diagnostics: &Diagnostics{},
},
},
newMachine: &AzureMachine{
Spec: AzureMachineSpec{
Diagnostics: &Diagnostics{Boot: &BootDiagnostics{StorageAccountType: ManagedDiagnosticsStorage}},
},
},
wantErr: true,
},
{
name: "invalidTest: azuremachine.spec.Diagnostics is immutable",
oldMachine: &AzureMachine{
Spec: AzureMachineSpec{
Diagnostics: &Diagnostics{
Boot: &BootDiagnostics{},
},
},
},
newMachine: &AzureMachine{
Spec: AzureMachineSpec{
Diagnostics: &Diagnostics{Boot: &BootDiagnostics{StorageAccountType: ManagedDiagnosticsStorage}},
},
},
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down