From 36738cd8bc99a39149db514ea95f1e317d119546 Mon Sep 17 00:00:00 2001 From: xing-yang Date: Fri, 9 Feb 2024 12:53:14 -0500 Subject: [PATCH] Add nil check for SourceVolumeMode in the ValidationWebHook --- pkg/validation-webhook/snapshot.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/validation-webhook/snapshot.go b/pkg/validation-webhook/snapshot.go index c79f49514..d0fb2a8f5 100644 --- a/pkg/validation-webhook/snapshot.go +++ b/pkg/validation-webhook/snapshot.go @@ -246,8 +246,12 @@ func checkSnapshotContentImmutableFieldsV1(snapcontent, oldSnapcontent *volumesn } if preventVolumeModeConversion { - if !reflect.DeepEqual(snapcontent.Spec.SourceVolumeMode, oldSnapcontent.Spec.SourceVolumeMode) { + if oldSnapcontent.Spec.SourceVolumeMode != nil && snapcontent.Spec.SourceVolumeMode != nil && !reflect.DeepEqual(snapcontent.Spec.SourceVolumeMode, oldSnapcontent.Spec.SourceVolumeMode) { return fmt.Errorf("Spec.SourceVolumeMode is immutable but was changed from %v to %v", *oldSnapcontent.Spec.SourceVolumeMode, *snapcontent.Spec.SourceVolumeMode) + } else if oldSnapcontent.Spec.SourceVolumeMode == nil && snapcontent.Spec.SourceVolumeMode != nil { + return fmt.Errorf("Spec.SourceVolumeMode is immutable but was changed from nil to %v", *snapcontent.Spec.SourceVolumeMode) + } else if oldSnapcontent.Spec.SourceVolumeMode != nil && snapcontent.Spec.SourceVolumeMode == nil { + return fmt.Errorf("Spec.SourceVolumeMode is immutable but was changed from %v to nil", *oldSnapcontent.Spec.SourceVolumeMode) } }