Skip to content

Commit

Permalink
Merge pull request #2961 from nawazkh/fix_upgrade_errors_diagonostics
Browse files Browse the repository at this point in the history
Bug_fix: validate non-nil AzureMachine.Spec.Diagnostic when upgrading to v1beta1
  • Loading branch information
k8s-ci-robot authored Dec 22, 2022
2 parents 9a6d89a + d92ea9a commit 27ff8d7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
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

0 comments on commit 27ff8d7

Please sign in to comment.