@@ -700,6 +700,7 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
700
700
applicableActions = append (applicableActions , action )
701
701
}
702
702
703
+ fileLoop:
703
704
for _ , file := range files {
704
705
fullPath := filepath .Join (resourcePath , file .Name ())
705
706
obj , err := ctx .unmarshal (fullPath )
@@ -847,6 +848,15 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
847
848
continue
848
849
}
849
850
851
+ abandon , err := abandonItem (executeOutput .UpdatedItem .(* unstructured.Unstructured ))
852
+ if err != nil {
853
+ addToResult (& errs , namespace , fmt .Errorf ("error preparing %s: %v" , fullPath , err ))
854
+ continue
855
+ }
856
+ if abandon {
857
+ ctx .log .Infof ("Skipping restore of %s: %v because a registered plugin discarded it" , obj .GroupVersionKind ().Kind , name )
858
+ continue fileLoop
859
+ }
850
860
unstructuredObj , ok := executeOutput .UpdatedItem .(* unstructured.Unstructured )
851
861
if ! ok {
852
862
addToResult (& errs , namespace , fmt .Errorf ("%s: unexpected type %T" , fullPath , executeOutput .UpdatedItem ))
@@ -1046,6 +1056,20 @@ func isCompleted(obj *unstructured.Unstructured, groupResource schema.GroupResou
1046
1056
return false , nil
1047
1057
}
1048
1058
1059
+ // abandonItem returns whether or not a RestoreItemAction has decided to skip restore
1060
+ // Used to identify whether or not an object should be restored.
1061
+ func abandonItem (obj * unstructured.Unstructured ) (bool , error ) {
1062
+ abandon , found , err := unstructured .NestedBool (obj .UnstructuredContent (), "abandonItem" )
1063
+ if err != nil {
1064
+ return false , errors .WithStack (err )
1065
+ }
1066
+ if found {
1067
+ return abandon , nil
1068
+ } else {
1069
+ return false , nil
1070
+ }
1071
+ }
1072
+
1049
1073
// unmarshal reads the specified file, unmarshals the JSON contained within it
1050
1074
// and returns an Unstructured object.
1051
1075
func (ctx * context ) unmarshal (filePath string ) (* unstructured.Unstructured , error ) {
0 commit comments