Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#16 from sseago/abandon-item-restore-a…
Browse files Browse the repository at this point in the history
…fter-rebase

Adds support for allowing a RestoreItemAction to skip item restore
  • Loading branch information
sseago committed Apr 1, 2019
2 parents 15f8574 + 29f3b55 commit 265bccf
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
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
}
5 changes: 4 additions & 1 deletion pkg/plugin/framework/restore_item_action_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,20 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re
// If the plugin implementation returned a nil updateItem (meaning no modifications), reset updatedItem to the
// original item.
var updatedItemJSON []byte
skipRestore := false
if executeOutput.UpdatedItem == nil {
updatedItemJSON = req.Item
} else {
updatedItemJSON, err = json.Marshal(executeOutput.UpdatedItem.UnstructuredContent())
skipRestore = executeOutput.SkipRestore
if err != nil {
return nil, newGRPCError(errors.WithStack(err))
}
}

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

for _, item := range executeOutput.AdditionalItems {
Expand Down
8 changes: 8 additions & 0 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
10 changes: 10 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,10 @@ 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.
SkipRestore bool
}

// NewRestoreItemActionExecuteOutput creates a new RestoreItemActionExecuteOutput
Expand All @@ -65,3 +69,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 265bccf

Please sign in to comment.