From 4a85051b0628c80d37ddd5f87fae6a69c47951e2 Mon Sep 17 00:00:00 2001 From: Nawaz Hussain K Date: Tue, 20 Dec 2022 10:59:13 -0800 Subject: [PATCH] Fix_Bug: validate non nil AzureMachine.Spec.Diagnostic - when upgrading from v1alpha4 -> v1beta1, AzureMachine CRD gets updated upon cluster upgrade. This upgrade updates AzureMachine.Spec.Diagnostics to "Managed", matching the existing behavior as implemented in https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/901 - This PR enables upgrading nil AzureMachine.Spec.Diagnostic to "Managed" and unblocks v1alpha4 -> v1beta1 upgrades. --- api/v1beta1/azuremachine_webhook.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/v1beta1/azuremachine_webhook.go b/api/v1beta1/azuremachine_webhook.go index aa7d29365bb..ba2e1c8c525 100644 --- a/api/v1beta1/azuremachine_webhook.go +++ b/api/v1beta1/azuremachine_webhook.go @@ -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 {