diff --git a/changelogs/unreleased/1123-mwieczorek b/changelogs/unreleased/1123-mwieczorek new file mode 100644 index 000000000..9d6b391e8 --- /dev/null +++ b/changelogs/unreleased/1123-mwieczorek @@ -0,0 +1 @@ +Add original resource (from backup) to restore item action interface \ No newline at end of file diff --git a/pkg/plugin/generated/BlockStore.pb.go b/pkg/plugin/generated/BlockStore.pb.go index a6b0975cf..b7e66ebb8 100644 --- a/pkg/plugin/generated/BlockStore.pb.go +++ b/pkg/plugin/generated/BlockStore.pb.go @@ -147,7 +147,7 @@ type CreateSnapshotRequest struct { func (m *CreateSnapshotRequest) Reset() { *m = CreateSnapshotRequest{} } func (m *CreateSnapshotRequest) String() string { return proto.CompactTextString(m) } func (*CreateSnapshotRequest) ProtoMessage() {} -func (*CreateSnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{6} } +func (*CreateSnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{4} } func (m *CreateSnapshotRequest) GetPlugin() string { if m != nil { @@ -184,7 +184,7 @@ type CreateSnapshotResponse struct { func (m *CreateSnapshotResponse) Reset() { *m = CreateSnapshotResponse{} } func (m *CreateSnapshotResponse) String() string { return proto.CompactTextString(m) } func (*CreateSnapshotResponse) ProtoMessage() {} -func (*CreateSnapshotResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{7} } +func (*CreateSnapshotResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{5} } func (m *CreateSnapshotResponse) GetSnapshotID() string { if m != nil { @@ -201,7 +201,7 @@ type DeleteSnapshotRequest struct { func (m *DeleteSnapshotRequest) Reset() { *m = DeleteSnapshotRequest{} } func (m *DeleteSnapshotRequest) String() string { return proto.CompactTextString(m) } func (*DeleteSnapshotRequest) ProtoMessage() {} -func (*DeleteSnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{8} } +func (*DeleteSnapshotRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{6} } func (m *DeleteSnapshotRequest) GetPlugin() string { if m != nil { @@ -225,7 +225,7 @@ type GetVolumeIDRequest struct { func (m *GetVolumeIDRequest) Reset() { *m = GetVolumeIDRequest{} } func (m *GetVolumeIDRequest) String() string { return proto.CompactTextString(m) } func (*GetVolumeIDRequest) ProtoMessage() {} -func (*GetVolumeIDRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{9} } +func (*GetVolumeIDRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{7} } func (m *GetVolumeIDRequest) GetPlugin() string { if m != nil { @@ -248,7 +248,7 @@ type GetVolumeIDResponse struct { func (m *GetVolumeIDResponse) Reset() { *m = GetVolumeIDResponse{} } func (m *GetVolumeIDResponse) String() string { return proto.CompactTextString(m) } func (*GetVolumeIDResponse) ProtoMessage() {} -func (*GetVolumeIDResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{10} } +func (*GetVolumeIDResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{8} } func (m *GetVolumeIDResponse) GetVolumeID() string { if m != nil { @@ -266,7 +266,7 @@ type SetVolumeIDRequest struct { func (m *SetVolumeIDRequest) Reset() { *m = SetVolumeIDRequest{} } func (m *SetVolumeIDRequest) String() string { return proto.CompactTextString(m) } func (*SetVolumeIDRequest) ProtoMessage() {} -func (*SetVolumeIDRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{11} } +func (*SetVolumeIDRequest) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{9} } func (m *SetVolumeIDRequest) GetPlugin() string { if m != nil { @@ -296,7 +296,7 @@ type SetVolumeIDResponse struct { func (m *SetVolumeIDResponse) Reset() { *m = SetVolumeIDResponse{} } func (m *SetVolumeIDResponse) String() string { return proto.CompactTextString(m) } func (*SetVolumeIDResponse) ProtoMessage() {} -func (*SetVolumeIDResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{12} } +func (*SetVolumeIDResponse) Descriptor() ([]byte, []int) { return fileDescriptor1, []int{10} } func (m *SetVolumeIDResponse) GetPersistentVolume() []byte { if m != nil { @@ -592,41 +592,38 @@ var _BlockStore_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("BlockStore.proto", fileDescriptor1) } var fileDescriptor1 = []byte{ - // 566 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0x96, 0x63, 0xb7, 0x6a, 0x26, 0xa5, 0x8a, 0x36, 0x3f, 0xb2, 0x2c, 0x11, 0x8c, 0x4f, 0x51, - 0x25, 0x22, 0x08, 0x07, 0x2a, 0x0e, 0x48, 0x05, 0x17, 0x64, 0x51, 0x09, 0xc9, 0x2e, 0x08, 0xc1, - 0xc9, 0x90, 0x4d, 0x1a, 0xd5, 0xf1, 0x1a, 0xef, 0xa6, 0x92, 0x1f, 0x86, 0x77, 0xe3, 0x41, 0x38, - 0x54, 0xb6, 0x37, 0xf1, 0xae, 0xb3, 0x69, 0x72, 0xc9, 0xcd, 0x33, 0xb3, 0xfb, 0xcd, 0x37, 0x3b, - 0xdf, 0x8c, 0xa1, 0xfd, 0x3e, 0x22, 0xbf, 0xef, 0x02, 0x46, 0x52, 0x3c, 0x4a, 0x52, 0xc2, 0x08, - 0x6a, 0xce, 0x70, 0x8c, 0xd3, 0x90, 0xe1, 0x89, 0x75, 0x1a, 0xdc, 0x86, 0x29, 0x9e, 0x94, 0x01, - 0xe7, 0xaf, 0x06, 0x9d, 0x0f, 0x29, 0x0e, 0x19, 0xfe, 0x46, 0xa2, 0xe5, 0x02, 0xfb, 0xf8, 0xcf, - 0x12, 0x53, 0x86, 0xfa, 0x70, 0x9c, 0x44, 0xcb, 0xd9, 0x3c, 0x36, 0x35, 0x5b, 0x1b, 0x36, 0x7d, - 0x6e, 0xa1, 0x01, 0x00, 0x8d, 0xc3, 0x84, 0xde, 0x12, 0xe6, 0xb9, 0x66, 0xa3, 0x88, 0x09, 0x9e, - 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, 0x85, - 0x56, 0x9a, 0xb5, 0x06, 0xdb, 0xc2, 0x9c, 0xd3, 0x35, 0xb4, 0x82, 0x2d, 0x68, 0xc1, 0xe3, 0x68, - 0x0a, 0xa9, 0xfe, 0x3a, 0x2e, 0xfe, 0xac, 0xaf, 0x1f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa2, 0x65, - 0xf8, 0xa4, 0x86, 0x07, 0x00, 0x00, + // 527 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0x4f, 0x6f, 0xd3, 0x4e, + 0x10, 0x95, 0x63, 0xb7, 0xfa, 0x65, 0xd2, 0x5f, 0x15, 0x4d, 0xfe, 0xc8, 0xb2, 0x44, 0x30, 0x3e, + 0x45, 0x3d, 0x44, 0x10, 0x0e, 0x54, 0x1c, 0x90, 0x0a, 0x2e, 0x28, 0xa2, 0x12, 0x92, 0x5d, 0x10, + 0x82, 0x93, 0xa1, 0xd3, 0x34, 0xaa, 0xe3, 0x35, 0xde, 0x4d, 0xa5, 0x7c, 0x18, 0xee, 0x7c, 0x2c, + 0x3e, 0x0a, 0x8a, 0xbd, 0x49, 0x76, 0x93, 0x4d, 0xd3, 0x4b, 0x6f, 0x9e, 0x19, 0xcf, 0x9b, 0xf7, + 0xc6, 0x6f, 0xd7, 0xd0, 0x7c, 0x9b, 0xb2, 0x9f, 0xb7, 0xb1, 0x60, 0x05, 0x0d, 0xf2, 0x82, 0x09, + 0x86, 0xf5, 0x31, 0x65, 0x54, 0x24, 0x82, 0xae, 0xbc, 0xa3, 0xf8, 0x26, 0x29, 0xe8, 0xaa, 0x2a, + 0x04, 0xbf, 0x2d, 0x68, 0xbd, 0x2b, 0x28, 0x11, 0xf4, 0x85, 0xa5, 0xb3, 0x29, 0x45, 0xf4, 0x6b, + 0x46, 0x5c, 0x60, 0x17, 0x0e, 0xf3, 0x74, 0x36, 0x9e, 0x64, 0xae, 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, 0xa3, 0x19, 0x6c, 0xf5, 0xe3, 0xb0, 0xfc, 0xdd, + 0xbc, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0xae, 0x59, 0x98, 0xf2, 0x9b, 0x06, 0x00, 0x00, } diff --git a/pkg/plugin/generated/RestoreItemAction.pb.go b/pkg/plugin/generated/RestoreItemAction.pb.go index e048be154..8bcbe360f 100644 --- a/pkg/plugin/generated/RestoreItemAction.pb.go +++ b/pkg/plugin/generated/RestoreItemAction.pb.go @@ -18,9 +18,10 @@ var _ = fmt.Errorf var _ = math.Inf type RestoreExecuteRequest struct { - Plugin string `protobuf:"bytes,1,opt,name=plugin" json:"plugin,omitempty"` - Item []byte `protobuf:"bytes,2,opt,name=item,proto3" json:"item,omitempty"` - Restore []byte `protobuf:"bytes,3,opt,name=restore,proto3" json:"restore,omitempty"` + Plugin string `protobuf:"bytes,1,opt,name=plugin" json:"plugin,omitempty"` + Item []byte `protobuf:"bytes,2,opt,name=item,proto3" json:"item,omitempty"` + Restore []byte `protobuf:"bytes,3,opt,name=restore,proto3" json:"restore,omitempty"` + ItemFromBackup []byte `protobuf:"bytes,4,opt,name=itemFromBackup,proto3" json:"itemFromBackup,omitempty"` } func (m *RestoreExecuteRequest) Reset() { *m = RestoreExecuteRequest{} } @@ -49,6 +50,13 @@ func (m *RestoreExecuteRequest) GetRestore() []byte { return nil } +func (m *RestoreExecuteRequest) GetItemFromBackup() []byte { + if m != nil { + return m.ItemFromBackup + } + return nil +} + type RestoreExecuteResponse struct { Item []byte `protobuf:"bytes,1,opt,name=item,proto3" json:"item,omitempty"` Warning string `protobuf:"bytes,2,opt,name=warning" json:"warning,omitempty"` @@ -186,20 +194,21 @@ var _RestoreItemAction_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("RestoreItemAction.proto", fileDescriptor4) } var fileDescriptor4 = []byte{ - // 230 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x0f, 0x4a, 0x2d, 0x2e, - 0xc9, 0x2f, 0x4a, 0xf5, 0x2c, 0x49, 0xcd, 0x75, 0x4c, 0x2e, 0xc9, 0xcc, 0xcf, 0xd3, 0x2b, 0x28, - 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4c, 0x4f, 0xcd, 0x4b, 0x2d, 0x4a, 0x2c, 0x49, 0x4d, 0x91, 0xe2, - 0x09, 0xce, 0x48, 0x2c, 0x4a, 0x4d, 0x81, 0x48, 0x28, 0xc5, 0x72, 0x89, 0x42, 0xf5, 0xb8, 0x56, - 0xa4, 0x26, 0x97, 0x96, 0xa4, 0x06, 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x08, 0x89, 0x71, 0xb1, - 0x15, 0xe4, 0x94, 0xa6, 0x67, 0xe6, 0x49, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x79, 0x42, - 0x42, 0x5c, 0x2c, 0x99, 0x25, 0xa9, 0xb9, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41, 0x60, 0xb6, - 0x90, 0x04, 0x17, 0x7b, 0x11, 0xc4, 0x10, 0x09, 0x66, 0xb0, 0x30, 0x8c, 0xab, 0xe4, 0xc6, 0x25, - 0x86, 0x6e, 0x7c, 0x71, 0x41, 0x7e, 0x5e, 0x71, 0x2a, 0xdc, 0x1c, 0x46, 0x54, 0x73, 0xca, 0x13, - 0x8b, 0xf2, 0x32, 0xf3, 0xd2, 0xc1, 0xc6, 0x73, 0x06, 0xc1, 0xb8, 0x46, 0xab, 0x19, 0xb9, 0x04, - 0x31, 0xfc, 0x26, 0xe4, 0xc6, 0xc5, 0xe9, 0x58, 0x50, 0x90, 0x93, 0x99, 0x5a, 0x1c, 0x92, 0x2f, - 0x24, 0xad, 0x07, 0xf7, 0xa3, 0x1e, 0x5c, 0x14, 0xea, 0x1b, 0x29, 0x19, 0xec, 0x92, 0x50, 0xb7, - 0xf8, 0x71, 0xb1, 0x43, 0x9d, 0x27, 0xa4, 0x80, 0xa4, 0x10, 0x6b, 0xc0, 0x48, 0x29, 0xe2, 0x51, - 0x01, 0x31, 0x2f, 0x89, 0x0d, 0x1c, 0xb6, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xaa, 0xe5, - 0x97, 0xa4, 0x8f, 0x01, 0x00, 0x00, + // 252 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x51, 0x4b, 0x4e, 0xc3, 0x30, + 0x14, 0x94, 0xa1, 0x6a, 0x95, 0xa7, 0x0a, 0x89, 0x27, 0x51, 0xac, 0xc0, 0x22, 0x74, 0x81, 0xba, + 0xca, 0x02, 0x4e, 0x50, 0x24, 0x22, 0xb1, 0x61, 0x61, 0xb8, 0x40, 0x48, 0x9f, 0x82, 0x45, 0x63, + 0x1b, 0x7f, 0x04, 0x17, 0xe0, 0x34, 0x5c, 0x12, 0xe1, 0xb8, 0x11, 0x94, 0x88, 0x9d, 0x67, 0xde, + 0xf8, 0xcd, 0x78, 0x0c, 0xa7, 0x82, 0x9c, 0xd7, 0x96, 0xee, 0x3c, 0x75, 0xeb, 0xc6, 0x4b, 0xad, + 0x4a, 0x63, 0xb5, 0xd7, 0x98, 0xb5, 0xa4, 0xc8, 0xd6, 0x9e, 0x36, 0xf9, 0xfc, 0xe1, 0xb9, 0xb6, + 0xb4, 0xe9, 0x07, 0xcb, 0x0f, 0x06, 0x27, 0xe9, 0xd2, 0xed, 0x3b, 0x35, 0xc1, 0x93, 0xa0, 0xd7, + 0x40, 0xce, 0xe3, 0x02, 0xa6, 0x66, 0x1b, 0x5a, 0xa9, 0x38, 0x2b, 0xd8, 0x2a, 0x13, 0x09, 0x21, + 0xc2, 0x44, 0x7a, 0xea, 0xf8, 0x41, 0xc1, 0x56, 0x73, 0x11, 0xcf, 0xc8, 0x61, 0x66, 0xfb, 0x25, + 0xfc, 0x30, 0xd2, 0x3b, 0x88, 0x97, 0x70, 0xf4, 0xad, 0xa8, 0xac, 0xee, 0x6e, 0xea, 0xe6, 0x25, + 0x18, 0x3e, 0x89, 0x82, 0x3d, 0x76, 0x59, 0xc1, 0x62, 0x3f, 0x86, 0x33, 0x5a, 0x39, 0x1a, 0xfc, + 0xd8, 0x6f, 0xbf, 0xb7, 0xda, 0x2a, 0xa9, 0xda, 0x18, 0x23, 0x13, 0x3b, 0x78, 0xf5, 0xc9, 0xe0, + 0xf8, 0x4f, 0x09, 0x58, 0x41, 0xb6, 0x36, 0x66, 0x2b, 0xc9, 0x3d, 0x6a, 0x3c, 0x2b, 0x87, 0x32, + 0xca, 0x81, 0x4d, 0xaf, 0xce, 0xcf, 0xc7, 0x87, 0x29, 0xcb, 0x3d, 0xcc, 0x52, 0x3c, 0x2c, 0x7e, + 0x08, 0x47, 0x0b, 0xcc, 0x2f, 0xfe, 0x51, 0xf4, 0xfb, 0x9e, 0xa6, 0xf1, 0x13, 0xae, 0xbf, 0x02, + 0x00, 0x00, 0xff, 0xff, 0x19, 0xeb, 0x64, 0x57, 0xb8, 0x01, 0x00, 0x00, } diff --git a/pkg/plugin/proto/RestoreItemAction.proto b/pkg/plugin/proto/RestoreItemAction.proto index c5dea92bd..87c186565 100644 --- a/pkg/plugin/proto/RestoreItemAction.proto +++ b/pkg/plugin/proto/RestoreItemAction.proto @@ -7,6 +7,7 @@ message RestoreExecuteRequest { string plugin = 1; bytes item = 2; bytes restore = 3; + bytes itemFromBackup = 4; } message RestoreExecuteResponse { diff --git a/pkg/plugin/restartable_delegate_test.go b/pkg/plugin/restartable_delegate_test.go index a87b2f15a..451d877b0 100644 --- a/pkg/plugin/restartable_delegate_test.go +++ b/pkg/plugin/restartable_delegate_test.go @@ -88,6 +88,14 @@ func runRestartableDelegateTests( continue } + // If function returns nil as struct return type, we cannot just + // compare the interface to nil as its type will not be nil, + // only the value will be + if expected[i] == nil && reflect.ValueOf(a).Kind() == reflect.Ptr { + assert.True(t, reflect.ValueOf(a).IsNil()) + continue + } + // Otherwise, use plain Equal assert.Equal(t, expected[i], a) } diff --git a/pkg/plugin/restartable_restore_item_action.go b/pkg/plugin/restartable_restore_item_action.go index 254cd4414..703d85b72 100644 --- a/pkg/plugin/restartable_restore_item_action.go +++ b/pkg/plugin/restartable_restore_item_action.go @@ -17,9 +17,7 @@ package plugin import ( "github.com/pkg/errors" - "k8s.io/apimachinery/pkg/runtime" - api "github.com/heptio/velero/pkg/apis/velero/v1" "github.com/heptio/velero/pkg/restore" ) @@ -78,11 +76,11 @@ func (r *restartableRestoreItemAction) AppliesTo() (restore.ResourceSelector, er } // Execute restarts the plugin's process if needed, then delegates the call. -func (r *restartableRestoreItemAction) Execute(obj runtime.Unstructured, restore *api.Restore) (res runtime.Unstructured, warning error, err error) { +func (r *restartableRestoreItemAction) Execute(input *restore.RestoreItemActionExecuteInput) (*restore.RestoreItemActionExecuteOutput, error) { delegate, err := r.getDelegate() if err != nil { - return nil, nil, err + return nil, err } - return delegate.Execute(obj, restore) + return delegate.Execute(input) } diff --git a/pkg/plugin/restartable_restore_item_action_test.go b/pkg/plugin/restartable_restore_item_action_test.go index a5fe9b5b3..33d49df4d 100644 --- a/pkg/plugin/restartable_restore_item_action_test.go +++ b/pkg/plugin/restartable_restore_item_action_test.go @@ -98,18 +98,25 @@ func TestRestartableRestoreItemActionGetDelegate(t *testing.T) { } func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { - r := new(v1.Restore) - pv := &unstructured.Unstructured{ Object: map[string]interface{}{ "color": "blue", }, } - pvToReturn := &unstructured.Unstructured{ - Object: map[string]interface{}{ - "color": "green", + input := &restore.RestoreItemActionExecuteInput{ + Item: pv, + ItemFromBackup: pv, + Restore: new(v1.Restore), + } + + output := &restore.RestoreItemActionExecuteOutput{ + UpdatedItem: &unstructured.Unstructured{ + Object: map[string]interface{}{ + "color": "green", + }, }, + Warning: errors.Errorf("delegate warning"), } runRestartableDelegateTests( @@ -132,9 +139,9 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { }, restartableDelegateTest{ function: "Execute", - inputs: []interface{}{pv, r}, - expectedErrorOutputs: []interface{}{nil, nil, errors.Errorf("reset error")}, - expectedDelegateOutputs: []interface{}{pvToReturn, errors.Errorf("delegate warning"), errors.Errorf("delegate error")}, + inputs: []interface{}{input}, + expectedErrorOutputs: []interface{}{nil, errors.Errorf("reset error")}, + expectedDelegateOutputs: []interface{}{output, errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/restore_item_action.go b/pkg/plugin/restore_item_action.go index e6897faff..31cb81ba9 100644 --- a/pkg/plugin/restore_item_action.go +++ b/pkg/plugin/restore_item_action.go @@ -24,7 +24,6 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" api "github.com/heptio/velero/pkg/apis/velero/v1" proto "github.com/heptio/velero/pkg/plugin/generated" @@ -39,6 +38,8 @@ type RestoreItemActionPlugin struct { *pluginBase } +var _ restore.ItemAction = &RestoreItemActionGRPCClient{} + // NewRestoreItemActionPlugin constructs a RestoreItemActionPlugin. func NewRestoreItemActionPlugin(options ...pluginOption) *RestoreItemActionPlugin { return &RestoreItemActionPlugin{ @@ -84,31 +85,37 @@ func (c *RestoreItemActionGRPCClient) AppliesTo() (restore.ResourceSelector, err }, nil } -func (c *RestoreItemActionGRPCClient) Execute(item runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { - itemJSON, err := json.Marshal(item.UnstructuredContent()) +func (c *RestoreItemActionGRPCClient) Execute(input *restore.RestoreItemActionExecuteInput) (*restore.RestoreItemActionExecuteOutput, error) { + itemJSON, err := json.Marshal(input.Item.UnstructuredContent()) if err != nil { - return nil, nil, err + return nil, err } - restoreJSON, err := json.Marshal(restore) + itemFromBackupJSON, err := json.Marshal(input.ItemFromBackup.UnstructuredContent()) if err != nil { - return nil, nil, err + return nil, err + } + + restoreJSON, err := json.Marshal(input.Restore) + if err != nil { + return nil, err } req := &proto.RestoreExecuteRequest{ - Plugin: c.plugin, - Item: itemJSON, - Restore: restoreJSON, + Plugin: c.plugin, + Item: itemJSON, + ItemFromBackup: itemFromBackupJSON, + Restore: restoreJSON, } res, err := c.grpcClient.Execute(context.Background(), req) if err != nil { - return nil, nil, err + return nil, err } var updatedItem unstructured.Unstructured if err := json.Unmarshal(res.Item, &updatedItem); err != nil { - return nil, nil, err + return nil, err } var warning error @@ -116,7 +123,10 @@ func (c *RestoreItemActionGRPCClient) Execute(item runtime.Unstructured, restore warning = errors.New(res.Warning) } - return &updatedItem, warning, nil + return &restore.RestoreItemActionExecuteOutput{ + UpdatedItem: &updatedItem, + Warning: warning, + }, nil } ////////////////////////////////////////////////////////////////////////////// @@ -176,31 +186,40 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re } var ( - item unstructured.Unstructured - restore api.Restore + item unstructured.Unstructured + itemFromBackup unstructured.Unstructured + restoreObj api.Restore ) if err := json.Unmarshal(req.Item, &item); err != nil { return nil, err } - if err := json.Unmarshal(req.Restore, &restore); err != nil { + if err := json.Unmarshal(req.ItemFromBackup, &itemFromBackup); err != nil { return nil, err } - res, warning, err := impl.Execute(&item, &restore) + if err := json.Unmarshal(req.Restore, &restoreObj); err != nil { + return nil, err + } + + executeOutput, err := impl.Execute(&restore.RestoreItemActionExecuteInput{ + Item: &item, + ItemFromBackup: &itemFromBackup, + Restore: &restoreObj, + }) if err != nil { return nil, err } - updatedItem, err := json.Marshal(res) + updatedItem, err := json.Marshal(executeOutput.UpdatedItem) if err != nil { return nil, err } var warnMessage string - if warning != nil { - warnMessage = warning.Error() + if executeOutput.Warning != nil { + warnMessage = executeOutput.Warning.Error() } return &proto.RestoreExecuteResponse{ diff --git a/pkg/restore/item_action.go b/pkg/restore/item_action.go index eaf052643..27a90b118 100644 --- a/pkg/restore/item_action.go +++ b/pkg/restore/item_action.go @@ -34,7 +34,38 @@ type ItemAction interface { // should be returned, along with a warning (which will be logged but will not prevent // the item from being restored) or error (which will be logged and will prevent the item // from being restored) if applicable. - Execute(obj runtime.Unstructured, restore *api.Restore) (res runtime.Unstructured, warning error, err error) + Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) +} + +// RestoreItemActionExecuteInput contains the input parameters for the ItemAction's Execute function. +type RestoreItemActionExecuteInput struct { + // Item is the item being restored. It is likely different from the pristine backed up version + // (metadata reset, changed by various restore item action plugins, etc.). + Item runtime.Unstructured + // ItemFromBackup is the item taken from the pristine backed up version of resource. + ItemFromBackup runtime.Unstructured + // Restore is the representation of the restore resource processed by Ark. + Restore *api.Restore +} + +// RestoreItemActionExecuteOutput contains the output variables for the ItemAction's Execution function. +type RestoreItemActionExecuteOutput struct { + // UpdatedItem is the item being restored mutated by ItemAction. + UpdatedItem runtime.Unstructured + // Warning is an exceptional message returned from ItemAction + // which is not preventing the item from being restored. + Warning error +} + +func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput { + return &RestoreItemActionExecuteOutput{ + UpdatedItem: item, + } +} + +func (r *RestoreItemActionExecuteOutput) WithWarning(err error) *RestoreItemActionExecuteOutput { + r.Warning = err + return r } // ResourceSelector is a collection of included/excluded namespaces, diff --git a/pkg/restore/job_action.go b/pkg/restore/job_action.go index ae70ccf82..e1f22879e 100644 --- a/pkg/restore/job_action.go +++ b/pkg/restore/job_action.go @@ -22,8 +22,6 @@ import ( batchv1api "k8s.io/api/batch/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - - velerov1api "github.com/heptio/velero/pkg/apis/velero/v1" ) type jobAction struct { @@ -40,10 +38,10 @@ func (a *jobAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (a *jobAction) Execute(obj runtime.Unstructured, restore *velerov1api.Restore) (runtime.Unstructured, error, error) { +func (a *jobAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { job := new(batchv1api.Job) - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), job); err != nil { - return nil, nil, errors.WithStack(err) + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), job); err != nil { + return nil, errors.WithStack(err) } if job.Spec.Selector != nil { @@ -53,8 +51,8 @@ func (a *jobAction) Execute(obj runtime.Unstructured, restore *velerov1api.Resto res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(job) if err != nil { - return nil, nil, errors.WithStack(err) + return nil, errors.WithStack(err) } - return &unstructured.Unstructured{Object: res}, nil, nil + return NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/job_action_test.go b/pkg/restore/job_action_test.go index 0570935ae..a9f433d1b 100644 --- a/pkg/restore/job_action_test.go +++ b/pkg/restore/job_action_test.go @@ -137,11 +137,15 @@ func TestJobActionExecute(t *testing.T) { unstructuredJob, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, _, err := action.Execute(&unstructured.Unstructured{Object: unstructuredJob}, nil) + res, err := action.Execute(&RestoreItemActionExecuteInput{ + Item: &unstructured.Unstructured{Object: unstructuredJob}, + ItemFromBackup: &unstructured.Unstructured{Object: unstructuredJob}, + Restore: nil, + }) if assert.Equal(t, test.expectedErr, err != nil) { var job batchv1api.Job - require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UnstructuredContent(), &job)) + require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UpdatedItem.UnstructuredContent(), &job)) assert.Equal(t, test.expectedRes, job) } diff --git a/pkg/restore/mocks/item_action.go b/pkg/restore/mocks/item_action.go index 6edd047a9..b8ef31717 100644 --- a/pkg/restore/mocks/item_action.go +++ b/pkg/restore/mocks/item_action.go @@ -18,8 +18,6 @@ package mocks import mock "github.com/stretchr/testify/mock" import restore "github.com/heptio/velero/pkg/restore" -import runtime "k8s.io/apimachinery/pkg/runtime" -import v1 "github.com/heptio/velero/pkg/apis/velero/v1" // ItemAction is an autogenerated mock type for the ItemAction type type ItemAction struct { @@ -47,32 +45,25 @@ func (_m *ItemAction) AppliesTo() (restore.ResourceSelector, error) { return r0, r1 } -// Execute provides a mock function with given fields: obj, _a1 -func (_m *ItemAction) Execute(obj runtime.Unstructured, _a1 *v1.Restore) (runtime.Unstructured, error, error) { - ret := _m.Called(obj, _a1) +// Execute provides a mock function with given fields: input +func (_m *ItemAction) Execute(input *restore.RestoreItemActionExecuteInput) (*restore.RestoreItemActionExecuteOutput, error) { + ret := _m.Called(input) - var r0 runtime.Unstructured - if rf, ok := ret.Get(0).(func(runtime.Unstructured, *v1.Restore) runtime.Unstructured); ok { - r0 = rf(obj, _a1) + var r0 *restore.RestoreItemActionExecuteOutput + if rf, ok := ret.Get(0).(func(*restore.RestoreItemActionExecuteInput) *restore.RestoreItemActionExecuteOutput); ok { + r0 = rf(input) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(runtime.Unstructured) + r0 = ret.Get(0).(*restore.RestoreItemActionExecuteOutput) } } var r1 error - if rf, ok := ret.Get(1).(func(runtime.Unstructured, *v1.Restore) error); ok { - r1 = rf(obj, _a1) + if rf, ok := ret.Get(1).(func(*restore.RestoreItemActionExecuteInput) error); ok { + r1 = rf(input) } else { r1 = ret.Error(1) } - var r2 error - if rf, ok := ret.Get(2).(func(runtime.Unstructured, *v1.Restore) error); ok { - r2 = rf(obj, _a1) - } else { - r2 = ret.Error(2) - } - - return r0, r1, r2 + return r0, r1 } diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 6b6dc9b85..1e60573cc 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -24,8 +24,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - - api "github.com/heptio/velero/pkg/apis/velero/v1" ) type podAction struct { @@ -42,10 +40,10 @@ func (a *podAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { +func (a *podAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { pod := new(v1.Pod) - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), pod); err != nil { - return nil, nil, errors.WithStack(err) + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), pod); err != nil { + return nil, errors.WithStack(err) } pod.Spec.NodeName = "" @@ -83,8 +81,8 @@ func (a *podAction) Execute(obj runtime.Unstructured, restore *api.Restore) (run res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pod) if err != nil { - return nil, nil, errors.WithStack(err) + return nil, errors.WithStack(err) } - return &unstructured.Unstructured{Object: res}, nil, nil + return NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index 02cfdbe63..0d62b0979 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -197,17 +197,21 @@ func TestPodActionExecute(t *testing.T) { unstructuredPod, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, warning, err := action.Execute(&unstructured.Unstructured{Object: unstructuredPod}, nil) - assert.Nil(t, warning) + res, err := action.Execute(&RestoreItemActionExecuteInput{ + Item: &unstructured.Unstructured{Object: unstructuredPod}, + ItemFromBackup: &unstructured.Unstructured{Object: unstructuredPod}, + Restore: nil, + }) + assert.Nil(t, res.Warning) if test.expectedErr { assert.NotNil(t, err, "expected an error") - } else { - assert.Nil(t, err, "expected no error, got %v", err) + return } + assert.Nil(t, err, "expected no error, got %v", err) var pod corev1api.Pod - require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UnstructuredContent(), &pod)) + require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UpdatedItem.UnstructuredContent(), &pod)) assert.Equal(t, test.expectedRes, pod) }) diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index e82e1613b..dfce23536 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - api "github.com/heptio/velero/pkg/apis/velero/v1" "github.com/heptio/velero/pkg/buildinfo" "github.com/heptio/velero/pkg/restic" "github.com/heptio/velero/pkg/util/kube" @@ -59,13 +58,13 @@ func (a *resticRestoreAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { +func (a *resticRestoreAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing resticRestoreAction") defer a.logger.Info("Done executing resticRestoreAction") var pod corev1.Pod - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), &pod); err != nil { - return nil, nil, errors.Wrap(err, "unable to convert pod from runtime.Unstructured") + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &pod); err != nil { + return nil, errors.Wrap(err, "unable to convert pod from runtime.Unstructured") } log := a.logger.WithField("pod", kube.NamespaceAndName(&pod)) @@ -73,7 +72,7 @@ func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Res volumeSnapshots := restic.GetPodSnapshotAnnotations(&pod) if len(volumeSnapshots) == 0 { log.Debug("No restic snapshot ID annotations found") - return obj, nil, nil + return NewRestoreItemActionExecuteOutput(input.Item), nil } log.Info("Restic snapshot ID annotations found") @@ -81,7 +80,7 @@ func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Res initContainer := corev1.Container{ Name: restic.InitContainer, Image: a.initContainerImage, - Args: []string{string(restore.UID)}, + Args: []string{string(input.Restore.UID)}, Env: []corev1.EnvVar{ { Name: "POD_NAMESPACE", @@ -118,8 +117,8 @@ func (a *resticRestoreAction) Execute(obj runtime.Unstructured, restore *api.Res res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&pod) if err != nil { - return nil, nil, errors.Wrap(err, "unable to convert pod to runtime.Unstructured") + return nil, errors.Wrap(err, "unable to convert pod to runtime.Unstructured") } - return &unstructured.Unstructured{Object: res}, nil, nil + return NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 1074965f3..53986eb07 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -733,6 +733,10 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a continue } + // make a copy of object retrieved from backup + // to make it available unchanged inside restore actions + itemFromBackup := obj.DeepCopy() + if !ctx.selector.Matches(labels.Set(obj.GetLabels())) { continue } @@ -873,18 +877,22 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a ctx.log.Infof("Executing item action for %v", &groupResource) - updatedObj, warning, err := action.Execute(obj, ctx.restore) - if warning != nil { - addToResult(&warnings, namespace, fmt.Errorf("warning preparing %s: %v", fullPath, warning)) + executeOutput, err := action.Execute(&RestoreItemActionExecuteInput{ + Item: obj, + ItemFromBackup: itemFromBackup, + Restore: ctx.restore, + }) + if executeOutput.Warning != nil { + addToResult(&warnings, namespace, fmt.Errorf("warning preparing %s: %v", fullPath, executeOutput.Warning)) } if err != nil { addToResult(&errs, namespace, fmt.Errorf("error preparing %s: %v", fullPath, err)) continue } - unstructuredObj, ok := updatedObj.(*unstructured.Unstructured) + unstructuredObj, ok := executeOutput.UpdatedItem.(*unstructured.Unstructured) if !ok { - addToResult(&errs, namespace, fmt.Errorf("%s: unexpected type %T", fullPath, updatedObj)) + addToResult(&errs, namespace, fmt.Errorf("%s: unexpected type %T", fullPath, executeOutput.UpdatedItem)) continue } diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 0de9a8c3d..d2c7182bb 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1880,10 +1880,10 @@ func (r *fakeAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (r *fakeAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { - labels, found, err := unstructured.NestedMap(obj.UnstructuredContent(), "metadata", "labels") +func (r *fakeAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { + labels, found, err := unstructured.NestedMap(input.Item.UnstructuredContent(), "metadata", "labels") if err != nil { - return nil, nil, err + return nil, err } if !found { labels = make(map[string]interface{}) @@ -1891,22 +1891,22 @@ func (r *fakeAction) Execute(obj runtime.Unstructured, restore *api.Restore) (ru labels["fake-restorer"] = "foo" - if err := unstructured.SetNestedField(obj.UnstructuredContent(), labels, "metadata", "labels"); err != nil { - return nil, nil, err + if err := unstructured.SetNestedField(input.Item.UnstructuredContent(), labels, "metadata", "labels"); err != nil { + return nil, err } - unstructuredObj, ok := obj.(*unstructured.Unstructured) + unstructuredObj, ok := input.Item.(*unstructured.Unstructured) if !ok { - return nil, nil, errors.New("Unexpected type") + return nil, errors.New("Unexpected type") } // want the baseline functionality too res, err := resetMetadataAndStatus(unstructuredObj) if err != nil { - return nil, nil, err + return nil, err } - return res, nil, nil + return NewRestoreItemActionExecuteOutput(res), nil } type fakeNamespaceClient struct { diff --git a/pkg/restore/service_account_action.go b/pkg/restore/service_account_action.go index 59df4ed3e..bef82604d 100644 --- a/pkg/restore/service_account_action.go +++ b/pkg/restore/service_account_action.go @@ -25,7 +25,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - api "github.com/heptio/velero/pkg/apis/velero/v1" "github.com/heptio/velero/pkg/util/kube" ) @@ -43,13 +42,13 @@ func (a *serviceAccountAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (a *serviceAccountAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { +func (a *serviceAccountAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing serviceAccountAction") defer a.logger.Info("Done executing serviceAccountAction") var serviceAccount corev1.ServiceAccount - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), &serviceAccount); err != nil { - return nil, nil, errors.Wrap(err, "unable to convert serviceaccount from runtime.Unstructured") + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), &serviceAccount); err != nil { + return nil, errors.Wrap(err, "unable to convert serviceaccount from runtime.Unstructured") } log := a.logger.WithField("serviceaccount", kube.NamespaceAndName(&serviceAccount)) @@ -72,8 +71,8 @@ func (a *serviceAccountAction) Execute(obj runtime.Unstructured, restore *api.Re res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&serviceAccount) if err != nil { - return nil, nil, errors.Wrap(err, "unable to convert serviceaccount to runtime.Unstructured") + return nil, errors.Wrap(err, "unable to convert serviceaccount to runtime.Unstructured") } - return &unstructured.Unstructured{Object: res}, nil, nil + return NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/service_account_action_test.go b/pkg/restore/service_account_action_test.go index 6b31deff4..ad2812a28 100644 --- a/pkg/restore/service_account_action_test.go +++ b/pkg/restore/service_account_action_test.go @@ -89,12 +89,16 @@ func TestServiceAccountActionExecute(t *testing.T) { require.NoError(t, err) action := NewServiceAccountAction(test.NewLogger()) - res, warning, err := action.Execute(&unstructured.Unstructured{Object: saUnstructured}, nil) - require.NoError(t, warning) + res, err := action.Execute(&RestoreItemActionExecuteInput{ + Item: &unstructured.Unstructured{Object: saUnstructured}, + ItemFromBackup: &unstructured.Unstructured{Object: saUnstructured}, + Restore: nil, + }) + require.NoError(t, res.Warning) require.NoError(t, err) var resSA *corev1.ServiceAccount - err = runtime.DefaultUnstructuredConverter.FromUnstructured(res.UnstructuredContent(), &resSA) + err = runtime.DefaultUnstructuredConverter.FromUnstructured(res.UpdatedItem.UnstructuredContent(), &resSA) require.NoError(t, err) actual := []string{} diff --git a/pkg/restore/service_action.go b/pkg/restore/service_action.go index a271e6e1c..40461f9ed 100644 --- a/pkg/restore/service_action.go +++ b/pkg/restore/service_action.go @@ -25,8 +25,6 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" - - api "github.com/heptio/velero/pkg/apis/velero/v1" ) const annotationLastAppliedConfig = "kubectl.kubernetes.io/last-applied-configuration" @@ -45,10 +43,10 @@ func (a *serviceAction) AppliesTo() (ResourceSelector, error) { }, nil } -func (a *serviceAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) { +func (a *serviceAction) Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error) { service := new(corev1api.Service) - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), service); err != nil { - return nil, nil, errors.WithStack(err) + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), service); err != nil { + return nil, errors.WithStack(err) } if service.Spec.ClusterIP != "None" { @@ -56,15 +54,15 @@ func (a *serviceAction) Execute(obj runtime.Unstructured, restore *api.Restore) } if err := deleteNodePorts(service); err != nil { - return nil, nil, err + return nil, err } res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(service) if err != nil { - return nil, nil, errors.WithStack(err) + return nil, errors.WithStack(err) } - return &unstructured.Unstructured{Object: res}, nil, nil + return NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } func deleteNodePorts(service *corev1api.Service) error { diff --git a/pkg/restore/service_action_test.go b/pkg/restore/service_action_test.go index c1f629936..882293cf5 100644 --- a/pkg/restore/service_action_test.go +++ b/pkg/restore/service_action_test.go @@ -274,11 +274,15 @@ func TestServiceActionExecute(t *testing.T) { unstructuredSvc, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, _, err := action.Execute(&unstructured.Unstructured{Object: unstructuredSvc}, nil) + res, err := action.Execute(&RestoreItemActionExecuteInput{ + Item: &unstructured.Unstructured{Object: unstructuredSvc}, + ItemFromBackup: &unstructured.Unstructured{Object: unstructuredSvc}, + Restore: nil, + }) - if assert.Equal(t, test.expectedErr, err != nil) { + if assert.Equal(t, test.expectedErr, err != nil) && !test.expectedErr { var svc corev1api.Service - require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UnstructuredContent(), &svc)) + require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UpdatedItem.UnstructuredContent(), &svc)) assert.Equal(t, test.expectedRes, svc) }