From 45de8a782fd85d6042cf5aa7057f1972f49131aa Mon Sep 17 00:00:00 2001 From: Scott Seago Date: Wed, 12 Oct 2022 12:41:50 -0400 Subject: [PATCH] moved RIA execute input/output structs back to velero package The RIA refactoring moved velero.RestoreItemAction into a separate (restoreitemaction) v1 package. Unfortunately, this change would require plugins to make code changes to locate the RestoreItemActionExecuteInput and RestoreItemActionExecuteOutput structs. This commit restores those structs to the original velero package, leaving just the RestoreItemAction interface in the new v1 package. Signed-off-by: Scott Seago --- changelogs/unreleased/5441-sseago | 1 + .../v1/restartable_restore_item_action.go | 2 +- .../restartable_restore_item_action_test.go | 5 +- .../framework/restore_item_action_client.go | 4 +- .../framework/restore_item_action_server.go | 2 +- .../restoreitemaction/v1/RestoreItemAction.go | 11 ++-- .../velero/restore_item_action_shared.go | 62 +++++++++++++++++++ .../v1/restore_item_action.go | 44 +------------ pkg/restore/add_pv_from_pvc_action.go | 7 +-- pkg/restore/add_pv_from_pvc_action_test.go | 3 +- pkg/restore/add_pvc_from_pod_action.go | 5 +- pkg/restore/add_pvc_from_pod_action_test.go | 3 +- pkg/restore/admissionwebhook_config_action.go | 9 ++- .../admissionwebhook_config_action_test.go | 4 +- pkg/restore/apiservice_action.go | 5 +- pkg/restore/apiservice_action_test.go | 4 +- pkg/restore/change_pvc_node_selector.go | 15 +++-- pkg/restore/change_pvc_node_selector_test.go | 4 +- pkg/restore/change_storageclass_action.go | 9 ++- .../change_storageclass_action_test.go | 4 +- pkg/restore/clusterrolebinding_action.go | 7 +-- pkg/restore/clusterrolebinding_action_test.go | 3 +- .../crd_v1_preserve_unknown_fields_action.go | 7 +-- ..._v1_preserve_unknown_fields_action_test.go | 4 +- pkg/restore/init_restorehook_pod_action.go | 5 +- .../init_restorehook_pod_action_test.go | 4 +- pkg/restore/job_action.go | 5 +- pkg/restore/job_action_test.go | 4 +- pkg/restore/pod_action.go | 5 +- pkg/restore/pod_action_test.go | 3 +- pkg/restore/restic_restore_action.go | 7 +-- pkg/restore/restic_restore_action_test.go | 4 +- pkg/restore/restore.go | 2 +- pkg/restore/restore_test.go | 36 +++++------ pkg/restore/rolebinding_action.go | 7 +-- pkg/restore/rolebinding_action_test.go | 3 +- pkg/restore/service_account_action.go | 5 +- pkg/restore/service_account_action_test.go | 3 +- pkg/restore/service_action.go | 5 +- pkg/restore/service_action_test.go | 4 +- 40 files changed, 162 insertions(+), 164 deletions(-) create mode 100644 changelogs/unreleased/5441-sseago create mode 100644 pkg/plugin/velero/restore_item_action_shared.go diff --git a/changelogs/unreleased/5441-sseago b/changelogs/unreleased/5441-sseago new file mode 100644 index 0000000000..fd8f7b7d21 --- /dev/null +++ b/changelogs/unreleased/5441-sseago @@ -0,0 +1 @@ +moved RIA execute input/output structs back to velero package diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go index a6b595544d..28b319eca1 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go @@ -99,7 +99,7 @@ func (r RestartableRestoreItemAction) AppliesTo() (velero.ResourceSelector, erro } // Execute restarts the plugin's process if needed, then delegates the call. -func (r *RestartableRestoreItemAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (r *RestartableRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { delegate, err := r.getDelegate() if err != nil { return nil, err diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go index 55a0db2781..d16e3bb1fe 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go @@ -30,7 +30,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" mocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/restoreitemaction/v1" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) func TestRestartableGetRestoreItemAction(t *testing.T) { @@ -108,13 +107,13 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { }, } - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: pv, ItemFromBackup: pv, Restore: new(v1.Restore), } - output := &riav1.RestoreItemActionExecuteOutput{ + output := &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{ Object: map[string]interface{}{ "color": "green", diff --git a/pkg/plugin/framework/restore_item_action_client.go b/pkg/plugin/framework/restore_item_action_client.go index 35bafa0893..75490d4c2f 100644 --- a/pkg/plugin/framework/restore_item_action_client.go +++ b/pkg/plugin/framework/restore_item_action_client.go @@ -73,7 +73,7 @@ func (c *RestoreItemActionGRPCClient) AppliesTo() (velero.ResourceSelector, erro }, nil } -func (c *RestoreItemActionGRPCClient) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (c *RestoreItemActionGRPCClient) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { itemJSON, err := json.Marshal(input.Item.UnstructuredContent()) if err != nil { return nil, errors.WithStack(err) @@ -120,7 +120,7 @@ func (c *RestoreItemActionGRPCClient) Execute(input *riav1.RestoreItemActionExec additionalItems = append(additionalItems, newItem) } - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &updatedItem, AdditionalItems: additionalItems, SkipRestore: res.SkipRestore, diff --git a/pkg/plugin/framework/restore_item_action_server.go b/pkg/plugin/framework/restore_item_action_server.go index 924929c975..bdc149c480 100644 --- a/pkg/plugin/framework/restore_item_action_server.go +++ b/pkg/plugin/framework/restore_item_action_server.go @@ -108,7 +108,7 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re return nil, common.NewGRPCError(errors.WithStack(err)) } - executeOutput, err := impl.Execute(&riav1.RestoreItemActionExecuteInput{ + executeOutput, err := impl.Execute(&velero.RestoreItemActionExecuteInput{ Item: &item, ItemFromBackup: &itemFromBackup, Restore: &restoreObj, diff --git a/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go b/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go index 5bf33ed851..1bacf7b161 100644 --- a/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go +++ b/pkg/plugin/velero/mocks/restoreitemaction/v1/RestoreItemAction.go @@ -20,7 +20,6 @@ package v1 import ( mock "github.com/stretchr/testify/mock" velero "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // RestoreItemAction is an autogenerated mock type for the RestoreItemAction type @@ -50,20 +49,20 @@ func (_m *RestoreItemAction) AppliesTo() (velero.ResourceSelector, error) { } // Execute provides a mock function with given fields: input -func (_m *RestoreItemAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (_m *RestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { ret := _m.Called(input) - var r0 *riav1.RestoreItemActionExecuteOutput - if rf, ok := ret.Get(0).(func(*riav1.RestoreItemActionExecuteInput) *riav1.RestoreItemActionExecuteOutput); ok { + var r0 *velero.RestoreItemActionExecuteOutput + if rf, ok := ret.Get(0).(func(*velero.RestoreItemActionExecuteInput) *velero.RestoreItemActionExecuteOutput); ok { r0 = rf(input) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*riav1.RestoreItemActionExecuteOutput) + r0 = ret.Get(0).(*velero.RestoreItemActionExecuteOutput) } } var r1 error - if rf, ok := ret.Get(1).(func(*riav1.RestoreItemActionExecuteInput) error); ok { + if rf, ok := ret.Get(1).(func(*velero.RestoreItemActionExecuteInput) error); ok { r1 = rf(input) } else { r1 = ret.Error(1) diff --git a/pkg/plugin/velero/restore_item_action_shared.go b/pkg/plugin/velero/restore_item_action_shared.go new file mode 100644 index 0000000000..2714d69ab6 --- /dev/null +++ b/pkg/plugin/velero/restore_item_action_shared.go @@ -0,0 +1,62 @@ +/* +Copyright the Velero contributors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package velero + +import ( + "k8s.io/apimachinery/pkg/runtime" + + api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" +) + +// 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 Velero. + 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 + + // 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 +func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput { + return &RestoreItemActionExecuteOutput{ + UpdatedItem: item, + } +} + +// WithoutRestore returns SkipRestore for RestoreItemActionExecuteOutput +func (r *RestoreItemActionExecuteOutput) WithoutRestore() *RestoreItemActionExecuteOutput { + r.SkipRestore = true + return r +} diff --git a/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go b/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go index a50f3021f0..3398af9e1e 100644 --- a/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go +++ b/pkg/plugin/velero/restoreitemaction/v1/restore_item_action.go @@ -17,9 +17,6 @@ limitations under the License. package v1 import ( - "k8s.io/apimachinery/pkg/runtime" - - api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) @@ -36,44 +33,5 @@ type RestoreItemAction interface { // related items that should be restored, 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(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 Velero. - 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 - - // AdditionalItems is a list of additional related items that should - // be restored. - AdditionalItems []velero.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 -func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput { - return &RestoreItemActionExecuteOutput{ - UpdatedItem: item, - } -} - -// WithoutRestore returns SkipRestore for RestoreItemActionExecuteOutput -func (r *RestoreItemActionExecuteOutput) WithoutRestore() *RestoreItemActionExecuteOutput { - r.SkipRestore = true - return r + Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) } diff --git a/pkg/restore/add_pv_from_pvc_action.go b/pkg/restore/add_pv_from_pvc_action.go index 147ad553f4..04c992357f 100644 --- a/pkg/restore/add_pv_from_pvc_action.go +++ b/pkg/restore/add_pv_from_pvc_action.go @@ -24,7 +24,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) type AddPVFromPVCAction struct { @@ -41,7 +40,7 @@ func (a *AddPVFromPVCAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *AddPVFromPVCAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing AddPVFromPVCAction") // use input.ItemFromBackup because we need to look at status fields, which have already been @@ -54,7 +53,7 @@ func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput) // TODO: consolidate this logic in a helper function to share with backup_pv_action.go if pvc.Status.Phase != corev1api.ClaimBound || pvc.Spec.VolumeName == "" { a.logger.Info("PVC is not bound or its volume name is empty") - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, }, nil } @@ -65,7 +64,7 @@ func (a *AddPVFromPVCAction) Execute(input *riav1.RestoreItemActionExecuteInput) } a.logger.Infof("Adding PV %s as an additional item to restore", pvc.Spec.VolumeName) - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{pv}, }, nil diff --git a/pkg/restore/add_pv_from_pvc_action_test.go b/pkg/restore/add_pv_from_pvc_action_test.go index f8b5b5aaba..b4ceb90a43 100644 --- a/pkg/restore/add_pv_from_pvc_action_test.go +++ b/pkg/restore/add_pv_from_pvc_action_test.go @@ -27,7 +27,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -90,7 +89,7 @@ func TestAddPVFromPVCActionExecute(t *testing.T) { action := &AddPVFromPVCAction{logger: velerotest.NewLogger()} - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: itemData}, ItemFromBackup: &unstructured.Unstructured{Object: itemFromBackupData}, } diff --git a/pkg/restore/add_pvc_from_pod_action.go b/pkg/restore/add_pvc_from_pod_action.go index b7bd60a34c..70f33d985d 100644 --- a/pkg/restore/add_pvc_from_pod_action.go +++ b/pkg/restore/add_pvc_from_pod_action.go @@ -24,7 +24,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) type AddPVCFromPodAction struct { @@ -41,7 +40,7 @@ func (a *AddPVCFromPodAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *AddPVCFromPodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *AddPVCFromPodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing AddPVCFromPodAction") var pod corev1api.Pod @@ -64,7 +63,7 @@ func (a *AddPVCFromPodAction) Execute(input *riav1.RestoreItemActionExecuteInput }) } - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: additionalItems, }, nil diff --git a/pkg/restore/add_pvc_from_pod_action_test.go b/pkg/restore/add_pvc_from_pod_action_test.go index 529751b379..b409e5d6ef 100644 --- a/pkg/restore/add_pvc_from_pod_action_test.go +++ b/pkg/restore/add_pvc_from_pod_action_test.go @@ -28,7 +28,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -101,7 +100,7 @@ func TestAddPVCFromPodActionExecute(t *testing.T) { action := &AddPVCFromPodAction{logger: velerotest.NewLogger()} - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: itemData}, } diff --git a/pkg/restore/admissionwebhook_config_action.go b/pkg/restore/admissionwebhook_config_action.go index 68fa089888..8fd5c1693e 100644 --- a/pkg/restore/admissionwebhook_config_action.go +++ b/pkg/restore/admissionwebhook_config_action.go @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // AdmissionWebhookConfigurationAction is a RestoreItemAction plugin applicable to mutatingwebhookconfiguration and @@ -47,7 +46,7 @@ func (a *AdmissionWebhookConfigurationAction) AppliesTo() (velero.ResourceSelect // Execute will reset the value of "sideEffects" attribute of each item in the "webhooks" list to "None" if they are invalid values for // v1, such as "Unknown" or "Some" -func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *AdmissionWebhookConfigurationAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ChangeStorageClassAction") defer a.logger.Info("Done executing ChangeStorageClassAction") @@ -60,7 +59,7 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc logger := a.logger.WithField("resource_name", name) if apiVersion != "admissionregistration.k8s.io/v1" { logger.Infof("unable to handle api version: %s, skip", apiVersion) - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } webhooks, ok, err := unstructured.NestedSlice(item.UnstructuredContent(), "webhooks") if err != nil { @@ -68,7 +67,7 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc } if !ok { logger.Info("webhooks is not set, skip") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } newWebhooks := make([]interface{}, 0) for i, entry := range webhooks { @@ -86,5 +85,5 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *riav1.RestoreItemAc newWebhooks = append(newWebhooks, obj) } item.UnstructuredContent()["webhooks"] = newWebhooks - return riav1.NewRestoreItemActionExecuteOutput(item), nil + return velero.NewRestoreItemActionExecuteOutput(item), nil } diff --git a/pkg/restore/admissionwebhook_config_action_test.go b/pkg/restore/admissionwebhook_config_action_test.go index a6548ae586..c6c31d2219 100644 --- a/pkg/restore/admissionwebhook_config_action_test.go +++ b/pkg/restore/admissionwebhook_config_action_test.go @@ -8,7 +8,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -163,7 +163,7 @@ func TestNewAdmissionWebhookConfigurationActionExecute(t *testing.T) { t.Run(tt.name, func(t *testing.T) { o := map[string]interface{}{} json.Unmarshal([]byte(tt.itemJSON), &o) - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: o, }, diff --git a/pkg/restore/apiservice_action.go b/pkg/restore/apiservice_action.go index 0d9568c0b8..7f817a59e0 100644 --- a/pkg/restore/apiservice_action.go +++ b/pkg/restore/apiservice_action.go @@ -21,7 +21,6 @@ import ( "k8s.io/kube-aggregator/pkg/controllers/autoregister" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) type APIServiceAction struct { @@ -43,10 +42,10 @@ func (a *APIServiceAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *APIServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *APIServiceAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing APIServiceAction") defer a.logger.Info("Done executing APIServiceAction") a.logger.Infof("Skipping restore of APIService as it is managed by Kubernetes") - return riav1.NewRestoreItemActionExecuteOutput(input.Item).WithoutRestore(), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item).WithoutRestore(), nil } diff --git a/pkg/restore/apiservice_action_test.go b/pkg/restore/apiservice_action_test.go index 1f9baeae92..81f4a6171c 100644 --- a/pkg/restore/apiservice_action_test.go +++ b/pkg/restore/apiservice_action_test.go @@ -25,7 +25,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -40,7 +40,7 @@ func TestAPIServiceActionExecuteSkipsRestore(t *testing.T) { require.NoError(t, err) action := NewAPIServiceAction(velerotest.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredAPIService}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredAPIService}, }) diff --git a/pkg/restore/change_pvc_node_selector.go b/pkg/restore/change_pvc_node_selector.go index 23a3c20c90..d281d318f7 100644 --- a/pkg/restore/change_pvc_node_selector.go +++ b/pkg/restore/change_pvc_node_selector.go @@ -28,7 +28,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // ChangePVCNodeSelectorAction updates/reset PVC's node selector @@ -62,23 +61,23 @@ func (p *ChangePVCNodeSelectorAction) AppliesTo() (velero.ResourceSelector, erro // Execute updates the pvc's selected-node annotation: // a) if node mapping found in the config map for the plugin // b) if node mentioned in annotation doesn't exist -func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (p *ChangePVCNodeSelectorAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { p.logger.Info("Executing ChangePVCNodeSelectorAction") defer p.logger.Info("Done executing ChangePVCNodeSelectorAction") typeAcc, err := meta.TypeAccessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{}, err + return &velero.RestoreItemActionExecuteOutput{}, err } metadata, err := meta.Accessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{}, err + return &velero.RestoreItemActionExecuteOutput{}, err } annotations := metadata.GetAnnotations() if annotations == nil { - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log := p.logger.WithFields(map[string]interface{}{ @@ -91,7 +90,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec node, ok := annotations["volume.kubernetes.io/selected-node"] if !ok { log.Debug("PVC doesn't have node selector") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } // fetch node mapping from configMap @@ -106,7 +105,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec annotations["volume.kubernetes.io/selected-node"] = newNode metadata.SetAnnotations(annotations) log.Infof("Updating selected-node to %s from %s", newNode, node) - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } // configMap doesn't have node-mapping @@ -126,7 +125,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *riav1.RestoreItemActionExec } } - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } func getNewNodeFromConfigMap(client corev1client.ConfigMapInterface, node string) (string, error) { diff --git a/pkg/restore/change_pvc_node_selector_test.go b/pkg/restore/change_pvc_node_selector_test.go index 92a6f4b311..8be3051bac 100644 --- a/pkg/restore/change_pvc_node_selector_test.go +++ b/pkg/restore/change_pvc_node_selector_test.go @@ -31,7 +31,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) // TestChangePVCNodeSelectorActionExecute runs the ChangePVCNodeSelectorAction's Execute @@ -146,7 +146,7 @@ func TestChangePVCNodeSelectorActionExecute(t *testing.T) { unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pvc) require.NoError(t, err) - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredMap, }, diff --git a/pkg/restore/change_storageclass_action.go b/pkg/restore/change_storageclass_action.go index 3349cc7925..a02b7c484e 100644 --- a/pkg/restore/change_storageclass_action.go +++ b/pkg/restore/change_storageclass_action.go @@ -31,7 +31,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // ChangeStorageClassAction updates a PV or PVC's storage class name @@ -65,7 +64,7 @@ func (a *ChangeStorageClassAction) AppliesTo() (velero.ResourceSelector, error) // Execute updates the item's spec.storageClassName if a mapping is found // in the config map for the plugin. -func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ChangeStorageClassAction") defer a.logger.Info("Done executing ChangeStorageClassAction") @@ -77,7 +76,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute if config == nil || len(config.Data) == 0 { a.logger.Debug("No storage class mappings found") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } obj, ok := input.Item.(*unstructured.Unstructured) @@ -129,7 +128,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute if err != nil { return nil, err } else if !exists { - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log.Infof("Updating item's storage class name to %s", newStorageClass) @@ -138,7 +137,7 @@ func (a *ChangeStorageClassAction) Execute(input *riav1.RestoreItemActionExecute return nil, errors.Wrap(err, "unable to set item's spec.storageClassName") } } - return riav1.NewRestoreItemActionExecuteOutput(obj), nil + return velero.NewRestoreItemActionExecuteOutput(obj), nil } func (a *ChangeStorageClassAction) isStorageClassExist(log *logrus.Entry, storageClass *string, cm *corev1.ConfigMap) (exists bool, newStorageClass string, err error) { diff --git a/pkg/restore/change_storageclass_action_test.go b/pkg/restore/change_storageclass_action_test.go index 12a663075f..65de052db2 100644 --- a/pkg/restore/change_storageclass_action_test.go +++ b/pkg/restore/change_storageclass_action_test.go @@ -32,7 +32,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) // TestChangeStorageClassActionExecute runs the ChangeStorageClassAction's Execute @@ -245,7 +245,7 @@ func TestChangeStorageClassActionExecute(t *testing.T) { unstructuredMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(tc.pvOrPvcOrSTS) require.NoError(t, err) - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredMap, }, diff --git a/pkg/restore/clusterrolebinding_action.go b/pkg/restore/clusterrolebinding_action.go index eed52ba89c..851b13f098 100644 --- a/pkg/restore/clusterrolebinding_action.go +++ b/pkg/restore/clusterrolebinding_action.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // ClusterRoleBindingAction handle namespace remappings for role bindings @@ -42,10 +41,10 @@ func (a *ClusterRoleBindingAction) AppliesTo() (velero.ResourceSelector, error) }, nil } -func (a *ClusterRoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ClusterRoleBindingAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { namespaceMapping := input.Restore.Spec.NamespaceMapping if len(namespaceMapping) == 0 { - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil } clusterRoleBinding := new(rbac.ClusterRoleBinding) @@ -64,5 +63,5 @@ func (a *ClusterRoleBindingAction) Execute(input *riav1.RestoreItemActionExecute return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/clusterrolebinding_action_test.go b/pkg/restore/clusterrolebinding_action_test.go index a68334565a..cea1c57871 100644 --- a/pkg/restore/clusterrolebinding_action_test.go +++ b/pkg/restore/clusterrolebinding_action_test.go @@ -28,7 +28,6 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -90,7 +89,7 @@ func TestClusterRoleBindingActionExecute(t *testing.T) { require.NoError(t, err) action := NewClusterRoleBindingAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: roleBindingUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: roleBindingUnstructured}, Restore: &api.Restore{ diff --git a/pkg/restore/crd_v1_preserve_unknown_fields_action.go b/pkg/restore/crd_v1_preserve_unknown_fields_action.go index a9d8768056..f67d47910d 100644 --- a/pkg/restore/crd_v1_preserve_unknown_fields_action.go +++ b/pkg/restore/crd_v1_preserve_unknown_fields_action.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // CRDV1PreserveUnknownFieldsAction will take a CRD and inspect it for the API version and the PreserveUnknownFields value. @@ -46,7 +45,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) AppliesTo() (velero.ResourceSelector, }, nil } -func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { c.logger.Info("Executing CRDV1PreserveUnknownFieldsAction") name, _, err := unstructured.NestedString(input.Item.UnstructuredContent(), "name") @@ -63,7 +62,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActio // We don't want to "fix" anything in beta CRDs at the moment, just v1 versions with preserveunknownfields = true if version != "apiextensions.k8s.io/v1" { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, }, nil } @@ -103,7 +102,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *riav1.RestoreItemActio return nil, errors.Wrap(err, "unable to convert crd to runtime.Unstructured") } - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{Object: res}, }, nil } diff --git a/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go b/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go index 3840918ad5..77045b596d 100644 --- a/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go +++ b/pkg/restore/crd_v1_preserve_unknown_fields_action_test.go @@ -24,7 +24,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -48,6 +48,6 @@ func TestExecuteForACRDWithAnIntOnAFloat64FieldShouldWork(t *testing.T) { a := NewCRDV1PreserveUnknownFieldsAction(test.NewLogger()) - _, err = a.Execute(&riav1.RestoreItemActionExecuteInput{Item: &u}) + _, err = a.Execute(&velero.RestoreItemActionExecuteInput{Item: &u}) require.NoError(t, err) } diff --git a/pkg/restore/init_restorehook_pod_action.go b/pkg/restore/init_restorehook_pod_action.go index cb72e14d4f..f994d811de 100644 --- a/pkg/restore/init_restorehook_pod_action.go +++ b/pkg/restore/init_restorehook_pod_action.go @@ -24,7 +24,6 @@ import ( "github.com/vmware-tanzu/velero/internal/hook" "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // InitRestoreHookPodAction is a RestoreItemAction plugin applicable to pods that runs @@ -46,7 +45,7 @@ func (a *InitRestoreHookPodAction) AppliesTo() (velero.ResourceSelector, error) } // Execute implements the RestoreItemAction plugin interface method. -func (a *InitRestoreHookPodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *InitRestoreHookPodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Infof("Executing InitRestoreHookPodAction") // handle any init container restore hooks for the pod restoreHooks, err := hook.GetRestoreHooksFromSpec(&input.Restore.Spec.Hooks) @@ -61,5 +60,5 @@ func (a *InitRestoreHookPodAction) Execute(input *riav1.RestoreItemActionExecute } a.logger.Infof("Returning from InitRestoreHookPodAction") - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: postHooksItem.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: postHooksItem.UnstructuredContent()}), nil } diff --git a/pkg/restore/init_restorehook_pod_action_test.go b/pkg/restore/init_restorehook_pod_action_test.go index 058865660a..c69d3c23f9 100644 --- a/pkg/restore/init_restorehook_pod_action_test.go +++ b/pkg/restore/init_restorehook_pod_action_test.go @@ -29,7 +29,7 @@ import ( velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/kuberesource" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -125,7 +125,7 @@ func TestInitContainerRestoreHookPodActionExecute(t *testing.T) { unstructuredPod, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredPod}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredPod}, Restore: tc.restore, diff --git a/pkg/restore/job_action.go b/pkg/restore/job_action.go index 4e20f9cc92..fbaf30b249 100644 --- a/pkg/restore/job_action.go +++ b/pkg/restore/job_action.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) type JobAction struct { @@ -41,7 +40,7 @@ func (a *JobAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *JobAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *JobAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { job := new(batchv1api.Job) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), job); err != nil { return nil, errors.WithStack(err) @@ -57,5 +56,5 @@ func (a *JobAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1. return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/job_action_test.go b/pkg/restore/job_action_test.go index 0b15bc47f0..606dd089d8 100644 --- a/pkg/restore/job_action_test.go +++ b/pkg/restore/job_action_test.go @@ -27,7 +27,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -138,7 +138,7 @@ func TestJobActionExecute(t *testing.T) { unstructuredJob, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredJob}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredJob}, Restore: nil, diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 35d9d75220..d4bdc13847 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -27,7 +27,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) type PodAction struct { @@ -44,7 +43,7 @@ func (a *PodAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *PodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *PodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { pod := new(v1.Pod) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), pod); err != nil { return nil, errors.WithStack(err) @@ -87,7 +86,7 @@ func (a *PodAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1. if err != nil { return nil, errors.WithStack(err) } - restoreExecuteOutput := riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) + restoreExecuteOutput := velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) if pod.Spec.PriorityClassName != "" { a.logger.Infof("Adding priorityclass %s to AdditionalItems", pod.Spec.PriorityClassName) restoreExecuteOutput.AdditionalItems = []velero.ResourceIdentifier{ diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index c8121df673..f1aa83c1a3 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -28,7 +28,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -230,7 +229,7 @@ func TestPodActionExecute(t *testing.T) { unstructuredPod, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredPod}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredPod}, Restore: nil, diff --git a/pkg/restore/restic_restore_action.go b/pkg/restore/restic_restore_action.go index bf7116b8b9..f2d8df9a1d 100644 --- a/pkg/restore/restic_restore_action.go +++ b/pkg/restore/restic_restore_action.go @@ -36,7 +36,6 @@ import ( "github.com/vmware-tanzu/velero/pkg/label" "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/podvolume" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -67,7 +66,7 @@ func (a *ResticRestoreAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ResticRestoreAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ResticRestoreAction") defer a.logger.Info("Done executing ResticRestoreAction") @@ -100,7 +99,7 @@ func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput volumeSnapshots := podvolume.GetVolumeBackupsForPod(podVolumeBackups, &pod, podFromBackup.Namespace) if len(volumeSnapshots) == 0 { log.Debug("No restic backups found for pod") - return riav1.NewRestoreItemActionExecuteOutput(input.Item), nil + return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } log.Info("Restic backups for pod found") @@ -172,7 +171,7 @@ func (a *ResticRestoreAction) Execute(input *riav1.RestoreItemActionExecuteInput return nil, errors.Wrap(err, "unable to convert pod to runtime.Unstructured") } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } func getCommand(log logrus.FieldLogger, config *corev1.ConfigMap) []string { diff --git a/pkg/restore/restic_restore_action_test.go b/pkg/restore/restic_restore_action_test.go index 660c1fc66c..b218f4b88d 100644 --- a/pkg/restore/restic_restore_action_test.go +++ b/pkg/restore/restic_restore_action_test.go @@ -35,7 +35,7 @@ import ( "github.com/vmware-tanzu/velero/pkg/builder" "github.com/vmware-tanzu/velero/pkg/buildinfo" velerofake "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -278,7 +278,7 @@ func TestResticRestoreActionExecute(t *testing.T) { unstructuredPodFromBackup = unstructuredPod } - input := &riav1.RestoreItemActionExecuteInput{ + input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ Object: unstructuredPod, }, diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 8705ae2127..02d882d955 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -1152,7 +1152,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso } ctx.log.Infof("Executing item action for %v", &groupResource) - executeOutput, err := action.RestoreItemAction.Execute(&riav1.RestoreItemActionExecuteInput{ + executeOutput, err := action.RestoreItemAction.Execute(&velero.RestoreItemActionExecuteInput{ Item: obj, ItemFromBackup: itemFromBackup, Restore: ctx.restore, diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index f1575bc185..46ef8cdede 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1149,17 +1149,17 @@ func (a *recordResourcesAction) AppliesTo() (velero.ResourceSelector, error) { return a.selector, nil } -func (a *recordResourcesAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *recordResourcesAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { metadata, err := meta.Accessor(input.Item) if err != nil { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: a.additionalItems, }, err } a.ids = append(a.ids, kubeutil.NamespaceAndName(metadata)) - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: a.additionalItems, }, nil @@ -1355,12 +1355,12 @@ func TestRestoreActionsRunForCorrectItems(t *testing.T) { // function body at runtime. type pluggableAction struct { selector velero.ResourceSelector - executeFunc func(*riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) + executeFunc func(*velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) } -func (a *pluggableAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *pluggableAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { if a.executeFunc == nil { - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, }, nil } @@ -1385,7 +1385,7 @@ func TestRestoreActionModifications(t *testing.T) { // method modifies the item being passed in by calling the 'modify' function on it. modifyingActionGetter := func(modify func(*unstructured.Unstructured)) *pluggableAction { return &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { obj, ok := input.Item.(*unstructured.Unstructured) if !ok { return nil, errors.Errorf("unexpected type %T", input.Item) @@ -1394,7 +1394,7 @@ func TestRestoreActionModifications(t *testing.T) { res := obj.DeepCopy() modify(res) - return &riav1.RestoreItemActionExecuteOutput{ + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: res, }, nil }, @@ -1532,8 +1532,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { actions: []riav1.RestoreItemAction{ &pluggableAction{ selector: velero.ResourceSelector{IncludedNamespaces: []string{"ns-1"}}, - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.Pods, Namespace: "ns-2", Name: "pod-2"}, @@ -1554,8 +1554,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.Pods, Namespace: "ns-2", Name: "pod-2"}, @@ -1579,8 +1579,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, @@ -1605,8 +1605,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, @@ -1631,8 +1631,8 @@ func TestRestoreActionAdditionalItems(t *testing.T) { apiResources: []*test.APIResource{test.Pods(), test.PVs()}, actions: []riav1.RestoreItemAction{ &pluggableAction{ - executeFunc: func(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { - return &riav1.RestoreItemActionExecuteOutput{ + executeFunc: func(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { + return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: input.Item, AdditionalItems: []velero.ResourceIdentifier{ {GroupResource: kuberesource.PersistentVolumes, Name: "pv-1"}, diff --git a/pkg/restore/rolebinding_action.go b/pkg/restore/rolebinding_action.go index 55820c21f9..c402075a61 100644 --- a/pkg/restore/rolebinding_action.go +++ b/pkg/restore/rolebinding_action.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" ) // RoleBindingAction handle namespace remappings for role bindings @@ -42,10 +41,10 @@ func (a *RoleBindingAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *RoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *RoleBindingAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { namespaceMapping := input.Restore.Spec.NamespaceMapping if len(namespaceMapping) == 0 { - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: input.Item.UnstructuredContent()}), nil } roleBinding := new(rbac.RoleBinding) @@ -64,5 +63,5 @@ func (a *RoleBindingAction) Execute(input *riav1.RestoreItemActionExecuteInput) return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil } diff --git a/pkg/restore/rolebinding_action_test.go b/pkg/restore/rolebinding_action_test.go index 2a62cf6d0d..8995df8c6d 100644 --- a/pkg/restore/rolebinding_action_test.go +++ b/pkg/restore/rolebinding_action_test.go @@ -28,7 +28,6 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -90,7 +89,7 @@ func TestRoleBindingActionExecute(t *testing.T) { require.NoError(t, err) action := NewRoleBindingAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: roleBindingUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: roleBindingUnstructured}, Restore: &api.Restore{ diff --git a/pkg/restore/service_account_action.go b/pkg/restore/service_account_action.go index 424985a26e..252d9fc576 100644 --- a/pkg/restore/service_account_action.go +++ b/pkg/restore/service_account_action.go @@ -26,7 +26,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -44,7 +43,7 @@ func (a *ServiceAccountAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ServiceAccountAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ServiceAccountAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { a.logger.Info("Executing ServiceAccountAction") defer a.logger.Info("Done executing ServiceAccountAction") @@ -76,5 +75,5 @@ func (a *ServiceAccountAction) Execute(input *riav1.RestoreItemActionExecuteInpu return nil, errors.Wrap(err, "unable to convert serviceaccount to runtime.Unstructured") } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.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 f8bc76fcc8..0bc976a0fa 100644 --- a/pkg/restore/service_account_action_test.go +++ b/pkg/restore/service_account_action_test.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/test" ) @@ -91,7 +90,7 @@ func TestServiceAccountActionExecute(t *testing.T) { require.NoError(t, err) action := NewServiceAccountAction(test.NewLogger()) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: saUnstructured}, ItemFromBackup: &unstructured.Unstructured{Object: saUnstructured}, Restore: nil, diff --git a/pkg/restore/service_action.go b/pkg/restore/service_action.go index d21690182e..0b22cf0959 100644 --- a/pkg/restore/service_action.go +++ b/pkg/restore/service_action.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "github.com/vmware-tanzu/velero/pkg/plugin/velero" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" "github.com/vmware-tanzu/velero/pkg/util/boolptr" ) @@ -48,7 +47,7 @@ func (a *ServiceAction) AppliesTo() (velero.ResourceSelector, error) { }, nil } -func (a *ServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*riav1.RestoreItemActionExecuteOutput, error) { +func (a *ServiceAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) { service := new(corev1api.Service) if err := runtime.DefaultUnstructuredConverter.FromUnstructured(input.Item.UnstructuredContent(), service); err != nil { return nil, errors.WithStack(err) @@ -73,7 +72,7 @@ func (a *ServiceAction) Execute(input *riav1.RestoreItemActionExecuteInput) (*ri return nil, errors.WithStack(err) } - return riav1.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + return velero.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 ccdef0729a..59fef00a15 100644 --- a/pkg/restore/service_action_test.go +++ b/pkg/restore/service_action_test.go @@ -29,7 +29,7 @@ import ( api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "github.com/vmware-tanzu/velero/pkg/builder" - riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1" + "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) @@ -377,7 +377,7 @@ func TestServiceActionExecute(t *testing.T) { unstructuredSvc, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&test.obj) require.NoError(t, err) - res, err := action.Execute(&riav1.RestoreItemActionExecuteInput{ + res, err := action.Execute(&velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{Object: unstructuredSvc}, ItemFromBackup: &unstructured.Unstructured{Object: unstructuredSvc}, Restore: test.restore,