Skip to content

Commit

Permalink
Adds support for allowing a RestoreItemAction to skip item restore (v…
Browse files Browse the repository at this point in the history
…mware-tanzu#1336)

* Adds support for allowing a RestoreItemAction to skip item restore

This allows a RestoreItemAction plugin to signal to velero that
the returned item should be skipped rather than restored to the
cluster.

To support this, a boolean SkipRestore attribute is added to
RestoreItemActionExecuteOutput. If restore.restoreResource finds
this set to true, any remaining actions on this item are skipped,
and restore on this item is skipped. Execution continues with
the next item of this resource type.

To signal this for a particular item, the RestoreItemAction's
Execute method should call WithoutRestore() on the
RestoreItemActionExecuteOutput before returning it.

Signed-off-by: Scott Seago <sseago@redhat.com>

* Autogenerated code to support SkipRestore

Signed-off-by: Scott Seago <sseago@redhat.com>

* Added changelog for vmware-tanzu#1336

Signed-off-by: Scott Seago <sseago@redhat.com>
  • Loading branch information
sseago authored and jessestuart committed May 28, 2019
1 parent cf7472d commit aad366f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/1336-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for allowing a RestoreItemAction to skip item restore.
1 change: 1 addition & 0 deletions pkg/plugin/framework/restore_item_action_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,6 @@ func (c *RestoreItemActionGRPCClient) Execute(input *velero.RestoreItemActionExe
return &velero.RestoreItemActionExecuteOutput{
UpdatedItem: &updatedItem,
AdditionalItems: additionalItems,
SkipRestore: res.SkipRestore,
}, nil
}
3 changes: 2 additions & 1 deletion pkg/plugin/framework/restore_item_action_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re
}

res := &proto.RestoreItemActionExecuteResponse{
Item: updatedItemJSON,
Item: updatedItemJSON,
SkipRestore: executeOutput.SkipRestore,
}

for _, item := range executeOutput.AdditionalItems {
Expand Down
47 changes: 28 additions & 19 deletions pkg/plugin/generated/RestoreItemAction.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/plugin/proto/RestoreItemAction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ message RestoreItemActionExecuteRequest {
message RestoreItemActionExecuteResponse {
bytes item = 1;
repeated ResourceIdentifier additionalItems = 2;
bool skipRestore = 3;
}

service RestoreItemAction {
Expand Down
11 changes: 11 additions & 0 deletions pkg/plugin/velero/restore_item_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ type RestoreItemActionExecuteOutput struct {
// AdditionalItems is a list of additional related items that should
// be restored.
AdditionalItems []ResourceIdentifier

// SkipRestore tells velero to stop executing further actions
// on this item, and skip the restore step. When this field's
// value is true, AdditionalItems will be ignored.
SkipRestore bool
}

// NewRestoreItemActionExecuteOutput creates a new RestoreItemActionExecuteOutput
Expand All @@ -65,3 +70,9 @@ func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemAc
UpdatedItem: item,
}
}

// WithoutRestore returns SkipRestore for RestoreItemActionExecuteOutput
func (r *RestoreItemActionExecuteOutput) WithoutRestore() *RestoreItemActionExecuteOutput {
r.SkipRestore = true
return r
}
4 changes: 4 additions & 0 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ func (ctx *context) restoreItem(obj *unstructured.Unstructured, groupResource sc
return warnings, errs
}

if executeOutput.SkipRestore {
ctx.log.Infof("Skipping restore of %s: %v because a registered plugin discarded it", obj.GroupVersionKind().Kind, name)
return warnings, errs
}
unstructuredObj, ok := executeOutput.UpdatedItem.(*unstructured.Unstructured)
if !ok {
addToResult(&errs, namespace, fmt.Errorf("%s: unexpected type %T", resourceID, executeOutput.UpdatedItem))
Expand Down

0 comments on commit aad366f

Please sign in to comment.