From 9ea26cc144590913c99d4e1ebc1ea1872e6bede5 Mon Sep 17 00:00:00 2001 From: duanmeng Date: Tue, 10 May 2022 13:28:30 +0800 Subject: [PATCH] fix empty anannotation which result to null-pointer exception when add overwrite annotation Signed-off-by: duanmeng --- pkg/karmadactl/promote.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/karmadactl/promote.go b/pkg/karmadactl/promote.go index 8f037c3f6..f2d2c37c8 100644 --- a/pkg/karmadactl/promote.go +++ b/pkg/karmadactl/promote.go @@ -379,6 +379,9 @@ func preprocessResource(obj *unstructured.Unstructured) error { // addOverwriteAnnotation add annotation "work.karmada.io/conflict-resolution" to the resource func addOverwriteAnnotation(obj *unstructured.Unstructured) { annotations := obj.DeepCopy().GetAnnotations() + if annotations == nil { + annotations = map[string]string{} + } if _, exist := annotations[workv1alpha2.ResourceConflictResolutionAnnotation]; !exist { annotations[workv1alpha2.ResourceConflictResolutionAnnotation] = workv1alpha2.ResourceConflictResolutionOverwrite obj.SetAnnotations(annotations)