fix empty anannotation which result to null-pointer exception when add overwrite annotation

Signed-off-by: duanmeng <duanmeng_yewu@cmss.chinamobile.com>
This commit is contained in:
duanmeng 2022-05-10 13:28:30 +08:00
parent 4ea28ff236
commit 9ea26cc144
1 changed files with 3 additions and 0 deletions

View File

@ -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)