Merge pull request #1759 from duanmengkk/master

fixed a panic which due to nil annotation during promote resources to Karmada
This commit is contained in:
karmada-bot 2022-05-11 16:50:31 +08:00 committed by GitHub
commit da78076e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -378,6 +378,9 @@ func preprocessResource(obj *unstructured.Unstructured) error {
// addOverwriteAnnotation add annotation "work.karmada.io/conflict-resolution" to the resource // addOverwriteAnnotation add annotation "work.karmada.io/conflict-resolution" to the resource
func addOverwriteAnnotation(obj *unstructured.Unstructured) { func addOverwriteAnnotation(obj *unstructured.Unstructured) {
annotations := obj.DeepCopy().GetAnnotations() annotations := obj.DeepCopy().GetAnnotations()
if annotations == nil {
annotations = map[string]string{}
}
if _, exist := annotations[workv1alpha2.ResourceConflictResolutionAnnotation]; !exist { if _, exist := annotations[workv1alpha2.ResourceConflictResolutionAnnotation]; !exist {
annotations[workv1alpha2.ResourceConflictResolutionAnnotation] = workv1alpha2.ResourceConflictResolutionOverwrite annotations[workv1alpha2.ResourceConflictResolutionAnnotation] = workv1alpha2.ResourceConflictResolutionOverwrite
obj.SetAnnotations(annotations) obj.SetAnnotations(annotations)