@@ -244,6 +244,14 @@ func (ib *itemBackupper) backupItemInternal(logger logrus.FieldLogger, obj runti
244244 return false , itemFiles , kubeerrs .NewAggregate (backupErrs )
245245 }
246246
247+ // If err is nil and updatedObj is nil, it means the item is skipped by plugin action,
248+ // we should return here to avoid backing up the item, and avoid potential NPE in the following code.
249+ if updatedObj == nil {
250+ log .Infof ("Remove item from the backup's backupItems list and totalItems list because it's skipped by plugin action." )
251+ ib .backupRequest .BackedUpItems .DeleteItem (key )
252+ return false , itemFiles , nil
253+ }
254+
247255 itemFiles = append (itemFiles , additionalItemFiles ... )
248256 obj = updatedObj
249257 if metadata , err = meta .Accessor (obj ); err != nil {
@@ -398,6 +406,13 @@ func (ib *itemBackupper) executeActions(
398406 }
399407
400408 u := & unstructured.Unstructured {Object : updatedItem .UnstructuredContent ()}
409+
410+ if _ , ok := u .GetAnnotations ()[velerov1api .SkipFromBackupAnnotation ]; ok {
411+ log .Infof ("Resource (groupResource=%s, namespace=%s, name=%s) is skipped from backup by action %s." ,
412+ groupResource .String (), namespace , name , actionName )
413+ return nil , itemFiles , nil
414+ }
415+
401416 if actionName == csiBIAPluginName {
402417 if additionalItemIdentifiers == nil && u .GetAnnotations ()[velerov1api .SkippedNoCSIPVAnnotation ] == "true" {
403418 // snapshot was skipped by CSI plugin
0 commit comments